Educational Codeforces Round 50 (Rated for Div. 2)


A. Function Height
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
Output
1
Input
4 12
Output
3
Input
999999999999999999 999999999999999986
Output
1
----------------------------------------------------------------------------------------------------
B. Diagonal Walking v.2
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 2 3
4 3 7
10 1 9
Output
1
6
-1
----------------------------------------------------------------------------------------------------
C. Classy Numbers
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1000
1024 1024
65536 65536
999999 1000001
Output
1000
1
0
2
----------------------------------------------------------------------------------------------------
D. Vasya and Arrays
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
11 2 3 5 7
4
11 7 3 7
Output
3
Input
2
1 2
1
100
Output
-1
Input
3
1 2 3
3
1 2 3
Output
3
----------------------------------------------------------------------------------------------------
E. Covered Points
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
0 0 4 4
-1 5 4 0
4 0 4 4
5 2 11 2
6 1 6 7
5 6 11 6
10 1 10 7
7 0 9 8
10 -1 11 -1
Output
42
Input
4
-1 2 1 2
-1 0 1 0
-1 0 0 3
0 3 1 0
Output
7
----------------------------------------------------------------------------------------------------
F. Relatively Prime Powers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
2
72
10
Output
2
1
61
6
----------------------------------------------------------------------------------------------------
G. Sources and Sinks
time limit per test: 7 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 1
1 2
Output
NO
Input
3 3
1 2
1 3
2 3
Output
YES
Input
4 4
1 2
1 3
4 2
4 3
Output
YES
----------------------------------------------------------------------------------------------------
