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


A. 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
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. Byteland coins
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
1
4
2
Output
1
Input
2
1
4 4
2
Output
3
Input
3
3 3
10 10 10
17
Output
6
----------------------------------------------------------------------------------------------------
F. Long number
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
8-11
Output
891011
Input
2(2-4+1)+2(2(17))
Output
100783079
Input
1234-5678
Output
745428774
Input
1+2+3+4-5+6+7-9
Output
123456789
----------------------------------------------------------------------------------------------------
