Codeforces Round 380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)


A. Road to Cinema
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
----------------------------------------------------------------------------------------------------
B. Sea Battle
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 1 2 1
00100
Output
2
4 2
Input
13 3 2 3
1000000010001
Output
2
7 11
----------------------------------------------------------------------------------------------------
C. Subordinates
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
2 0 2
Output
1
Input
5 3
1 0 0 4 1
Output
2
----------------------------------------------------------------------------------------------------
D. Financiers Game
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
1 3 1
Output
4
Input
5
-1 -2 -1 -2 -1
Output
0
Input
4
-4 -2 4 5
Output
-13
----------------------------------------------------------------------------------------------------
E. Tanya is 5!
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2 100
3 7
2 1 3 2 1
2 1 3 2 1
Output
4
10
8
1 1 0 1
2 2 0 1
1 1 1 1
2 1 1 1
2 1 2 1
1 1 2 1
1 2 3 1
2 1 3 1
Input
3 2 15
11 7
2 2 10 1 5
1 2 20
2 1 4 2 3
Output
20
01
17
2 2 0 4
2 2 4 1
1 1 5 2
2 2 5 2
1 2 7 5
2 2 7 5
2 2 12 1
1 2 12 1
3 1 13 4
2 2 13 4
1 2 13 4
1 1 17 2
3 2 17 2
2 2 17 2
1 1 19 1
2 2 19 1
3 2 19 1
----------------------------------------------------------------------------------------------------
F. Dirty plates
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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