Codeforces Round 141 (Div. 2)


A. Is your horseshoe on the other hoof?
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3 2
01
10
00
2 3
001
111
Output
0 1
Input
3 3
000
010
000
1 1
1
Output
-1 -1
----------------------------------------------------------------------------------------------------
C. Fractal Detector
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 11
......*.***
*.*.*....**
.***....*.*
..***.*....
.*.*.....**
......*.*..
Output
3
Input
4 4
..**
..**
....
....
Output
0
----------------------------------------------------------------------------------------------------
D. Zigzag
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 3 1 5 5
4
2 2 3 2
2 1 5 3
1 3 5
2 1 5 3
Output
5
26
38
----------------------------------------------------------------------------------------------------
E. The Road to Berland is Paved With Good Intentions
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2 1
2 4 0
4 3 1
3 2 0
Output
4
3 2 1 3
Input
3 3
1 2 0
2 3 0
3 1 0
Output
Impossible
----------------------------------------------------------------------------------------------------
