Educational Codeforces Round 167 (Rated for Div. 2)


A. Catch the Coin
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
24 42
-2 -1
-1 -2
0 -50
15 0
Output
YES
YES
NO
NO
YES
----------------------------------------------------------------------------------------------------
B. Substring and Subsequence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
aba
cb
er
cf
mmm
mmm
contest
test
cde
abcefg
Output
4
4
3
7
7
----------------------------------------------------------------------------------------------------
C. Two Movies
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2
-1 1
-1 -1
1
-1
-1
5
0 -1 1 0 1
-1 1 0 0 1
4
-1 -1 -1 1
-1 1 1 1
Output
0
-1
1
1
----------------------------------------------------------------------------------------------------
D. Smithing Skill
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
9 6 7 5 5
8 4 5 1 2
10 4 7
Output
12
Input
3 4
10 20 20
0 0 0
9 10 19 20
Output
8
Input
1 5
3
1
1000000000 1000000000 1000000000 1000000000 1000000000
Output
4999999990
----------------------------------------------------------------------------------------------------
E. Distance to Different
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2
Output
1
Input
4 3
Output
3
Input
6 2
Output
20
Input
6 5
Output
3
Input
133 7
Output
336975971
----------------------------------------------------------------------------------------------------
F. Simultaneous Coloring
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2 4
1 1 R
2 2 R
1 2 B
2 1 B
Output
0
0
0
16
Input
3 5 10
1 1 B
2 5 B
2 2 B
2 3 R
2 1 B
3 2 R
3 3 B
1 2 R
1 3 B
3 1 B
Output
0
0
0
0
0
0
16
16
25
25
----------------------------------------------------------------------------------------------------
