Codeforces Round 762 (Div. 3)


A. Square String?
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
a
aa
aaa
aaaa
abab
abcabc
abacaba
xxyy
xyyx
xyxy
Output
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
----------------------------------------------------------------------------------------------------
B. Squares and Cubes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
10
1
25
1000000000
999999999
500000000
Output
4
1
6
32591
32590
23125
----------------------------------------------------------------------------------------------------
C. Wrong Addition
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
17236 1106911
1 5
108 112
12345 1023412
1 11
1 20
Output
3465
4
-1
90007
10
-1
----------------------------------------------------------------------------------------------------
D. New Year's Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 2
1 2
3 4
4 3
1 3 1
3 1 1
1 2 2
1 1 3
2 3
5 3 4
2 5 1
4 2
7 9
8 1
9 6
10 8
2 4
6 5 2 1
7 9 7 2
Output
3
2
4
8
2
----------------------------------------------------------------------------------------------------
E. MEX and Increments
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
0 1 3
7
0 1 2 3 4 3 2
4
3 0 0 0
7
4 6 2 3 5 0 5
5
4 0 1 0 4
Output
1 1 0 -1 
1 1 2 2 1 0 2 6 
3 0 1 4 3 
1 0 -1 -1 -1 -1 -1 -1 
2 1 0 2 -1 -1 
----------------------------------------------------------------------------------------------------
F. Let's Play the Hat?
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5 2 2
8 3 1
2 1 3
Output
3 1 2 3
2 4 5
3 4 5 2
2 1 3
2 6 2
3 3 5 1
3 4 7 8
2 2 1
2 2 1
2 2 1
----------------------------------------------------------------------------------------------------
G. Unusual Minesweeper
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5 0
0 0 1
0 1 4
1 0 2
1 1 3
2 2 9
5 2
0 0 1
0 1 4
1 0 2
1 1 3
2 2 9
6 1
1 -1 3
0 -1 9
0 1 7
-1 0 1
-1 1 9
-1 -1 7
Output
2
1
0
----------------------------------------------------------------------------------------------------
H. Permutation and Queries
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
5 3 4 2 1
2 3 1
2 1 2
1 1 3
2 1 2
Output
4
1
2
Input
5 9
2 3 5 1 4
2 3 5
2 5 5
2 5 1
2 5 3
2 5 4
1 5 4
2 5 3
2 2 5
2 5 1
Output
3
5
4
2
3
3
3
1
----------------------------------------------------------------------------------------------------
