Codeforces Round 142 (Div. 1)


A. Shifts
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 6
101010
000100
100000
Output
3
Input
2 3
111
000
Output
-1
----------------------------------------------------------------------------------------------------
B. Planets
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 6
1 2 2
1 3 3
1 4 8
2 3 4
2 4 5
3 4 3
0
1 3
2 3 4
0
Output
7
Input
3 1
1 2 3
0
1 3
0
Output
-1
----------------------------------------------------------------------------------------------------
C. Triangles
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 3
2 3
2 4
3 4
Output
3
Input
5 3
1 2
2 3
1 3
Output
4
----------------------------------------------------------------------------------------------------
D. Towers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3 1
3 10 20 30
Output
1.000000000
Input
3 2
1 40
4 10 20 30 40
Output
0.166666667
----------------------------------------------------------------------------------------------------
