Codeforces Round 584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)


A. Paint the Numbers
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
10 2 3 5 4 2
Output
3
Input
4
100 100 100 100
Output
1
Input
8
7 6 5 4 3 2 2 3
Output
4
----------------------------------------------------------------------------------------------------
B. Koala and Lights
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
101
3 3
3 2
3 1
Output
2
Input
4
1111
3 4
5 2
3 1
3 2
Output
4
Input
6
011100
5 3
5 5
2 4
3 5
4 2
1 5
Output
6
----------------------------------------------------------------------------------------------------
C. Paint the Digits
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
12
040425524644
1
0
9
123456789
2
98
3
987
Output
121212211211
1
222222222
21
-
----------------------------------------------------------------------------------------------------
D. Cow and Snacks
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
1 2
4 3
1 4
3 4
Output
1
Input
6 5
2 3
2 1
3 4
6 5
4 5
Output
0
----------------------------------------------------------------------------------------------------
E1. Rotate Columns (easy version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7
Output
12
29
----------------------------------------------------------------------------------------------------
E2. Rotate Columns (hard version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3
2 5 7
4 2 4
3 6
4 1 5 2 10 4
8 6 6 4 9 10
5 4 9 5 8 7
3 3
9 9 9
1 1 1
1 1 1
Output
12
29
27
----------------------------------------------------------------------------------------------------
F. Koala and Notebook
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
11 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
Output
1
12
123
1234
12345
123456
1234567
12345678
123456789
345678826
Input
12 19
1 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
3 11
11 12
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
Output
1
12
13
14
15
16
17
18
19
1210
121011
Input
12 14
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
1 3
1 4
1 10
Output
1
12
13
134
1345
13456
1498
149
14
1410
141011
----------------------------------------------------------------------------------------------------
G1. Into Blocks (easy version)
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 0
3 7 3 7 3
Output
2
Input
10 0
1 2 1 2 3 1 1 1 50 1
Output
4
Input
6 0
6 6 3 3 4 4
Output
0
Input
7 0
3 3 1 3 2 1 2
Output
4
----------------------------------------------------------------------------------------------------
G2. Into Blocks (hard version)
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
1 2 1 2 1
2 1
4 1
5 3
2 3
4 2
2 1
Output
2
1
0
0
2
3
0
----------------------------------------------------------------------------------------------------
H. Moving Walkways
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 5
0 2 2.0
Output
3.000000000000
Input
1 5
2 4 0.91
Output
3.808900523560
Input
3 1000
0 990 1.777777
995 996 1.123456789
996 1000 2.0
Output
361.568848429553
----------------------------------------------------------------------------------------------------
