Codeforces Beta Round 35 (Div. 2)


A. Shell Game
time limit per test: 2 seconds
memory limit per test: 64 megabytes
input: input.txt
output: output.txt

Examples
Input
1
1 2
2 1
2 1
Output
2
Input
1
2 1
3 1
1 3
Output
2
----------------------------------------------------------------------------------------------------
B. Warehouse
time limit per test: 2 seconds
memory limit per test: 64 megabytes
input: input.txt
output: output.txt

Examples
Input
2 2 9
+1 1 1 cola
+1 1 1 fanta
+1 1 1 sevenup
+1 1 1 whitekey
-1 cola
-1 fanta
-1 sevenup
-1 whitekey
-1 cola
Output
1 1
1 2
2 1
2 2
-1 -1
Input
2 2 8
+1 1 1 cola
-1 cola
+1 1 1 fanta
-1 fanta
+1 1 1 sevenup
-1 sevenup
+1 1 1 whitekey
-1 whitekey
Output
1 1
1 1
1 1
1 1
----------------------------------------------------------------------------------------------------
C. Fire Again
time limit per test: 2 seconds
memory limit per test: 64 megabytes
input: input.txt
output: output.txt

Examples
Input
3 3
1
2 2
Output
1 1
Input
3 3
1
1 1
Output
3 3
Input
3 3
2
1 1 3 3
Output
2 2
----------------------------------------------------------------------------------------------------
D. Animals
time limit per test: 2 seconds
memory limit per test: 64 megabytes
input: input.txt
output: output.txt

Examples
Input
3 4
1 1 1
Output
2
Input
3 6
1 1 1
Output
3
----------------------------------------------------------------------------------------------------
E. Parade
time limit per test: 2 seconds
memory limit per test: 64 megabytes
input: input.txt
output: output.txt

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