Codeforces Round 546 (Div. 2)


A. Nastya Is Reading a Book
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 3
4 7
8 11
2
Output
3
Input
3
1 4
5 9
10 12
9
Output
2
Input
1
1 7
4
Output
1
----------------------------------------------------------------------------------------------------
B. Nastya Is Playing Computer Games
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
Output
6
Input
4 2
Output
13
Input
5 1
Output
15
----------------------------------------------------------------------------------------------------
C. Nastya Is Transposing Matrices
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
1 1
6 1
1 6
1 1
Output
YES
Input
2 2
4 4
4 5
5 4
4 4
Output
NO
Input
3 3
1 2 3
4 5 6
7 8 9
1 4 7
2 5 6
3 8 9
Output
YES
----------------------------------------------------------------------------------------------------
D. Nastya Is Buying Lunch
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
1 2
1 2
Output
1
Input
3 3
3 1 2
1 2
3 1
3 2
Output
2
Input
5 2
3 1 5 4 2
5 2
5 4
Output
1
----------------------------------------------------------------------------------------------------
E. Nastya Hasn't Written a Legend
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2 3
1 -1
5
s 2 3
+ 1 2
s 1 2
+ 3 1
s 2 3
Output
5
7
8
Input
3
3 6 7
3 1
3
+ 1 3
+ 2 4
s 1 3
Output
33
----------------------------------------------------------------------------------------------------
