Codeforces Round 218 (Div. 2)


A. K-Periodic Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 2
2 1 2 2 2 1
Output
1
Input
8 4
1 1 2 1 1 1 2 1
Output
0
Input
9 3
2 1 1 1 2 1 1 1 2
Output
3
----------------------------------------------------------------------------------------------------
B. Fox Dividing Cheese
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
15 20
Output
3
Input
14 8
Output
-1
Input
6 6
Output
0
----------------------------------------------------------------------------------------------------
C. Hamburgers
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
BBBSSC
6 4 1
1 2 3
4
Output
2
Input
BBC
1 10 1
1 10 1
21
Output
7
Input
BSC
1 1 1
1 1 3
1000000000000
Output
200000000001
----------------------------------------------------------------------------------------------------
D. Vessels
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
5 10
6
1 1 4
2 1
1 2 5
1 1 4
2 1
2 2
Output
4
5
8
Input
3
5 10 8
6
1 1 12
2 2
1 1 6
1 3 2
2 2
2 3
Output
7
10
5
----------------------------------------------------------------------------------------------------
E. Subway Innovation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 100 101
2
Output
2 3 
----------------------------------------------------------------------------------------------------
