Codeforces Round 644 (Div. 3)


A. Minimal Square
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
3 2
4 2
1 1
3 1
4 7
1 3
7 4
100 100
Output
16
16
4
9
64
9
64
40000
----------------------------------------------------------------------------------------------------
B. Honest Coach
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
3 1 2 6 4
6
2 1 3 2 4 3
4
7 9 3 1
2
1 1000
3
100 150 200
Output
1
0
2
999
50
----------------------------------------------------------------------------------------------------
C. Similar Pairs
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
4
11 14 16 12
2
1 8
4
1 1 1 1
4
1 2 5 6
2
12 13
6
1 6 3 10 5 8
6
1 12 3 10 5 8
Output
YES
NO
YES
YES
YES
YES
NO
----------------------------------------------------------------------------------------------------
D. Buying Shovels
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
8 7
8 1
6 10
999999733 999999732
999999733 999999733
Output
2
8
1
999999733
1
----------------------------------------------------------------------------------------------------
E. Polygon
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
----------------------------------------------------------------------------------------------------
F. Spy-string
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 4
abac
zbab
2 4
aaaa
bbbb
3 3
baa
aaa
aab
2 2
ab
bb
3 1
a
b
c
Output
abab
-1
aaa
ab
z
----------------------------------------------------------------------------------------------------
G. A/B Matrix
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2
Output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1
----------------------------------------------------------------------------------------------------
H. Binary Median
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 3
010
001
111
4 3
000
111
100
011
1 1
1
1 1
0
3 2
00
01
10
Output
100
010
0
1
11
----------------------------------------------------------------------------------------------------
