Codeforces Round 516 (Div. 1, by Moscow Team Olympiad)


A. Oh Those Palindromes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
oolol
Output
ololo
Input
16
gagadbcgghhchbdf
Output
abccbaghghghgdfd
----------------------------------------------------------------------------------------------------
B. Labyrinth
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 5
3 2
1 2
.....
.***.
...**
*....
Output
10
Input
4 4
2 2
0 1
....
..*.
....
....
Output
7
----------------------------------------------------------------------------------------------------
C. Dwarves, Hats and Extrasensory Abilities
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
black
black
white
white
black
Output
0 0
3 1
2 3
4 4
0 2
1 3 4 1
----------------------------------------------------------------------------------------------------
D. Candies for Children
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 1 4 12
Output
2
Input
5 3 4 10
Output
3
Input
10 5 5 1
Output
10
Input
5 4 5 6
Output
-1
----------------------------------------------------------------------------------------------------
E. Lasers and Mirrors
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 1 3 2
Output
3
.\..
\\..
/../
...\
----------------------------------------------------------------------------------------------------
F. String Journey
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
7
abcdbcc
Output
3
Input
4
bbcb
Output
2
----------------------------------------------------------------------------------------------------
