Kotlin Heroes 5: ICPC Round


A. Selling Hamburgers
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
3
1 1 1
3
4 1 1
3
2 4 2
8
1 2 3 4 5 6 7 8
1
1000000000000
3
1000000000000 999999999999 1
Output
3
4
6
20
1000000000000
1999999999998
----------------------------------------------------------------------------------------------------
B. Polycarp and the Language of Gods
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
vv
v
w
vwv
vwvvwv
Output
1
0
1
1
3
----------------------------------------------------------------------------------------------------
C. Black Friday
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5 2
1 3 4 6 7
6 3
1 2 3 4 5 6
6 3
3 3 4 4 5 5
1 1
7
4 4
1 3 3 7
Output
7
4
6
7
1
----------------------------------------------------------------------------------------------------
D. Used Markers
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
1 2 1 2
2
2 1
3
1 1 1
4
2 3 1 3
Output
4 1 3 2
1 2
3 1 2
4 3 2 1
----------------------------------------------------------------------------------------------------
E. Chess Match
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
4
1 2 3 4
1 2 3 4
2
1 100
100 101
2
1 100
50 51
5
1 1 1 1 1
3 3 3 3 3
Output
3 4 1 2
1 2
2 1
5 4 2 3 1
----------------------------------------------------------------------------------------------------
F. Neural Network Problem
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5 4
1 1 5 4 5
Output
0
Input
5 2 4
6 1 5 5 6
Output
11
Input
6 1 4
3 3 1 3 1 2
Output
8
Input
6 1 3
2 2 1 2 2 1
Output
5
----------------------------------------------------------------------------------------------------
G. Number Deletion Game
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 2
3 4 1 5 2
Output
4
Input
7 3
101 108 200 1 201 109 100
Output
283
----------------------------------------------------------------------------------------------------
H. Rogue-like Game
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4 2
0 5 7
0 2 6 10
2 5 5 2
5 3 4 4
3 4 2 4
Output
3
Input
4 2 1
0 3 9 9
0 2
3 3
5 1
1 3
2 3
Output
2
Input
3 3 5
0 8 11
0 0 3
3 1 3
1 2 1
1 1 3
Output
2
----------------------------------------------------------------------------------------------------
I. Cyclic Shifts
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 5 4
abacc
ccbba
ccabc
abacc
acbbc
ababa
acbbc
Output
0
2
1
2
Input
6 4 4
daac
bcba
acad
cbdc
aaaa
bcbb
dcdd
acba
bbbb
dbcd
Output
3
1
2
-1
Input
5 10 5
ltjksdyfgg
cbhpsereqn
ijndtzbzcf
ghgcgeadep
bfzdgxqmqe
ibgcgzyfep
bbhdgxqmqg
ltgcgxrzep
ljnpseldgn
ghhpseyzcf
Output
5
3
5
-1
3
----------------------------------------------------------------------------------------------------
J. Zero-XOR Array
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
0 1 3
Output
2
Input
4
0 3 6 7
Output
6
Input
5
1 5 9 10 23
Output
20
Input
10
39 62 64 79 81 83 96 109 120 122
Output
678132
----------------------------------------------------------------------------------------------------
