Codeforces Round 659 (Div. 2)


A. Common Prefixes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4
1 2 4 2
2
5 3
3
1 3 1
3
0 0 0
Output
aeren
ari
arousal
around
ari
monogon
monogamy
monthly
kevinvu
kuroni
kurioni
korone
anton
loves
adhoc
problems
----------------------------------------------------------------------------------------------------
B1. Koa and the Beach (Easy Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
2 1 1
1 0
5 2 3
1 2 3 2 2
4 3 4
0 2 4 3
2 3 5
3 0
7 2 3
3 0 2 1 3 0 1
7 1 4
4 4 3 0 2 4 2
5 2 3
1 2 3 2 2
Output
Yes
No
Yes
Yes
Yes
No
No
----------------------------------------------------------------------------------------------------
B2. Koa and the Beach (Hard Version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
2 1 1
1 0
5 2 3
1 2 3 2 2
4 3 4
0 2 4 3
2 3 5
3 0
7 2 3
3 0 2 1 3 0 1
7 1 4
4 4 3 0 2 4 2
5 2 3
1 2 3 2 2
Output
Yes
No
Yes
Yes
Yes
No
No
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. 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
----------------------------------------------------------------------------------------------------
F. 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
----------------------------------------------------------------------------------------------------
