Codeforces Round 548 (Div. 2)


A. Even Substrings
time limit per test: 0.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1234
Output
6
Input
4
2244
Output
10
----------------------------------------------------------------------------------------------------
B. Chocolates
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 1 3 6
Output
10
Input
5
3 2 5 4 10
Output
20
Input
4
1 1 1 1
Output
1
----------------------------------------------------------------------------------------------------
C. Edgy Trees
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2 1
2 3 1
3 4 1
Output
252
Input
4 6
1 2 0
1 3 0
1 4 0
Output
0
Input
3 5
1 2 1
2 3 0
Output
210
----------------------------------------------------------------------------------------------------
D. Steps to One
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
Output
1
Input
2
Output
2
Input
4
Output
333333338
----------------------------------------------------------------------------------------------------
E. Maximize Mex
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
0 1 2 2 0
1 2 2 3 2
5
3
2
4
5
1
Output
3
1
1
1
0
Input
5 3
0 1 2 2 1
1 3 2 3 2
5
4
2
3
5
1
Output
3
2
2
1
0
Input
5 5
0 1 2 4 5
1 2 3 4 5
4
2
3
5
4
Output
1
1
1
1
----------------------------------------------------------------------------------------------------
F. Dish Shopping
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
2 1 3
2 4 4
2 1 1
2 2 3
1 2 4
Output
1 2 0 
Input
4 3
1 2 1 1
3 3 1 3
2 1 3 2
1 1 3
1 2 1
Output
0 2 3 
----------------------------------------------------------------------------------------------------
