Codeforces Round 687 (Div. 2, based on Technocup 2021 Elimination Round 2)


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

Examples
Input
3
10 10 1 1
3 5 2 4
10 2 5 1
Output
18
4
6
----------------------------------------------------------------------------------------------------
B. Repainting Street
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
10 2
1 1 2 2 1 1 2 2 2 1
7 1
1 2 3 4 5 6 7
10 3
1 3 3 3 3 1 2 1 3 3
Output
3
6
2
----------------------------------------------------------------------------------------------------
C. Bouncing Ball
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
10 3 2
0101010101
2 2
5 4 1
00000
2 10
11 2 3
10110011000
4 3
Output
2
4
10
----------------------------------------------------------------------------------------------------
D. XOR-gun
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 5 6 8
Output
1
Input
3
1 2 3
Output
-1
Input
5
1 2 4 6 20
Output
2
----------------------------------------------------------------------------------------------------
E. New Game Plus!
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 0
1 1 1
Output
3
Input
5 1
-1 -2 -3 -4 5
Output
11
Input
13 2
3 1 4 1 5 -9 -2 -6 -5 -3 -5 -8 -9
Output
71
----------------------------------------------------------------------------------------------------
