Codeforces Round 790 (Div. 4)


A. Lucky?
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
213132
973894
045207
000000
055776
Output
YES
NO
YES
YES
NO
----------------------------------------------------------------------------------------------------
B. Equal Candies
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
1 2 3 4 5
6
1000 1000 5 1000 1000 1000
10
1 2 3 5 1 2 7 9 13 5
3
8 8 8
1
10000000
Output
10
4975
38
0
0
----------------------------------------------------------------------------------------------------
C. Most Similar Words
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 4
best
cost
6 3
abb
zba
bef
cdu
ooo
zzz
2 7
aaabbbc
bbaezfe
3 2
ab
ab
ab
2 8
aaaaaaaa
zzzzzzzz
3 1
a
u
y
Output
11
8
35
0
200
4
----------------------------------------------------------------------------------------------------
D. X-Sum
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 4
1 2 2 1
2 4 2 4
2 2 3 1
2 4 2 4
2 1
1
0
3 3
1 1 1
1 1 1
1 1 1
3 3
0 1 1
1 0 1
1 1 0
Output
20
1
5
3
----------------------------------------------------------------------------------------------------
E. Eating Queries
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
8 7
4 3 3 1 1 4 5 9
1
10
50
14
15
22
30
4 1
1 2 3 4
3
1 2
5
4
6
Output
1
2
-1
2
3
4
8
1
1
-1
----------------------------------------------------------------------------------------------------
F. Longest Strike
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
7 2
11 11 12 13 13 14 14
5 1
6 3 5 2 1
6 4
4 3 4 3 3 4
14 2
1 1 2 2 2 3 3 3 3 4 4 4 4 4
Output
13 14
1 3
-1
1 4
----------------------------------------------------------------------------------------------------
G. White-Black Balanced Subtrees
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
7
1 1 2 3 3 5
WBBWWBW
2
1
BW
8
1 2 3 4 5 6 7
BWBWBWBW
Output
2
1
4
----------------------------------------------------------------------------------------------------
H1. Maximum Crossings (Easy Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

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