Codeforces Round 858 (Div. 2)


A. Walking Master
time limit per test: 1 second
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
6
-1 0 -1 2
0 0 4 5
-2 -1 1 1
-3 2 -3 2
2 -1 -1 -1
1 1 0 2
Output
4
6
-1
0
3
3
----------------------------------------------------------------------------------------------------
B. Mex Master
time limit per test: 1 second
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
3
2
0 0
3
0 0 1
8
1 0 0 0 2 0 3 0
Output
1
0
1
----------------------------------------------------------------------------------------------------
C. Sequence Master
time limit per test: 1 second
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4
1
6 9
2
1 2 2 1
2
-2 -2 2 2
4
-3 -2 -1 0 1 2 3 4
Output
3
2
5
13
----------------------------------------------------------------------------------------------------
D. DSU Master
time limit per test: 2 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
2
3
0 0
9
0 1 0 0 0 1 0 0
Output
1 3 
1 2 7 31 167 1002 7314 60612 
----------------------------------------------------------------------------------------------------
E. Tree Master
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
6 2
1 5 2 3 1 1
1 2 3 3 2
4 5
6 6
Output
33
27
Input
14 8
3 2 5 3 1 4 2 2 2 5 5 5 2 4
1 2 3 1 1 4 7 3 3 1 5 3 8
4 4
4 10
13 10
3 12
13 9
3 12
9 10
11 5
Output
47
53
48
36
42
36
48
14
----------------------------------------------------------------------------------------------------
F1. GCD Master (easy version)
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
3
3 8 1
4 7 8
5 114 2
7 2 4 1 6
3 514 2
2 3 3
Output
11
14
1
----------------------------------------------------------------------------------------------------
F2. GCD Master (hard version)
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4
3 8 1
4 7 8
5 114514 2
7 2 4 1 6
3 1919810 2
2 3 3
3 9000000000000000000 1
9000000000000000000 9000000000000000000 9000000000000000000
Output
11
14
1
18000000000000000000
----------------------------------------------------------------------------------------------------
