Codeforces Round 325 (Div. 1)


A. Gennady the Dentist
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2
Output
2
1 3 
Input
5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9
Output
4
1 2 4 5 
----------------------------------------------------------------------------------------------------
B. Phillip and Trains
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
16 4
...AAAAA........
s.BBB......CCCCC
........DDDDD...
16 4
...AAAAA........
s.BBB....CCCCC..
.......DDDDD....
Output
YES
NO
Input
2
10 4
s.ZZ......
.....AAABB
.YYYYYY...
10 4
s.ZZ......
....AAAABB
.YYYYYY...
Output
YES
NO
----------------------------------------------------------------------------------------------------
C. Alice, Bob, Oranges and Apples
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 4
Output
3B
Input
2 2
Output
Impossible
Input
3 2
Output
1A1B
----------------------------------------------------------------------------------------------------
D. Lizard Era: Beginning
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 0 0
0 1 0
0 0 1
Output
LM
MW
MW
Input
7
0 8 9
5 9 -2
6 -8 -7
9 4 5
-4 -9 9
-4 5 2
-6 8 -7
Output
LM
MW
LM
LW
MW
LM
LW
Input
2
1 0 0
1 1 0
Output
Impossible
----------------------------------------------------------------------------------------------------
E. Present for Vitalik the Philatelist
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3 2
Output
5
Input
2
9 6
Output
0
----------------------------------------------------------------------------------------------------
F. Digits of Number Pi
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
02
10
19
Output
2
Input
023456789
10
19
Output
9
Input
31415926535
10
29
Output
20
----------------------------------------------------------------------------------------------------
