Codeforces Round 559 (Div. 1)


A. The Party and Sweets
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 2 1
3 4
Output
12
Input
2 2
0 1
1 0
Output
-1
Input
2 3
1 0
1 1 2
Output
4
----------------------------------------------------------------------------------------------------
B. The minimal unique substring
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
Output
1111
Input
5 3
Output
01010
Input
7 3
Output
1011011
----------------------------------------------------------------------------------------------------
C. Permutation recovery
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3
2 3 4
2
3 3
3
-1 -1 -1
3
3 4 -1
1
2
4
4 -1 4 5
Output
1 2 3
2 1
2 1 3
-1
1
3 2 1 4
----------------------------------------------------------------------------------------------------
D. Winding polygonal line
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 1
3 1
1 3
L
Output
1 2 3
Input
6
1 0
0 1
0 2
-1 0
-1 -1
2 1
RLLR
Output
6 1 3 4 2 5
----------------------------------------------------------------------------------------------------
E. Strange device
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
00000
11011
11100
10010
Output
? 0 0 0 0 0
? 1 1 2 0 2
? 0 0 0 1 0
? 0 1 0 0 1
!
4 2
1 5
3 4
4 1
----------------------------------------------------------------------------------------------------
F. Density of subarrays
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 1
1 1 1 1
Output
0 4 6 4 1 
Input
3 3
1 2 3
Output
6 1 0 0 
Input
5 2
1 2 1 2 1
Output
10 17 4 0 0 0 
----------------------------------------------------------------------------------------------------
