Codeforces Round 515 (Div. 3)


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

Examples
Input
4
10 2 3 7
100 51 51 51
1234 1 100 199
1000000000 1 1 1000000000
Output
3
0
1134
0
----------------------------------------------------------------------------------------------------
B. Heaters
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 2
0 1 1 0 0 1
Output
3
Input
5 3
1 0 0 0 1
Output
2
Input
5 10
0 0 0 0 0
Output
-1
Input
10 3
0 0 1 1 0 1 0 0 0 1
Output
3
----------------------------------------------------------------------------------------------------
C. Books Queries
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
L 1
R 2
R 3
? 2
L 4
? 1
L 5
? 1
Output
1
1
2
Input
10
L 100
R 100000
R 123
L 101
? 123
L 10
R 115
? 100
R 110
? 115
Output
0
2
1
----------------------------------------------------------------------------------------------------
D. Boxes Packing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2 6
5 2 1 4 2
Output
4
Input
5 1 4
4 2 3 4 1
Output
1
Input
5 3 3
1 2 3 1 1
Output
5
----------------------------------------------------------------------------------------------------
E. Binary Numbers AND Sum
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1010
1101
Output
12
Input
4 5
1001
10101
Output
11
----------------------------------------------------------------------------------------------------
F. Yet another 2D Walking
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
2 2
1 4
2 3
3 1
3 4
1 1
4 3
1 2
Output
15
Input
5
2 1
1 0
2 0
3 2
0 3
Output
9
----------------------------------------------------------------------------------------------------
