Codeforces Round 798 (Div. 2)


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

Examples
Input
3
6 4 2
aaaaaa
bbbb
5 9 3
caaca
bedededeb
7 7 1
noskill
wxhtzdy
Output
aabaabaa
aaabbcc
dihktlwlxnyoz
----------------------------------------------------------------------------------------------------
B. Mystic Permutation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 2 3
5
2 3 4 5 1
4
2 3 1 4
1
1
Output
2 3 1
1 2 3 4 5
1 2 4 3
-1
----------------------------------------------------------------------------------------------------
C. Infected Tree
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2
1 2
4
1 2
2 3
2 4
7
1 2
1 5
2 3
2 4
5 6
5 7
15
1 2
2 3
3 4
4 5
4 6
3 7
2 8
1 9
9 10
9 11
10 12
10 13
11 14
11 15
Output
0
2
2
10
----------------------------------------------------------------------------------------------------
D. Lena and Matrix
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 2
BW
WW
WB
3 3
WWB
WBW
BWW
2 3
BBB
BBB
5 5
BWBWB
WBWBW
BWBWB
WBWBW
BWBWB
9 9
WWWWWWWWW
WWWWWWWWW
BWWWWWWWW
WWWWWWWWW
WWWWBWWWW
WWWWWWWWW
WWWWWWWWW
WWWWWWWWW
WWWWWWWWB
Output
2 1
2 2
1 2
3 3
6 5
----------------------------------------------------------------------------------------------------
E. ANDfinity
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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