Codeforces Round 703 (Div. 2)


A. Shifting Stacks
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2
1 2
2
1 0
3
4 4 4
2
0 0
3
0 1 0
4
1000000000 1000000000 1000000000 1000000000
Output
YES
YES
YES
NO
NO
YES
----------------------------------------------------------------------------------------------------
B. Eastern Exhibition
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3
0 0
2 0
1 2
4
1 0
0 2
2 3
3 1
4
0 0
0 1
1 0
1 1
2
0 0
1 1
2
0 0
2 0
2
0 0
0 0
Output
1
4
4
4
3
1
----------------------------------------------------------------------------------------------------
C1. Guessing the Greatest (easy version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
4
Output
? 1 5
? 4 5
! 1
----------------------------------------------------------------------------------------------------
C2. Guessing the Greatest (hard version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
4
Output
? 1 5
? 4 5
! 1
----------------------------------------------------------------------------------------------------
D. Max Median
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 2 3 2 1
Output
2
Input
4 2
1 2 3 4
Output
3
----------------------------------------------------------------------------------------------------
E. Paired Payment
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 6
1 2 3
2 3 4
3 4 5
4 5 6
1 5 1
2 4 2
Output
0 98 49 25 114 
Input
3 2
1 2 1
2 3 2
Output
0 -1 9 
----------------------------------------------------------------------------------------------------
F. Pairs of Paths
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2
1 3
1 4
3 5
4
2 3
2 4
3 4
3 5
Output
2
Input
1
3
1 1
1 1
1 1
Output
3
Input
5
1 2
1 3
1 4
3 5
6
2 3
2 4
3 4
3 5
1 1
1 2
Output
7
----------------------------------------------------------------------------------------------------
