Pinely Round 2 (Div. 1 + Div. 2)


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

Examples
Input
4
5 5 3
--+
5 2 3
++-
5 4 2
-+
5 0 7
++++-++
Output
YES
NO
MAYBE
YES
----------------------------------------------------------------------------------------------------
B. Split Sort
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1
1
2
2 1
6
6 4 3 5 2 1
3
3 1 2
19
10 19 7 1 17 11 8 5 12 9 4 18 14 2 6 15 3 16 13
Output
0
1
4
1
7
----------------------------------------------------------------------------------------------------
C. MEX Repetition
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 1
0 1 3
2 2
0 2
5 5
1 2 3 4 5
10 100
5 3 0 4 2 1 6 9 10 8
Output
1
2 0 1
2 1
2 3 4 5 0
7 5 3 0 4 2 1 6 9 10
----------------------------------------------------------------------------------------------------
D. Two-Colored Dominoes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 6
..LR..
ULRU..
DLRDUU
..LRDD
5 4
.LR.
.UU.
UDDU
D..D
LR..
2 2
..
..
Output
..WB..
WWBB..
BBWWWB
..BWBW
-1
..
..
----------------------------------------------------------------------------------------------------
E. Speedrun
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4 4 24
12 16 18 12
1 2
1 3
2 4
3 4
4 3 10
2 6 5 9
1 4
2 4
3 4
2 1 10
5 5
1 2
5 0 1000
8 800 555 35 35
5 0 10
3 2 5 4 7
3 2 5
4 3 2
1 2
2 3
Output
24
7
0
480
5
8
----------------------------------------------------------------------------------------------------
F. Divide, XOR, and Conquer
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
6
3 2 1 3 7 4
5
1 1 1 1 1
10
1 2 4 8 4 1 2 3 4 5
5
0 0 0 0 0
5
1 2 3 0 1
1
100500
Output
111111
10101
0001000000
11111
11001
1
----------------------------------------------------------------------------------------------------
G. Swaps
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 1 2
Output
2
Input
4
2 1 4 3
Output
4
Input
6
2 3 1 1 1 2
Output
18
----------------------------------------------------------------------------------------------------
H. Goldberg Machine 3
time limit per test: 8 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1 2 2
0 0 0 0 0
5
3 1
4 1
5 1
3 4
4 1000000000
Output
0
1
2
3
7
7022585
----------------------------------------------------------------------------------------------------
I. Redundant Routes
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

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