2019-2020 ICPC, NERC, Southern and Volga Russian Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)


A. Berstagram
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 5
3 2 1 3 3
Output
1 2
2 3
1 3
Input
10 6
7 3 5 7 3 6
Output
1 2
2 3
1 3
4 7
4 5
6 7
5 7
8 8
9 9
10 10
----------------------------------------------------------------------------------------------------
B. The Feast and the Bus
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 3
3 1 2 3 2 3
Output
6
Input
10 1
1 1 1 1 1 1 1 1 1 1
Output
10
Input
12 4
1 2 3 1 2 3 4 1 2 1 2 1
Output
12
----------------------------------------------------------------------------------------------------
C. Trip to Saint Petersburg
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 5
1 1 3
3 3 11
5 5 17
7 7 4
Output
13 3 5 2
3 2 
Input
1 3
1 2 5
Output
0
Input
4 8
1 5 16
2 4 9
3 3 24
1 5 13
Output
22 1 5 4
3 2 1 4 
----------------------------------------------------------------------------------------------------
D. Conference Problem
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
4
1 10 30
5 6 30
6 12 0
1 1 0
4
1 2 1
2 3 0
3 4 0
4 5 2
Output
4
2
----------------------------------------------------------------------------------------------------
E. The Coronation
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
5 7 2
1010100
0010101
1111010
1000010
0000101
6 9 3
011111110
100111000
111100000
000111111
110100111
111110111
3 4 2
0001
1000
0000
3 4 4
0001
1000
0000
2 4 3
0001
1000
Output
2
1 3 
1
3 
0
-1
1
1 
----------------------------------------------------------------------------------------------------
F. Data Center
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
36
Output
24
Input
13
Output
28
Input
1
Output
4
----------------------------------------------------------------------------------------------------
G. Discarding Game
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
4 17
1 3 5 7
3 5 7 9
11 17
5 2 8 2 4 6 1 2 7 2 5
4 6 3 3 5 1 7 4 2 5 3
6 17
6 1 2 7 2 5
1 7 4 2 5 3
Output
0
2
2 4
-1
----------------------------------------------------------------------------------------------------
H. Happy Birthday
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1 1 1 1 1 1 1 1 1
0 0 1 1 2 2 3 3 4 4
1 2 1 2 1 3 1 0 0 0
0 1 2 1 4 3 1 1 2 1
Output
11
1
7
10
----------------------------------------------------------------------------------------------------
I. Show Must Go On
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
7 13 10
3 1 5 1 8 2 13
2 10 1
12 12
3 32 100000
2 1 5
Output
10
5 12
4 7
4 9
4 10
4 11
4 11
4 12
4 13
3 4
3 5
2 4 1 
0
7
3 8
2 3
2 6
2 7
1 1
1 2
1 5
3 
----------------------------------------------------------------------------------------------------
J. The Parade
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
3 4
7 1 13
1 1
100
1 3
100
2 1
1000000000000 1000000000000
4 1
10 2 11 1
Output
16
100
99
2000000000000
13
----------------------------------------------------------------------------------------------------
K. Projectors
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
2 2 2 2
1 5
2 5
1 5
1 4
2 0 2 10
1 3
1 3
Output
YES
2 1 4 3 
YES
2 1 
Input
3
1 2 1 1
3 4
2 4
1 3
3 4 2 3
5 7
1 3
1 7
4 8
2 5
1 6
2 8
0 1 1 0
1 1000000
Output
YES
1 2 1 
NO
YES
1 
----------------------------------------------------------------------------------------------------
L. Divide The Students
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
3 5 7
4 8 4
13 10 13
1000 1000 1000
13 22 7
Output
5
6
13
1000
14
Input
5
1 3 4
1000 1000 1
4 1 2
325 226 999
939 861 505
Output
3
667
3
517
769
----------------------------------------------------------------------------------------------------
M. SmartGarden
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
Output
2
1 1
1 2
1 1
1 2
Input
4
Output
4
2 1 4
1 2
2 1 2
2 3 4
1 3
2 1 4
1 4
1 1
----------------------------------------------------------------------------------------------------
N. Wires
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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