Codeforces Round 524 (Div. 2)


A. Petya and Origami
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
Output
10
Input
15 6
Output
38
----------------------------------------------------------------------------------------------------
B. Margarite and the best present
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 3
2 5
5 5
4 4
2 3
Output
-2
-2
-5
4
-1
----------------------------------------------------------------------------------------------------
C. Masha and two friends
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 2
1 1 2 2
1 1 2 2
3 4
2 2 3 2
3 1 4 3
1 5
1 1 5 1
3 1 5 1
4 4
1 1 4 2
1 3 4 4
3 4
1 2 4 2
2 1 3 3
Output
0 4
3 9
2 3
8 8
4 8
----------------------------------------------------------------------------------------------------
D. Olya and magical square
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 1
2 2
2 12
Output
YES 0
YES 1
NO
----------------------------------------------------------------------------------------------------
E. Sonya and Matrix Beauty
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 3
aba
Output
4
Input
2 3
aca
aac
Output
11
Input
3 5
accac
aaaba
cccaa
Output
43
----------------------------------------------------------------------------------------------------
F. Katya and Segments Sets
time limit per test: 3.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 5 9
3 6 3
1 3 1
2 4 2
1 2 3
4 6 5
2 5 3
7 9 4
2 3 1
4 10 4
1 2 2 3
1 2 2 4
1 3 1 5
2 3 3 6
2 4 2 9
Output
no
yes
yes
no
yes
----------------------------------------------------------------------------------------------------
