Codeforces Round 161 (Div. 2)


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

Examples
Input
0 0 0 0 0
0 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Output
3
Input
0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
0 0 0 0 0
0 0 0 0 0
Output
1
----------------------------------------------------------------------------------------------------
B. Squares
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
5 1 3 4
Output
2 1
Input
3 1
2 4 1
Output
4 0
Input
4 50
5 1 10 2
Output
-1
----------------------------------------------------------------------------------------------------
C. Circle of Numbers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2
2 3
3 4
4 5
5 1
1 3
2 4
3 5
4 1
5 2
Output
1 2 3 4 5 
Input
6
5 6
4 3
5 3
2 4
6 1
3 1
6 2
2 5
1 4
3 6
1 2
4 5
Output
1 2 4 5 3 6 
----------------------------------------------------------------------------------------------------
D. Cycle in Graph
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 2
1 2
2 3
3 1
Output
3
1 2 3 
Input
4 6 3
4 3
1 2
1 3
1 4
2 3
2 4
Output
4
3 4 1 2 
----------------------------------------------------------------------------------------------------
E. Rhombus
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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