Yandex.Algorithm 2011: Round 2


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

Examples
Input
3 7
Output
20
Input
1 1
Output
8
Input
8 10
Output
890
----------------------------------------------------------------------------------------------------
B. Tetris revisited
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
...
#.#
Output
000
#0#
Input
3 3
.#.
...
..#
Output
5#1
511
55#
Input
3 3
...
.##
.#.
Output
-1
Input
1 2
##
Output
##
----------------------------------------------------------------------------------------------------
C. Genetic engineering
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1
A
Output
1
Input
6 2
CAT
TACT
Output
2
----------------------------------------------------------------------------------------------------
D. Powerful array
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 2 1
1 2
1 3
Output
3
6
Input
8 3
1 1 2 2 1 3 1 1
2 7
1 6
2 7
Output
20
20
20
----------------------------------------------------------------------------------------------------
E. Long sequence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
Output
1 1
1 0
Input
3
Output
0 1 1
1 1 1
----------------------------------------------------------------------------------------------------
