Codeforces Round 124 (Div. 1)


A. Lexicographically Maximum Subsequence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
ababba
Output
bbba
Input
abbcbccacbbcbaaba
Output
cccccbba
----------------------------------------------------------------------------------------------------
B. Infinite Maze
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
##.#
##S#
#..#
#.##
#..#
Output
Yes
Input
5 4
##.#
##S#
#..#
..#.
#.##
Output
No
----------------------------------------------------------------------------------------------------
C. Paint Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 3
2 3
0 0
1 1
2 0
Output
1 3 2
Input
4
1 2
2 3
1 4
-1 -2
3 5
-3 3
2 0
Output
4 2 1 3
----------------------------------------------------------------------------------------------------
D. The Next Good String
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
aaaaaaa
Output
aabbcaa
Input
3
zzyzzzz
Output
Impossible
Input
4
abbabbbabbb
Output
abbbcaaabab
----------------------------------------------------------------------------------------------------
E. Opening Portals
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2 1
1 3 1
2 3 1
3
1 2 3
Output
2
Input
4 3
1 2 1
2 3 5
2 4 10
3
2 3 4
Output
16
Input
4 3
1 2 1000000000
2 3 1000000000
3 4 1000000000
4
1 2 3 4
Output
3000000000
----------------------------------------------------------------------------------------------------
