Codeforces Round 526 (Div. 1)


A. 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
----------------------------------------------------------------------------------------------------
B. 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
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. The Fair Nut's getting crazy
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 3
Output
1
Input
5
1 2 1 2 3
Output
4
----------------------------------------------------------------------------------------------------
E. The Fair Nut and Rectangles
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 4 8
1 5 0
5 2 10
Output
9
Input
4
6 2 4
1 6 2
2 4 3
5 3 8
Output
10
----------------------------------------------------------------------------------------------------
F. The Fair Nut and Amusing Xor
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 1
0 4 2
1 2 3
b 2 5
Output
-1
1
Input
3 2 2
1 3 2
0 0 0
a 1 0
b 1 1
Output
2
-1
2
----------------------------------------------------------------------------------------------------
