Contest 2050 and Codeforces Round 718 (Div. 1 + Div. 2)


A. Sum of 2050
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
205
2050
4100
20500
22550
25308639900
Output
-1
1
2
1
2
36
----------------------------------------------------------------------------------------------------
B. Morning Jogging
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3
2 3 1
Output
2
2 3
3 3 1
Input
5
1 2 3 4 5
Output
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
----------------------------------------------------------------------------------------------------
D. Explorer Space
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 10
1 1
1 1
1 1
1 1 1
1 1 1
Output
10 10 10
10 10 10
10 10 10
Input
2 2 4
1
3
4 2
Output
4 4
10 6
Input
2 2 3
1
2
3 4
Output
-1 -1
-1 -1
----------------------------------------------------------------------------------------------------
E. Group Photo
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5
2 1 2 1 1
4
9 2 2 2
1
998244353
Output
10
7
1
----------------------------------------------------------------------------------------------------
F. Reunion
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2
2 3
Output
499122177
Input
5
1 2
2 3
3 4
3 5
Output
249561089
Input
10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
Output
821796866
----------------------------------------------------------------------------------------------------
G. Starry Night Camping
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
0 0 4
0 1 5
1 0 3
1 1 1
-1 1 2
Output
12
Input
32
2 2 1
2 3 1
3 2 1
3 3 1
2 6 1
2 5 1
3 6 1
3 5 1
2 8 1
2 9 1
1 8 1
1 9 1
2 12 1
2 11 1
1 12 1
1 11 1
6 2 1
7 2 1
6 3 1
5 3 1
6 6 1
7 6 1
5 5 1
6 5 1
6 8 1
5 8 1
6 9 1
7 9 1
6 12 1
5 12 1
6 11 1
7 11 1
Output
24
----------------------------------------------------------------------------------------------------
H. Fly Around the World
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
0 1
0 1
0 1
1 1
1 1
-100 100
3
-967 541
-500 834
-724 669
-858 978
-964 962
-645 705
4
0 0
0 1
0 1
1 1
0 1
0 1
0 1
0 0
0 0
4
0 0
33 34
65 66
100 100
0 100
0 100
0 100
0 0
0 0
Output
NO
YES
YES
NO
----------------------------------------------------------------------------------------------------
