Codeforces Round 144 (Div. 1)


A. Cycles
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
Output
3
011
101
110
Input
10
Output
5
01111
10111
11011
11101
11110
----------------------------------------------------------------------------------------------------
B. Table
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6 1
Output
45
----------------------------------------------------------------------------------------------------
C. Doe Graphs
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
10
1 2 2 1 100 99 99 100 100 100
6
1 4
1 2
3 4
1 5
9 10
10 10
Output
1
2
2
0
2
9
----------------------------------------------------------------------------------------------------
E. Quick Tortoise
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 3
...
.##
.#.
5
1 1 3 3
1 1 1 3
1 1 3 1
1 1 1 2
1 1 2 1
Output
No
Yes
Yes
Yes
Yes
Input
5 5
.....
.###.
.....
.###.
.....
5
1 1 5 5
1 1 1 5
1 1 3 4
2 1 2 5
1 1 2 5
Output
Yes
Yes
Yes
No
Yes
----------------------------------------------------------------------------------------------------
