Educational Codeforces Round 113 (Rated for Div. 2)


A. Balanced Substring
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
a
6
abbaba
6
abbaba
9
babbabbaa
Output
-1 -1
1 6
3 6
2 5
----------------------------------------------------------------------------------------------------
B. Chess Tournament
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
111
2
21
4
2122
Output
YES
X==
=X=
==X
NO
YES
X--+
+X++
+-X-
--+X
----------------------------------------------------------------------------------------------------
C. Jury Meeting
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2
1 2
3
5 5 5
4
1 3 3 7
6
3 4 2 1 3 3
Output
1
6
0
540
----------------------------------------------------------------------------------------------------
D. Inconvenient Pairs
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 2 4
0 1000000
0 1000000
1 0
1000000 1
999999 1000000
0 999999
5 4 9
0 1 2 6 1000000
0 4 8 1000000
4 4
2 5
2 2
6 3
1000000 1
3 8
5 8
8 8
6 8
Output
2
5
----------------------------------------------------------------------------------------------------
E. Playoff Restoration
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 1337 75275197
Output
5 3 5 2 1 5 5 3 
Input
2 100 5040100
Output
1 3 3 2 
Input
2 100 7020100
Output
-1
----------------------------------------------------------------------------------------------------
F. Palindromic Hamiltonian Path
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3 3
1 2
2 3
3 4
Output
9
Input
4 6 3
1 2
1 3
1 4
2 3
2 4
3 4
Output
21
Input
12 19 12
1 3
2 6
3 6
3 7
4 8
8 5
8 7
9 4
5 9
10 1
10 4
10 6
9 10
11 1
5 11
7 11
12 2
12 5
12 11
Output
456165084
----------------------------------------------------------------------------------------------------
