Codeforces Round 419 (Div. 1)


A. Karen and Game
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 5
2 2 2 3 2
0 0 0 1 0
1 1 1 2 1
Output
4
row 1
row 1
col 4
row 3
Input
3 3
0 0 0
0 1 0
0 0 0
Output
-1
Input
3 3
1 1 1
1 1 1
1 1 1
Output
3
row 1
row 2
row 3
----------------------------------------------------------------------------------------------------
B. Karen and Test
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
3 6 9 12 15
Output
36
Input
4
3 7 5 2
Output
1000000006
----------------------------------------------------------------------------------------------------
C. Karen and Supermarket
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 16
10 9
10 5 1
12 2 1
20 18 3
10 2 3
2 1 5
Output
4
Input
5 10
3 1
3 1 1
3 1 2
3 1 3
3 1 4
Output
5
----------------------------------------------------------------------------------------------------
D. Karen and Cards
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 4 4 5
2 2 5
1 3 4
4 1 1
Output
10
Input
5 10 10 10
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
Output
972
----------------------------------------------------------------------------------------------------
E. Karen and Neighborhood
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 4
Output
2
Input
39 3
Output
20
----------------------------------------------------------------------------------------------------
