Educational Codeforces Round 102 (Rated for Div. 2)


A. Replacing Elements
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5 3
2 3 2 5 4
3 4
2 4 4
5 4
2 1 5 3 6
Output
NO
YES
YES
----------------------------------------------------------------------------------------------------
B. String LCM
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
baba
ba
aa
aaa
aba
ab
Output
baba
aaaaaa
-1
----------------------------------------------------------------------------------------------------
C. No More Inversions
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1
2 2
3 2
4 3
Output
1 
1 2 
2 1 
1 3 2 
----------------------------------------------------------------------------------------------------
D. Program
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
8 4
-+--+--+
1 8
2 8
2 5
1 1
4 10
+-++
1 1
1 2
2 2
1 3
2 3
3 3
1 4
2 4
3 4
4 4
Output
1
2
4
4
3
3
4
2
3
2
1
2
2
2
----------------------------------------------------------------------------------------------------
E. Minimum Path
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
5 3 4
2 1 1
3 2 2
2 4 2
Output
1 2 2 4 
Input
6 8
3 1 1
3 6 2
5 4 2
4 2 2
6 1 1
5 2 1
3 2 3
1 5 4
Output
2 1 4 3 1 
Input
7 10
7 5 5
2 3 3
4 7 1
5 3 6
2 7 6
6 2 6
3 7 6
4 2 1
3 1 4
1 7 4
Output
3 4 2 7 7 3 
----------------------------------------------------------------------------------------------------
F. Strange Set
time limit per test: 4 seconds
memory limit per test: 32 megabytes
input: standard input
output: standard output

Examples
Input
9
4 7 3 4 5 6 7 8 13
-2 3 -19 5 -6 7 -8 9 1
Output
16
Input
2
42 42
-37 13
Output
0
Input
2
42 42
13 -37
Output
13
----------------------------------------------------------------------------------------------------
G. Tiles
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4 2
2 3
Output
850
Input
3
4 1
2 3
3 1
Output
10150
Input
8
328 323
867 868
715 718
721 722
439 435
868 870
834 834
797 796
Output
759099319
----------------------------------------------------------------------------------------------------
