Codeforces Round 659 (Div. 1)


A. String Transformation 1
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
-1
3
2
-1
----------------------------------------------------------------------------------------------------
B. GameGame
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
1 2 2
3
2 2 3
5
0 0 0 2 2
Output
WIN
LOSE
DRAW
Input
4
5
4 1 5 1 3
4
1 0 1 6
1
0
2
5 4
Output
WIN
WIN
DRAW
WIN
----------------------------------------------------------------------------------------------------
C. String Transformation 2
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
Output
2
3
3
2
4
----------------------------------------------------------------------------------------------------
D. Rearrange
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
3 5 6
1 7 9
4 8 2
Output
9 5 1
7 8 2
3 6 4
Input
2 2
4 1
3 2
Output
4 1
3 2
Input
3 4
12 10 8 6
3 4 5 7
2 11 9 1
Output
12 8 6 1
10 11 9 2
3 4 5 7
----------------------------------------------------------------------------------------------------
E. Strange Operation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
000
Output
3
Input
0101
Output
6
Input
0001111
Output
16
Input
00101100011100
Output
477
----------------------------------------------------------------------------------------------------
F. Special Edges
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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