Codeforces Round 225 (Div. 2)


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

Examples
Input
2
Output
2
C.
.C
----------------------------------------------------------------------------------------------------
B. Multitasking
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
4
0 0 1 0
Output
1
Input
5
1 0 1 0 1
Output
3
----------------------------------------------------------------------------------------------------
D. Volcanoes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 3
1 4
Output
6
Input
7 8
1 6
2 6
3 5
3 6
4 3
5 1
5 2
5 3
Output
12
Input
2 2
1 2
2 1
Output
-1
----------------------------------------------------------------------------------------------------
E. Propagating tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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