Educational Codeforces Round 147 (Rated for Div. 2)


A. Matching
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
8
??
?
0
9
03
1??7
?5?
9??99
Output
90
9
0
1
0
100
90
100
----------------------------------------------------------------------------------------------------
B. Sort the Subarray
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
7
6 7 3 4 4 6 5
6 3 4 4 7 6 5
3
1 2 1
1 1 2
3
2 2 1
2 1 2
Output
2 5
1 3
2 3
----------------------------------------------------------------------------------------------------
C. Tear It Apart
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
abacaba
codeforces
oooooooo
abcdef
mewheniseearulhiiarul
Output
1
3
0
2
4
----------------------------------------------------------------------------------------------------
D. Black Cells
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 3
1 3
1 4
4 20
10 13 16 19
11 14 17 20
2 3
1 3
1 10
2 4
99 999999999
100 1000000000
Output
8
-1
7
1000000004
----------------------------------------------------------------------------------------------------
E. Rearrange Brackets
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
0
()
0
(())
1
(())
5
()
1
(()()(()))
2
((())()(()())((())))
3
((())()(()())((())))
Output
0
1
0
0
1
4
2
----------------------------------------------------------------------------------------------------
F. Timber
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 1 4
Output
4
Input
5 2 2
Output
0
Input
6 2 2
Output
4
Input
15 3 2
Output
311
----------------------------------------------------------------------------------------------------
