Codeforces Round 345 (Div. 1)


A. Watchmen
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 1
7 5
1 5
Output
2
Input
6
0 0
0 1
0 2
-1 1
0 1
1 1
Output
11
----------------------------------------------------------------------------------------------------
B. Image Preview
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2 3 10
wwhw
Output
2
Input
5 2 4 13
hhwhh
Output
4
Input
5 2 4 1000
hhwhh
Output
5
Input
3 1 100 10
whw
Output
0
----------------------------------------------------------------------------------------------------
C. Table Compression
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
1 2
3 4
Output
1 2
2 3
Input
4 3
20 10 30
50 40 30
50 60 70
90 80 70
Output
2 1 3
5 4 3
5 6 7
9 8 7
----------------------------------------------------------------------------------------------------
D. Zip-line
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

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