Codeforces Round 225 (Div. 1)


A. 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
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. Antimatter
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1 1 1
Output
12
----------------------------------------------------------------------------------------------------
E. Vowels
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
abc
aaa
ada
bcd
def
Output
0
----------------------------------------------------------------------------------------------------
