School Regional Team Contest, Saratov, 2011


A. Elevator
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
front
1
Output
L
----------------------------------------------------------------------------------------------------
B. Quiz League
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
5 5
0 1 0 1 0
Output
2
Input
2 1
1 1
Output
1
----------------------------------------------------------------------------------------------------
C. Winnie-the-Pooh and honey
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
3 3
15 8 10
Output
9
----------------------------------------------------------------------------------------------------
D. Three Sons
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
3 3
1 1 1
1 1 1
1 1 1
3 3 3
Output
2
Input
2 5
1 1 1 1 1
2 2 2 2 2
3 6 6
Output
3
Input
3 3
1 2 3
3 1 2
2 3 1
5 6 7
Output
0
----------------------------------------------------------------------------------------------------
E. Put Knight!
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
2
2
1
Output
1
0
----------------------------------------------------------------------------------------------------
F. Spiders
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
1
3 1 2 2 3
Output
2
Input
2
3 1 2 1 3
4 1 2 2 3 2 4
Output
4
Input
2
5 1 2 2 3 3 4 3 5
7 3 4 1 2 2 4 4 6 2 7 6 5
Output
7
----------------------------------------------------------------------------------------------------
G. Boom
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
2 2
1 1 1 1
1 1 1 1
3
home
1
car
1
brother
1
Output
2 home car 
1 brother 
Input
2 4
1 2 2 1
2 3 2 2
4
armchair
3
quetzalcoatl
10
pilotage
5
defibrillator
7
Output
2 armchair quetzalcoatl 
2 pilotage defibrillator 
----------------------------------------------------------------------------------------------------
H. Brevity is Soul of Wit
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
6
privet
spasibo
codeforces
java
marmelad
normalno
Output
pret
sps
cdfs
java
mama
norm
Input
5
aaa
aa
a
aaaa
aaaaa
Output
-1
----------------------------------------------------------------------------------------------------
I. Luck is in Numbers
time limit per test: 1 second
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
13
Output
20
Input
2345
Output
2348
Input
88
Output
-1
----------------------------------------------------------------------------------------------------
J. Minimum Sum
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: input.txt
output: output.txt

Examples
Input
5
-7 -3
9 0
-8 6
7 -8
4 -5
Output
3 2 4 2
Input
5
3 2
-4 7
-6 0
-8 4
5 1
Output
3 4 5 4
----------------------------------------------------------------------------------------------------
