Codeforces Round 639 (Div. 1)


A. Hilbert's Hotel
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1
14
2
1 -1
4
5 5 5 1
3
3 2 1
2
0 1
5
-239 -2 -100 -3 -11
Output
YES
YES
YES
NO
NO
YES
----------------------------------------------------------------------------------------------------
B. Monopole Magnets
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
.#.
###
##.
Output
1
Input
4 2
##
.#
.#
##
Output
-1
Input
4 5
....#
####.
.###.
.#...
Output
2
Input
2 1
.
#
Output
-1
Input
3 5
.....
.....
.....
Output
0
----------------------------------------------------------------------------------------------------
C. Quantifier Question
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
1 2
Output
1
AE
Input
4 3
1 2
2 3
3 1
Output
-1
Input
3 2
1 3
2 3
Output
2
AAE
----------------------------------------------------------------------------------------------------
D. Résumé Review
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 32
1 2 3 4 5 5 5 5 5 5
Output
1 2 3 3 3 4 4 4 4 4 
Input
5 8
4 4 8 2 1
Output
2 2 2 1 1 
----------------------------------------------------------------------------------------------------
E. Train Tracks
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
1 2 1
1 3 2
3 4 1
3 5 3
2 1
4 2
2 6
5 10
Output
-1 6
Input
5 4
1 2 1
1 3 2
3 4 1
3 5 3
5 1
4 2
4 3
2 4
Output
4 0
Input
11 6
1 2 1
1 3 2
3 4 1
3 5 2
5 6 1
5 7 2
7 8 1
7 9 2
9 10 1
9 11 1
2 1
8 3
6 5
10 7
4 9
2 11
Output
11 4
----------------------------------------------------------------------------------------------------
F. Piet's Palette
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
mix 2 2 1 R
mix 2 1 3 Y
Output
YES
YB.
Input
2 3
mix 1 2 Y
RB 1 2
mix 1 2 W
Output
NO
Input
1 3
RY 1 1
YB 1 1
mix 1 1 B
Output
YES
R
Input
3 8
mix 2 1 2 R
mix 2 1 3 Y
RY 2 2 3
RB 3 1 2 3
YB 3 1 2 3
mix 1 1 W
mix 1 2 B
mix 1 3 Y
Output
YES
.RY
----------------------------------------------------------------------------------------------------
