Codeforces Round 526 (Div. 2)


A. The Fair Nut and Elevator
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
0 2 1
Output
16
Input
2
1 1
Output
4
----------------------------------------------------------------------------------------------------
B. Kvass and the Fair Nut
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
----------------------------------------------------------------------------------------------------
C. The Fair Nut and String
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
abbaa
Output
5
Input
baaaa
Output
4
Input
agaa
Output
3
----------------------------------------------------------------------------------------------------
D. The Fair Nut and the Best Path
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 3 3
1 2 2
1 3 2
Output
3
Input
5
6 3 2 5 0
1 2 10
2 3 3
2 4 1
1 5 1
Output
7
----------------------------------------------------------------------------------------------------
E. The Fair Nut and Strings
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 4
aa
bb
Output
6
Input
3 3
aba
bba
Output
8
Input
4 5
abbb
baaa
Output
8
----------------------------------------------------------------------------------------------------
F. Max Mex
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 5 0 3 1 4
1 1 3 3 3
3
2
1 6 3
2
Output
3
2
Input
6
5 2 1 4 3 0
1 1 1 3 3
9
2
1 5 3
2
1 6 1
2
1 4 2
2
1 1 6
2
Output
3
2
4
4
2
----------------------------------------------------------------------------------------------------
