Educational Codeforces Round 116 (Rated for Div. 2)


A. AB Balance
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
b
aabbbabaa
abbb
abbaab
Output
b
aabbbabaa
bbbb
abbaaa
----------------------------------------------------------------------------------------------------
B. Update Files
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
8 3
6 6
7 1
1 1
Output
4
3
6
0
----------------------------------------------------------------------------------------------------
C. Banknotes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 13
0 1 2
2 777
0 4
3 255
0 1 3
10 1000000000
0 1 2 3 4 5 6 7 8 9
Output
59
778
148999
999999920999999999
----------------------------------------------------------------------------------------------------
D. Red-Blue Matrix
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5 5
1 5 8 8 7
5 2 1 4 3
1 6 9 7 5
9 3 3 3 2
1 7 9 9 8
3 3
8 9 8
1 5 3
7 5 7
2 6
3 3 3 2 2 2
1 1 1 4 4 4
Output
YES
BRBRB 1
NO
YES
RB 3
----------------------------------------------------------------------------------------------------
E. Arena
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 5
Output
5
Input
3 3
Output
15
Input
5 4
Output
1024
Input
13 37
Output
976890680
----------------------------------------------------------------------------------------------------
F. Tree Queries
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
8
6 7
3 2
8 3
5 7
7 4
7 1
7 3
6
1 0
1 2
1 3
7 1
5 0
7 200000
Output
5
2
1
4
0
4
----------------------------------------------------------------------------------------------------
