Codeforces Round 214 (Div. 2)


A. Dima and Guards
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
Output
1 5 5
Input
10
6 6 6 6
7 7 7 7
4 4 4 4
8 8 8 8
Output
3 4 6
Input
5
3 3 3 3
3 3 3 3
3 3 3 3
3 3 3 3
Output
-1
----------------------------------------------------------------------------------------------------
B. Dima and To-do List
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 2
3 2 1 6 5 4
Output
1
Input
10 5
1 3 5 7 9 9 4 1 8 5
Output
3
----------------------------------------------------------------------------------------------------
C. Dima and Salad
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
10 8 1
2 7 1
Output
18
Input
5 3
4 4 4 4 4
2 2 2 2 2
Output
-1
----------------------------------------------------------------------------------------------------
D. Dima and Trap Graph
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2 1 10
2 4 3 5
1 3 1 5
2 4 2 7
Output
6
Input
5 6
1 2 1 10
2 5 11 20
1 4 2 5
1 3 10 11
3 4 12 10000
4 5 6 6
Output
Nice work, Dima!
----------------------------------------------------------------------------------------------------
E. Dima and Magic Guitar
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 6 5 7
3 1 2 2 3 1
3 2 2 2 5 5
4 2 2 2 5 3
3 2 2 1 4 3
2 3 1 4 1 5 1
Output
8
Input
4 4 9 5
4 7 9 5
1 2 1 7
8 3 4 9
5 7 7 2
7 1 9 2 5
Output
4
----------------------------------------------------------------------------------------------------
