Codeforces Global Round 15


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

Examples
Input
4
3
lol
10
codeforces
5
aaaaa
4
dcba
Output
2
6
0
4
----------------------------------------------------------------------------------------------------
B. Running for Gold
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
50000 1 50000 50000 50000
3
10 10 20 30 30
20 20 30 10 10
30 30 10 20 20
3
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
6
9 5 3 7 1
7 4 1 6 8
5 6 7 3 2
6 7 8 8 6
4 2 2 4 5
8 3 6 9 4
Output
1
-1
1
5
----------------------------------------------------------------------------------------------------
C. Maximize the Intersections
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 2
8 2
1 5
1 1
2 1
2 0
10 6
14 6
2 20
9 10
13 18
15 12
11 7
Output
4
0
1
14
----------------------------------------------------------------------------------------------------
D. Array Differentiation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
4 -7 -1 5 10
1
0
3
1 10 100
4
-3 2 10 2
9
25 -171 250 174 152 242 100 -205 -258
Output
YES
YES
NO
YES
YES
----------------------------------------------------------------------------------------------------
E. Colors and Intervals
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
2 4 3 1 1 4 2 3 2 1 3 4
Output
4 5
1 7
8 11
6 12
Input
1 2
1 1
Output
1 2
Input
3 3
3 1 2 3 2 1 2 1 3
Output
6 8
3 7
1 4
Input
2 3
2 1 1 1 2 2
Output
2 3
5 6
----------------------------------------------------------------------------------------------------
F. Telepanting
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 2 0
6 5 1
7 4 0
8 1 1
Output
23
Input
1
454971987 406874902 1
Output
503069073
Input
5
243385510 42245605 0
644426565 574769163 0
708622105 208990040 0
786625660 616437691 0
899754846 382774619 0
Output
899754847
Input
5
200000000 100000000 1
600000000 400000000 0
800000000 300000000 0
900000000 700000000 1
1000000000 500000000 0
Output
3511295
----------------------------------------------------------------------------------------------------
G. A Serious Referee
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 3
3 1 2 3
3 2 3 4
2 1 2
Output
ACCEPTED
Input
4 3
3 1 2 3
3 2 3 4
3 1 3 4
Output
REJECTED
Input
3 4
1 1
1 2
1 3
2 1 3
Output
REJECTED
Input
5 2
3 2 3 4
5 1 2 3 4 5
Output
ACCEPTED
----------------------------------------------------------------------------------------------------
H. Guess the Perimeter
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
13 5 123 80
Output
Input
2 2 4 4
Output
Input
1 1 200 200
Output
----------------------------------------------------------------------------------------------------
I. Organizing a Music Festival
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
2 1 3
Output
4
Input
5 5
2 1 2
2 2 3
2 3 4
2 4 5
2 1 5
Output
0
Input
100 1
1 50
Output
35305197
Input
5 1
5 1 2 3 4 5
Output
120
Input
2 5
1 2
1 2
1 2
1 1
1 1
Output
2
Input
11 4
5 4 5 7 9 11
2 2 10
2 9 11
7 1 2 3 5 8 10 11
Output
384
----------------------------------------------------------------------------------------------------
