Codeforces Beta Round 72 (Div. 1 Only)


A. Magical Array
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 1 1 4
Output
5
Input
5
-2 -2 -2 0 1
Output
8
----------------------------------------------------------------------------------------------------
B. Doctor
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
5 3 2
Sba
ccc
aac
ccc
abT
Output
bcccc
Input
3 4 1
Sxyy
yxxx
yyyT
Output
xxxx
Input
1 3 3
TyS
Output
y
Input
1 4 1
SxyT
Output
-1
----------------------------------------------------------------------------------------------------
D. Numbers
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 10 2
Output
5
Input
12 23 3
Output
2
Input
6 19 5
Output
0
----------------------------------------------------------------------------------------------------
E. Two Subsequences
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
01
10
01
Output
4
Input
4
000
111
110
001
Output
8
Input
5
10101
01010
11111
01000
10010
Output
17
----------------------------------------------------------------------------------------------------
