Codeforces Round 137 (Div. 2)


A. Shooshuns and Sequence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
3 1 1
Output
1
Input
3 1
3 1 1
Output
-1
----------------------------------------------------------------------------------------------------
B. Cosmic Tables
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
----------------------------------------------------------------------------------------------------
C. Reducing Fractions
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
100 5 2
50 10
Output
2 3
2 1
1 1 1
Input
4 3
2 5 10 20
100 1 3
Output
1 1
20
3
----------------------------------------------------------------------------------------------------
D. Olympiad
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 2
1 1 1 1 1
1 1 1 1 1
Output
1 5
Input
6 7
4 3 5 6 4 4
8 6 0 4 3 4
Output
1 5
----------------------------------------------------------------------------------------------------
E. Decoding Genome
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 2
ab
ba
Output
17
Input
3 3 0
Output
27
Input
2 1 1
aa
Output
0
----------------------------------------------------------------------------------------------------
