Codeforces Round 569 (Div. 1)


A. Valeriy and Deque
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 2 3 4 5
1
2
10
Output
1 2
2 3
5 2
Input
2 0
0 0
Output
----------------------------------------------------------------------------------------------------
B. Tolik and His Uncle
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
Output
1 1
1 3
1 2
2 2
2 3
2 1
Input
1 1
Output
1 1
----------------------------------------------------------------------------------------------------
C. Serge and Dining Room
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
1
1
1
1 1 100
Output
100
Input
1 1
1
1
1
2 1 100
Output
-1
Input
4 6
1 8 2 4
3 3 6 1 5 2
3
1 1 1
2 5 10
1 1 6
Output
8
-1
4
----------------------------------------------------------------------------------------------------
D. Fedor Runs for President
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2
Output
2
Input
4
1 2
1 3
1 4
Output
11
Input
6
1 2
1 3
3 4
3 5
4 6
Output
29
----------------------------------------------------------------------------------------------------
E. Alesya and Discrete Math
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
? 1 0
? 1 1
? 2 1
? 2 2
? 3 2
? 3 3
? 4 3
? 4 4
? 5 4
? 5 5
!
0 1
1 2
2 3
3 4
4 5
Output
0
1
1
2
2
3
3
4
4
4
5
----------------------------------------------------------------------------------------------------
