Codeforces Round 321 (Div. 2)


A. Kefa and First Steps
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 2 1 3 4 1
Output
3
Input
3
2 2 9
Output
3
----------------------------------------------------------------------------------------------------
B. Kefa and Company
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
75 5
0 100
150 20
75 1
Output
100
Input
5 100
0 7
11 32
99 10
46 8
87 54
Output
111
----------------------------------------------------------------------------------------------------
C. Kefa and Park
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 1
1 1 0 0
1 2
1 3
1 4
Output
2
Input
7 1
1 0 1 1 0 0 0
1 2
1 3
2 4
2 5
3 6
3 7
Output
2
----------------------------------------------------------------------------------------------------
D. Kefa and Dishes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2 1
1 1
2 1 1
Output
3
Input
4 3 2
1 2 3 4
2 1 5
3 4 2
Output
12
----------------------------------------------------------------------------------------------------
E. Kefa and Watch
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1 2
112
2 2 3 1
1 1 3 8
2 1 2 1
Output
NO
YES
Input
6 2 3
334934
2 2 5 2
1 4 4 3
2 1 6 3
1 2 3 8
2 3 6 1
Output
NO
YES
NO
----------------------------------------------------------------------------------------------------
