Codeforces Round 498 (Div. 3)


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

Examples
Input
5
1 2 4 5 10
Output
1 1 3 5 9
Input
10
10000 10 50605065 1 5 89 5 999999999 60506056 1000000000
Output
9999 9 50605065 1 5 89 5 999999999 60506055 999999999
----------------------------------------------------------------------------------------------------
B. Polycarp's Practice
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 3
5 4 2 6 5 1 9 2
Output
20
3 2 3
Input
5 1
1 1 1 1 1
Output
1
5
Input
4 2
1 2000 2000 2
Output
4000
2 2
----------------------------------------------------------------------------------------------------
C. Three Parts of the Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 3 1 1 4
Output
5
Input
5
1 3 2 1 4
Output
4
Input
3
4 1 2
Output
0
----------------------------------------------------------------------------------------------------
D. Two Strings Swaps
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
abacaba
bacabaa
Output
4
Input
5
zcabd
dbacz
Output
0
----------------------------------------------------------------------------------------------------
E. Military Problem
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9 6
1 1 1 3 5 3 5 7
3 1
1 5
3 4
7 3
1 8
1 9
Output
3
6
8
-1
9
4
----------------------------------------------------------------------------------------------------
F. Xor-Paths
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 11
2 1 5
7 10 0
12 6 4
Output
3
Input
3 4 2
1 3 3 3
0 3 3 2
3 0 1 1
Output
5
Input
3 4 1000000000000000000
1 3 3 3
0 3 3 2
3 0 1 1
Output
0
----------------------------------------------------------------------------------------------------
