Educational Codeforces Round 47 (Rated for Div. 2)


A. Game Shopping
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4
2 4 5 2 4
5 3 4 6
Output
3
Input
5 2
20 40 50 20 40
19 20
Output
0
Input
6 4
4 8 15 16 23 42
1000 1000 1000 1000
Output
4
----------------------------------------------------------------------------------------------------
B. Minimum Ternary String
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
100210
Output
001120
Input
11222121
Output
11112222
Input
20
Output
20
----------------------------------------------------------------------------------------------------
C. Annoying Present
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
-1 3
0 0
-1 -4
Output
-2.500000000000000
Input
3 2
0 2
5 0
Output
7.000000000000000
----------------------------------------------------------------------------------------------------
D. Relatively Prime Graph
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
Output
Possible
2 5
3 2
5 1
3 4
4 1
5 4
Input
6 12
Output
Impossible
----------------------------------------------------------------------------------------------------
E. Intercity Travelling
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2
Output
5
Input
4
1 3 3 7
Output
60
----------------------------------------------------------------------------------------------------
F. Dominant Indices
time limit per test: 4.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2
2 3
3 4
Output
0
0
0
0
Input
4
1 2
1 3
1 4
Output
1
0
0
0
Input
4
1 2
2 3
2 4
Output
2
1
0
0
----------------------------------------------------------------------------------------------------
G. Allowed Letters
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
bedefead
5
2 e
1 dc
5 b
7 ef
6 ef
Output
deadbeef
Input
abacaba
0
Output
aaaabbc
Input
fc
2
1 cfab
2 f
Output
cf
----------------------------------------------------------------------------------------------------
