Codeforces Global Round 19


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

Examples
Input
3
3
2 2 1
4
3 1 2 1
5
1 2 2 4 4
Output
YES
YES
NO
----------------------------------------------------------------------------------------------------
B. MEX and Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2
1 2
3
2 0 1
4
2 0 5 1
5
0 1 1 0 1
Output
4
14
26
48
----------------------------------------------------------------------------------------------------
C. Andrew and Stones
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5
1 2 2 3 6
3
1 3 1
3
1 2 1
4
3 1 1 2
Output
4
-1
1
-1 
----------------------------------------------------------------------------------------------------
D. Yet Another Minimization Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1
3
6
4
3 6 6 6
2 7 4 1
4
6 7 2 4
2 5 3 5
Output
0
987
914
----------------------------------------------------------------------------------------------------
E. Best Pair
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6 1
6 3 6 7 3 3
3 6
2 0
3 4
7 4
1 2 2 3 1 5 1
1 5
3 5
1 3
2 5
Output
40
14
15
----------------------------------------------------------------------------------------------------
F. Towers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 1
1 2
2 3
Output
4
Input
5
1 3 3 1 3
1 3
5 4
4 3
2 3
Output
7
Input
2
6 1
1 2
Output
12
----------------------------------------------------------------------------------------------------
G. Birthday
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2
3
Output
-1
3
1 3
2 2
4 0
----------------------------------------------------------------------------------------------------
H. Minimize Inversions Number
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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