VK Cup 2015 - Round 2


A. Berland Miners
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
5 8 4 6 3 12
1 2
1 3
4 2
2 5
6 3
6
7 4 2 5 3 11
Output
6
Input
7
10 14 7 12 4 50 1
1 2
2 3
2 4
5 1
6 5
1 7
6
7 3 4 8 8 10
Output
0
Input
3
4 2 8
1 2
1 3
2
17 15
Output
-1
----------------------------------------------------------------------------------------------------
B. Work Group
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
-1 3
1 2
1 1
1 4
4 5
4 3
5 2
Output
17
----------------------------------------------------------------------------------------------------
C. Board Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 1 2 2
Output
Polycarp
Input
4 7 7 4
Output
Vasiliy
----------------------------------------------------------------------------------------------------
D. Landmarks
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
0 20 40 100
15 40
Output
10
Input
3
0 4 10 28 30
9 13 5
Output
0
----------------------------------------------------------------------------------------------------
E. Correcting Mistakes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
reading
trading
Output
1
Input
5
sweet
sheep
Output
0
Input
3
toy
try
Output
2
----------------------------------------------------------------------------------------------------
F. Encoding
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
11 5
abacabadaba
acaba
Output
3
1 3 7
Input
21 13
paraparallelogramgram
qolorreraglom
Output
1
5
----------------------------------------------------------------------------------------------------
