Codeforces Round 502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2)


A. The Rank
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
100 98 100 100
100 100 100 100
100 100 99 99
90 99 90 100
100 98 60 99
Output
2
Input
6
100 80 90 99
60 60 60 60
90 60 100 60
60 100 60 80
100 100 0 100
0 0 0 0
Output
1
----------------------------------------------------------------------------------------------------
B. The Bits
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
01011
11001
Output
4
Input
6
011000
010011
Output
6
----------------------------------------------------------------------------------------------------
C. The Phone Number
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
Output
3 4 1 2
Input
2
Output
2 1
----------------------------------------------------------------------------------------------------
D. The Wu
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 4 5
40 20
01
01
10
11
00 20
00 40
11 20
11 40
11 60
Output
2
4
2
3
4
Input
1 2 4
100
0
1
0 0
0 100
1 0
1 100
Output
1
2
1
2
----------------------------------------------------------------------------------------------------
E. The Supersonic Rocket
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
0 0
0 2
2 0
0 2
2 2
2 0
1 1
Output
YES
Input
3 4
0 0
0 2
2 0
0 2
2 2
2 0
0 0
Output
NO
----------------------------------------------------------------------------------------------------
F. The Neutral Zone
time limit per test: 5 seconds
memory limit per test: 16 megabytes
input: standard input
output: standard output

Examples
Input
12 0 0 1 0
Output
63
Input
4 1 2 3 4
Output
136
----------------------------------------------------------------------------------------------------
G. The Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 10
1 2 1 2 5 4 5
1 2
3 2
3 1
1 1
1 1
3 5
3 7
3 4
2 2
3 5
Output
black
white
black
white
black
white
Input
8 11
1 1 2 3 3 6 6
1 1
1 1
1 3
3 2
3 4
3 6
3 7
2 3
1 6
3 7
3 6
Output
black
white
black
white
white
black
----------------------------------------------------------------------------------------------------
H. The Films
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6 4 4
1 2 3 4 4 4
1 4 0
1 3 2
1 4 2
1 5 2
Output
6
26730
12150
4860
Input
5 5 3
1 2 3 4 5
1 2 100000
1 4 4
3 5 5
Output
494942218
13125
151632
----------------------------------------------------------------------------------------------------
