Codeforces Round 166 (Div. 2)


A. Beautiful Year
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1987
Output
2013
Input
2013
Output
2014
----------------------------------------------------------------------------------------------------
B. Prime Matrix
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2 3
5 6 1
4 4 1
Output
1
Input
2 3
4 8 8
9 2 9
Output
3
Input
2 2
1 3
4 2
Output
0
----------------------------------------------------------------------------------------------------
C. Secret
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
11 3
Output
3 1 2 1 1 2 3 2 2 3 1
Input
5 2
Output
-1
----------------------------------------------------------------------------------------------------
D. Good Substrings
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
----------------------------------------------------------------------------------------------------
E. Three Horses
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 6
2
Output
11
Input
1 6
7
Output
14
Input
2 10
13 7
Output
36
----------------------------------------------------------------------------------------------------
