Codeforces Round 264 (Div. 2)


A. Caisa and Sugar
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 10
3 90
12 0
9 70
5 50
7 0
Output
50
Input
5 5
10 10
20 20
30 30
40 40
50 50
Output
-1
----------------------------------------------------------------------------------------------------
B. Caisa and Pylons
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 4 3 2 4
Output
4
Input
3
4 4 4
Output
4
----------------------------------------------------------------------------------------------------
C. Gargari and Bishops
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1 1 1
2 1 1 0
1 1 1 0
1 0 0 1
Output
12
2 2 3 2
----------------------------------------------------------------------------------------------------
D. Gargari and Permutations
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
1 4 2 3
4 1 2 3
1 2 4 3
Output
3
----------------------------------------------------------------------------------------------------
E. Caisa and Tree
time limit per test: 10 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 6
10 8 4 3
1 2
2 3
3 4
1 1
1 2
1 3
1 4
2 1 9
1 4
Output
-1
1
2
-1
1
----------------------------------------------------------------------------------------------------
