Codeforces Round 743 (Div. 2)


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

Examples
Input
7
3
007
4
1000
5
00000
3
103
4
2020
9
123456789
30
001678294039710047203946100020
Output
7
2
0
5
6
53
115
----------------------------------------------------------------------------------------------------
B. Swaps
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
3 1
4 2
3
5 3 1
2 4 6
5
7 5 9 1 3
2 4 6 10 8
Output
0
2
3
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. 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
----------------------------------------------------------------------------------------------------
F. 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
----------------------------------------------------------------------------------------------------
