Codeforces Round 117 (Div. 2)


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

Examples
Input
2 4
0 5 6 5
3
0 0 0 4
1 1 4 1
6 0 6 4
Output
19.0000000000
Input
5 10
0 0 10 10
1
5 0 5 9
Output
-1
----------------------------------------------------------------------------------------------------
B. Vasya's Calendar
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2
2 2
Output
2
Input
5
3
3 4 3
Output
3
Input
31
12
31 28 31 30 31 30 31 31 30 31 30 31
Output
7
----------------------------------------------------------------------------------------------------
C. Optimal Sum
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
0 -2 3 -5 1
2
Output
10
Input
5 2
1 -3 -10 4 1
3
Output
14
Input
3 3
-2 -5 4
1
Output
11
----------------------------------------------------------------------------------------------------
D. Common Divisors
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
abcdabcd
abcdabcdabcdabcd
Output
2
Input
aaa
aa
Output
1
----------------------------------------------------------------------------------------------------
E. Wooden Fence
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 2
2 3
Output
2
Input
1 2
2 2
Output
1
Input
6 6
2 1
3 2
2 5
3 3
5 1
2 1
Output
20
----------------------------------------------------------------------------------------------------
