Codeforces Round 247 (Div. 2)


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

Examples
Input
1 2 3 4
123214
Output
13
Input
1 5 3 2
11221
Output
13
----------------------------------------------------------------------------------------------------
B. Shower Line
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
0 0 0 0 9
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
7 0 0 0 0
Output
32
Input
0 43 21 18 2
3 0 21 11 65
5 2 0 1 4
54 62 12 0 99
87 64 81 33 0
Output
620
----------------------------------------------------------------------------------------------------
C. k-Tree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7
----------------------------------------------------------------------------------------------------
D. Random Task
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
Output
1
Input
3 2
Output
5
----------------------------------------------------------------------------------------------------
E. Chemistry Experiment
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2 0
2 2
1 2 1
2 3
Output
1.50000
1.66667
Input
4 5
1 3 0 1
2 3
2 1
1 3 2
2 3
2 4
Output
1.66667
1.00000
2.33333
2.66667
----------------------------------------------------------------------------------------------------
