Codeforces Round 779 (Div. 2)


A. Marin and Photoshoot
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
3
000
3
001
3
010
3
011
3
100
3
101
3
110
3
111
19
1010110000100000101
Output
4
2
1
0
2
0
0
0
17
----------------------------------------------------------------------------------------------------
B. Marin and Anti-coprime Permutation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1
2
3
4
5
6
1000
Output
0
1
0
4
0
36
665702330
----------------------------------------------------------------------------------------------------
C. Shinju and the Lost Permutation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1
1
2
1 2
2
2 2
6
1 2 4 6 3 5
6
2 3 1 2 3 4
3
3 2 1
Output
YES
YES
NO
NO
YES
NO
----------------------------------------------------------------------------------------------------
D1. 388535 (Easy Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
0 3
3 2 1 0
0 3
4 7 6 5
0 2
1 2 3
Output
0
4
3
----------------------------------------------------------------------------------------------------
D2. 388535 (Hard Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 7
3 2 1 0
4 7
4 7 6 5
1 3
0 2 1
Output
4
0
3
----------------------------------------------------------------------------------------------------
E. Gojou and Matrix Game
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
1 2 4
6 8 3
9 5 7
Output
GGG
MGG
MGG
----------------------------------------------------------------------------------------------------
F. Juju and Binary String
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 2
0011
8 6
11000011
4 3
0101
5 5
11111
Output
1
2 3
2
2 3
5 8
-1
1
1 5
----------------------------------------------------------------------------------------------------
