Codeforces Round 224 (Div. 2)


A. Ksenia and Pan Scales
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
AC|T
L
Output
AC|TL
Input
|ABC
XYZ
Output
XYZ|ABC
Input
W|T
F
Output
Impossible
Input
ABC|
D
Output
Impossible
----------------------------------------------------------------------------------------------------
B. Number Busters
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2 3 1 6
Output
2
Input
4 2 3 1 7
Output
4
Input
1 2 3 2 6
Output
13
Input
1 1 2 1 1
Output
0
----------------------------------------------------------------------------------------------------
C. Arithmetic Progression
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 1 7
Output
2
-2 10
Input
1
10
Output
-1
Input
4
1 3 5 9
Output
1
7
Input
4
4 3 4 5
Output
0
Input
2
2 4
Output
3
0 3 6
----------------------------------------------------------------------------------------------------
D. Ksenia and Pawns
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
#
Output
0
Input
3 4
####
#>^#
####
Output
3
Input
3 4
####
#><#
####
Output
-1
Input
7 5
#####
##v##
##v##
#####
##^##
##^##
#####
Output
4
Input
7 5
#####
##v##
##v##
##<##
##^##
##^##
#####
Output
5
----------------------------------------------------------------------------------------------------
E. Ksenia and Combinatorics
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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