Codeforces Round 734 (Div. 3)


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

Examples
Input
6
1000
30
1
32
1000000000
5
Output
334 333
10 10
1 0
10 11
333333334 333333333
1 2
----------------------------------------------------------------------------------------------------
B1. Wonderful Coloring - 1
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
kzaaa
codeforces
archive
y
xxxxxx
Output
2
5
3
0
1
----------------------------------------------------------------------------------------------------
B2. Wonderful Coloring - 2
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
10 3
3 1 1 1 1 10 3 10 10 2
4 4
1 1 1 1
1 1
1
13 1
3 1 4 1 5 9 2 6 5 3 5 8 9
13 2
3 1 4 1 5 9 2 6 5 3 5 8 9
13 3
3 1 4 1 5 9 2 6 5 3 5 8 9
Output
1 1 0 2 3 2 2 1 3 3
4 2 1 3
1
0 0 1 1 0 1 1 1 0 1 1 1 0
2 1 2 2 1 1 1 1 2 1 0 2 2
1 1 3 2 1 3 3 1 2 2 3 2 0
----------------------------------------------------------------------------------------------------
C. Interesting Story
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3
bac
aaada
e
3
aba
abcde
aba
2
baba
baba
4
ab
ab
c
bc
5
cbdca
d
a
d
e
3
b
c
ca
Output
3
2
0
2
3
2
----------------------------------------------------------------------------------------------------
D1. Domino (easy version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
4 4 2
2 3 0
3 2 3
1 2 0
2 4 2
5 2 2
2 17 16
2 1 1
Output
YES
YES
YES
NO
YES
NO
YES
NO
----------------------------------------------------------------------------------------------------
D2. Domino (hard version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
4 4 2
2 3 0
3 2 3
1 2 0
2 4 2
5 2 2
2 17 16
2 1 1
Output
YES
accx
aegx
bega
bdda
YES
aha
aha
YES
zz
aa
zz
NO
YES
aaza
bbza
NO
YES
bbaabbaabbaabbaay
ddccddccddccddccy
NO
----------------------------------------------------------------------------------------------------
E. Fixed Points
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
----------------------------------------------------------------------------------------------------
F. Equidistant Vertices
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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