Codeforces Round 743 (Div. 1)


A. Book
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4
1 2
0
2 1 4
1 2
5
1 5
1 1
1 2
1 3
1 4
5
0
0
2 1 2
1 2
2 2 1
4
2 2 3
0
0
2 3 2
5
1 2
1 3
1 4
1 5
0
Output
2
-1
1
2
5
----------------------------------------------------------------------------------------------------
B. Xor of 3
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3
5
1 2 3 2 1
4
1 1 2 2
5
1 2 1 4 2
Output
2
1
3
----------------------------------------------------------------------------------------------------
D. Bridge Club
time limit per test: 2.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 1
8 3 5 7 1 10 3 2
Output
13
Input
2 3
7 4 5 7
Output
23
Input
3 2
1 9 1 5 7 8 1 1
Output
29
----------------------------------------------------------------------------------------------------
E. Polygon
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 4
-2 -4
2 -2
4 2
1 5
0 5
-4 4
-5 0
-5 -1
Output
11
Input
6 3
2 -2
2 -1
1 2
0 2
-2 1
-1 0
Output
3
----------------------------------------------------------------------------------------------------
F. Stations
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 3
2 1 1
1 1 1
2 1 1
Output
1
1
Input
5 10
1 3 4
2 3 5
1 1 5
2 1 5
1 4 5
2 2 4
1 2 3
2 1 3
1 5 5
2 2 5
Output
4
10
5
4
5
----------------------------------------------------------------------------------------------------
