Educational Codeforces Round 49 (Rated for Div. 2)


A. Palindromic Twist
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
6
abccba
2
cf
4
adfa
8
abaazaba
2
ml
Output
YES
NO
YES
NO
NO
----------------------------------------------------------------------------------------------------
B. Numbers on the Chessboard
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5
1 1
4 4
4 3
3 2
2 4
Output
1
8
16
13
4
Input
5 4
2 1
4 2
3 3
3 4
Output
16
9
7
20
----------------------------------------------------------------------------------------------------
C. Minimum Value Rectangle
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
7 2 2 7
8
2 8 1 4 8 2 1 5
5
5 5 5 5 5
Output
2 7 7 2
2 2 1 1
5 5 5 5
----------------------------------------------------------------------------------------------------
D. Mouse Hunt
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 3 2 10
1 3 4 3 3
Output
3
Input
4
1 10 2 10
2 4 2 2
Output
10
Input
7
1 1 1 1 1 1 1
2 2 2 3 6 7 6
Output
2
----------------------------------------------------------------------------------------------------
E. Inverse Coloring
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
Output
0
Input
2 3
Output
6
Input
49 1808
Output
359087121
----------------------------------------------------------------------------------------------------
F. Session in BSU
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 5
1 7
Output
5
Input
3
5 13
1 5
1 7
Output
7
Input
3
10 40
40 80
10 80
Output
80
Input
3
99 100
99 100
99 100
Output
-1
----------------------------------------------------------------------------------------------------
G. X-mouse in the Campus
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
Output
3
Input
5 2
Output
2
----------------------------------------------------------------------------------------------------
