Codeforces Round 223 (Div. 1)


A. Sereja and Prefixes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 1
1 2
2 2 1
1 3
2 5 2
1 4
16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Output
1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4
----------------------------------------------------------------------------------------------------
B. Sereja and Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
1 4 4 7 1
1 3 1 2 2
2 1 1
2 4 1
2 3 3
Output
2
0
1
----------------------------------------------------------------------------------------------------
C. Sereja and Brackets
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
())(())(())(
7
1 1
2 3
1 2
1 12
8 12
5 11
2 10
Output
0
0
2
10
4
6
6
----------------------------------------------------------------------------------------------------
D. Sereja and Cinema
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
11
0 0 0 0 0 0 0 0 0 0 0
Output
1024
Input
6
0 3 1 0 0 0
Output
3
----------------------------------------------------------------------------------------------------
E. Sereja and Dividing
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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