RCC 2014 Warmup (Div. 2)


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

Examples
Input
1 10
7 2
1
Output
2
Input
2 2
2 1
2
Output
0
----------------------------------------------------------------------------------------------------
B. Crash
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
0 1
1 1
Output
YES
Input
4
0 1
1 2
1 1
0 2
Output
NO
Input
4
0 1
1 1
0 1
0 2
Output
YES
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. 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
----------------------------------------------------------------------------------------------------
