Codeforces Round 545 (Div. 1)


A. Skyscrapers
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 2 1
2 1 2
Output
2 2 2 
2 2 2 
Input
2 2
1 2
3 4
Output
2 3 
3 2 
----------------------------------------------------------------------------------------------------
B. Camp Schedule
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
101101
110
Output
110110
Input
10010110
100011
Output
01100011
Input
10
11100
Output
01
----------------------------------------------------------------------------------------------------
C. Museums Tour
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 5 3
3 1
1 2
2 4
4 1
2 3
011
110
111
001
Output
3
Input
3 3 7
1 2
1 3
2 3
1111111
0000000
0111111
Output
2
----------------------------------------------------------------------------------------------------
D. Cooperative Game
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 05 12346789
3 246789 135 0
3 246789 0 135
3 246789 0 135
2 135 0246789
1 0123456789
Output
next 0 5
next 0 1 3
next 2 3 0 1 4 5 6 7 8 9
next 9 8 7 6 5 4 3 2 1 0
next 0 1 3 5
next 1 3 5
done
----------------------------------------------------------------------------------------------------
E. Train Car Selection
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
1 8
1 1
3 1 1
3 1 1
2 1
2 1
3 1 1
2 1
3 1 5
Output
1 0
1 1
1 2
3 0
3 0
1 3
5 0
1 4
----------------------------------------------------------------------------------------------------
F. Matches Are Not a Child's Play
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 7
1 5
1 2
1 3
4 3
when 1
when 2
when 3
when 4
when 5
compare 2 3
compare 3 4
Output
4
1
3
2
5
2
4
Input
5 5
1 5
1 2
1 3
4 3
up 1
compare 2 4
compare 4 3
compare 3 1
compare 1 5
Output
2
4
3
5
----------------------------------------------------------------------------------------------------
