Codeforces Round 510 (Div. 2)


A. Benches
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
6
1
1
1
1
Output
3 7
Input
1
10
5
Output
15 15
Input
3
6
1
6
5
Output
6 12
Input
3
7
1
6
5
Output
7 13
----------------------------------------------------------------------------------------------------
B. Vitamins
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 C
6 B
16 BAC
4 A
Output
15
Input
2
10 AB
15 BA
Output
-1
Input
5
10 A
9 BC
11 CA
4 A
5 B
Output
13
Input
6
100 A
355 BCA
150 BC
160 AC
180 B
190 CA
Output
250
Input
2
5 BA
11 CB
Output
16
----------------------------------------------------------------------------------------------------
C. Array Product
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5 -2 0 1 -3
Output
2 3
1 1 2
1 2 4
1 4 5
Input
5
5 2 0 4 0
Output
1 3 5
2 5
1 1 2
1 2 4
Input
2
2 -1
Output
2 2
Input
4
0 -10 0 0
Output
1 1 2
1 2 3
1 3 4
Input
4
0 0 0 0
Output
1 1 2
1 2 3
1 3 4
----------------------------------------------------------------------------------------------------
D. Petya and Array
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
5 -1 3 4 -1
Output
5
Input
3 0
-1 2 -3
Output
4
Input
4 -1
-2 1 -2 3
Output
3
----------------------------------------------------------------------------------------------------
E. Vasya and Magic Matrix
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 4
1 1 2 1
1 3
Output
2
Input
2 3
1 5 7
2 3 1
1 2
Output
665496238
----------------------------------------------------------------------------------------------------
F. Leaf Sets
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9 3
1 2
1 3
2 4
2 5
3 6
6 7
6 8
3 9
Output
2
Input
5 3
1 2
2 3
3 4
4 5
Output
2
Input
6 1
1 2
1 3
1 4
1 5
1 6
Output
5
----------------------------------------------------------------------------------------------------
