RCC 2014 Warmup (Div. 1)


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

Examples
Input
3 1
Output
3
1 2
2 3
3 1
----------------------------------------------------------------------------------------------------
B. Cunning Gena
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2 1
100 1 1
2
100 2 1
1
Output
202
Input
3 2 5
100 1 1
1
100 1 1
2
200 1 2
1 2
Output
205
Input
1 2 1
1 1 1
1
Output
-1
----------------------------------------------------------------------------------------------------
C. Square Table
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
Output
1
Input
1 2
Output
3 4
----------------------------------------------------------------------------------------------------
D. Big Problems for Organizers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3
3 1
3
2 1
2 3
3 1
Output
1
1
1
Input
4
1 4
1 2
2 3
3
1 4
1 3
2 3
Output
2
1
2
----------------------------------------------------------------------------------------------------
E. Tricky Password
time limit per test: 3.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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