Codeforces Round 393 (Div. 2) (8VC Venture Cup 2017 - Final Round Div. 2 Edition)


A. Petr and a calendar
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
----------------------------------------------------------------------------------------------------
B. Frodo and pillows
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 6 2
Output
2
Input
3 10 3
Output
4
Input
3 6 1
Output
3
----------------------------------------------------------------------------------------------------
C. Pavel and barbecue
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 3 2 1
0 1 1 1
Output
2
Input
3
2 3 1
0 0 0
Output
1
----------------------------------------------------------------------------------------------------
D. Travel Card
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
10
20
30
Output
20
20
10
Input
10
13
45
46
60
103
115
126
150
256
516
Output
20
20
10
0
20
0
0
20
20
10
----------------------------------------------------------------------------------------------------
E. Nikita and stack
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 1 2
1 0
Output
2
2
Input
3
1 1 2
2 1 3
3 0
Output
2
3
2
Input
5
5 0
4 0
3 1 1
2 1 1
1 1 2
Output
-1
-1
-1
-1
2
----------------------------------------------------------------------------------------------------
F. Bacterial Melee
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
aaa
Output
1
Input
2
ab
Output
3
Input
4
babb
Output
11
Input
7
abacaba
Output
589
----------------------------------------------------------------------------------------------------
