Codeforces Round 547 (Div. 3)


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

Examples
Input
120 51840
Output
7
Input
42 42
Output
0
Input
48 72
Output
-1
----------------------------------------------------------------------------------------------------
B. Maximal Continuous Rest
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 0 1 0 1
Output
2
Input
6
0 1 0 1 1 0
Output
2
Input
7
1 0 1 1 1 0 1
Output
3
Input
3
0 0 0
Output
0
----------------------------------------------------------------------------------------------------
C. Polycarp Restores Permutation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
-2 1
Output
3 1 2 
Input
5
1 1 1 1
Output
1 2 3 4 5 
Input
4
-1 2 2
Output
-1
----------------------------------------------------------------------------------------------------
D. Colored Boots
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
codeforces
dodivthree
Output
5
7 8
4 9
2 2
9 10
3 1
Input
7
abaca?b
zabbbcc
Output
5
6 5
2 3
4 6
7 4
1 2
Input
9
bambarbia
hellocode
Output
0
Input
10
code??????
??????test
Output
10
6 2
1 6
7 3
3 5
4 8
9 7
5 1
2 4
10 9
8 10
----------------------------------------------------------------------------------------------------
E. Superhero Battle
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1000 6
-100 -200 -300 125 77 -4
Output
9
Input
1000000000000 5
-1 0 0 0 0
Output
4999999999996
Input
10 4
-3 -6 5 4
Output
-1
----------------------------------------------------------------------------------------------------
F1. Same Sum Blocks (Easy)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
4 1 2 2 1 5 3
Output
3
7 7
2 3
4 5
Input
11
-5 -4 -3 -2 -1 0 1 2 3 4 5
Output
2
3 4
1 1
Input
4
1 1 1 1
Output
4
4 4
1 1
2 2
3 3
----------------------------------------------------------------------------------------------------
F2. Same Sum Blocks (Hard)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
4 1 2 2 1 5 3
Output
3
7 7
2 3
4 5
Input
11
-5 -4 -3 -2 -1 0 1 2 3 4 5
Output
2
3 4
1 1
Input
4
1 1 1 1
Output
4
4 4
1 1
2 2
3 3
----------------------------------------------------------------------------------------------------
G. Privatization of Roads in Treeland
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 2
1 4
4 3
3 5
3 6
5 2
Output
2
1 2 1 1 2 
Input
4 2
3 1
1 4
1 2
Output
1
1 1 1 
Input
10 2
10 3
1 2
1 3
1 4
2 5
2 6
2 7
3 8
3 9
Output
3
1 1 2 3 2 3 1 3 1 
----------------------------------------------------------------------------------------------------
