Codeforces Round 871 (Div. 4)


A. Love Story
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
coolforsez
cadafurcie
codeforces
paiuforces
forcescode
Output
4
5
0
4
9
----------------------------------------------------------------------------------------------------
B. Blank Space
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
1 0 0 1 0
4
0 1 1 1
1
0
3
1 1 1
9
1 0 0 0 1 0 0 0 1
Output
2
1
1
0
3
----------------------------------------------------------------------------------------------------
C. Mr. Perfectly Fine
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4
2 00
3 10
4 01
4 00
5
3 01
3 01
5 01
2 10
9 10
1
5 11
3
9 11
8 01
7 10
6
4 01
6 01
7 01
8 00
9 01
1 00
4
8 00
9 10
9 11
8 11
Output
7
5
5
9
-1
8
----------------------------------------------------------------------------------------------------
D. Gold Rush
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
11
6 4
9 4
4 2
18 27
27 4
27 2
27 10
1 1
3 1
5 1
746001 2984004
Output
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
----------------------------------------------------------------------------------------------------
E. The Lakes
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 3
1 2 0
3 4 0
0 0 5
1 1
0
3 3
0 1 1
1 0 1
1 1 1
5 5
1 1 1 1 1
1 0 0 0 1
1 0 5 0 1
1 0 0 0 1
1 1 1 1 1
5 5
1 1 1 1 1
1 0 0 0 1
1 1 4 0 1
1 0 0 0 1
1 1 1 1 1
Output
10
0
7
16
21
----------------------------------------------------------------------------------------------------
F. Forever Winter
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
21 20
21 20
5 20
13 20
1 3
11 3
10 3
4 8
19 8
14 8
9 7
12 7
17 7
18 6
16 6
2 6
6 15
7 15
8 15
20 15
3 15
7 6
1 2
1 3
2 4
2 5
3 6
3 7
9 8
9 3
3 6
6 2
2 1
5 2
2 7
4 3
3 8
Output
5 3
2 2
2 3
----------------------------------------------------------------------------------------------------
G. Hits Different
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
9
1
2
3
4
5
6
10
1434
1000000
Output
156
1
5
10
21
39
46
146
63145186
58116199242129511
----------------------------------------------------------------------------------------------------
H. Don't Blame Me
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
5 1
1 1 1 1 1
4 0
0 1 2 3
5 1
5 5 7 4 2
1 2
3
12 0
0 2 0 2 0 2 0 2 0 2 0 2
10 6
63 0 63 5 5 63 63 4 12 13
Output
31
10
10
1
4032
15
----------------------------------------------------------------------------------------------------
