Educational Codeforces Round 20


A. Maximal Binary Matrix
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
Output
1 0 
0 0 
Input
3 2
Output
1 0 0 
0 1 0 
0 0 0 
Input
2 5
Output
-1
----------------------------------------------------------------------------------------------------
B. Distances to Zero
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
2 1 0 3 0 0 3 2 4
Output
2 1 0 1 0 0 1 2 3 
Input
5
0 1 2 3 4
Output
0 1 2 3 4 
Input
7
5 6 0 1 -2 3 4
Output
2 1 0 1 2 3 4 
----------------------------------------------------------------------------------------------------
C. Maximal GCD
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 3
Output
1 2 3
Input
8 2
Output
2 6
Input
5 3
Output
-1
----------------------------------------------------------------------------------------------------
D. Magazine Ad
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
garage for sa-le
Output
7
Input
4
Edu-ca-tion-al Ro-unds are so fun
Output
10
----------------------------------------------------------------------------------------------------
E. Roma and Poker
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
L??
Output
LDL
Input
3 1
W??
Output
NO
Input
20 5
?LLLLLWWWWW?????????
Output
WLLLLLWWWWWWWWLWLWDW
----------------------------------------------------------------------------------------------------
F. Coprime Subsequences
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 3
Output
5
Input
4
1 1 1 1
Output
15
Input
7
1 3 5 15 3 105 35
Output
100
----------------------------------------------------------------------------------------------------
G. Periodic RMQ Problem
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

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