Codeforces Round 383 (Div. 1)


A. Arpa's loud Owf and Mehrdad's evil plan
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 3 1 4
Output
3
Input
4
4 4 4 4
Output
-1
Input
4
2 1 4 3
Output
1
----------------------------------------------------------------------------------------------------
B. Arpa's weak amphitheater and Mehrdad's valuable Hoses
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1 5
3 2 5
2 4 2
1 2
Output
6
Input
4 2 11
2 4 6 6
6 4 2 1
1 2
2 3
Output
7
----------------------------------------------------------------------------------------------------
C. Arpa’s overnight party and Mehrdad’s silent entering
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 4
2 5
3 6
Output
1 2
2 1
1 2
----------------------------------------------------------------------------------------------------
D. Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 s
2 a
3 s
Output
3 1 1 0 
Input
5
1 a
2 h
1 a
4 h
Output
4 1 0 1 0 
----------------------------------------------------------------------------------------------------
E. Arpa’s abnormal DNA and Mehrdad’s deep interest
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
abc d 4
0 3 2 0 0
0 3 1 0 0
1 2 1 0 0
0 1 3 2 2
Output
2 3 2 -1 
Input
abbbbbbaaa baababaaab 10
1 2 1 0 0
2 7 8 4 7
2 3 9 2 8
3 4 6 1 1
0 8 5 2 4
2 8 10 4 7
7 10 1 0 0
1 4 6 0 2
0 9 8 0 6
4 8 5 0 1
Output
1 4 2 -1 2 4 10 1 1 5 
----------------------------------------------------------------------------------------------------
