Codecraft-18 and Codeforces Round 458 (Div. 1 + Div. 2, combined)


A. Perfect Squares
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4 2
Output
2
Input
8
1 2 4 8 16 32 64 576
Output
32
----------------------------------------------------------------------------------------------------
B. Conan and Agasa play a Card Game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 5 7
Output
Conan
Input
2
1 1
Output
Agasa
----------------------------------------------------------------------------------------------------
C. Travelling Salesman and Special Numbers
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
110
2
Output
3
Input
111111011
2
Output
169
----------------------------------------------------------------------------------------------------
D. Bash and a Tough Math Puzzle
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 6 3
4
1 1 2 2
1 1 3 3
2 1 9
1 1 3 2
Output
YES
YES
NO
Input
5
1 2 3 4 5
6
1 1 4 2
2 3 6
1 1 4 2
1 1 5 2
2 5 10
1 1 5 2
Output
NO
YES
NO
YES
----------------------------------------------------------------------------------------------------
E. Palindromes in a Tree
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2
2 3
3 4
3 5
abcbb
Output
1 3 4 3 3 
Input
7
6 2
4 3
3 7
5 2
7 2
1 4
afefdfs
Output
1 4 1 1 2 4 2 
----------------------------------------------------------------------------------------------------
F. Substrings in a String
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
ababababa
3
2 1 7 aba
1 5 c
2 1 7 aba
Output
3
1
Input
abcdcbc
5
2 1 7 bc
1 4 b
2 4 7 bc
1 2 a
2 1 4 aa
Output
2
2
1
----------------------------------------------------------------------------------------------------
G. Sum the Fibonacci
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2
Output
32
Input
3
7 4 1
Output
3520
Input
10
1 3 0 7 3 7 6 5 7 5
Output
1235424
Input
10
50 9 11 44 39 40 5 39 23 7
Output
113860062
----------------------------------------------------------------------------------------------------
H. Ember and Storm's Tree Game
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 1 1000000007
Output
4
Input
3 1 250
Output
0
Input
3 2 100
Output
36
----------------------------------------------------------------------------------------------------
