Technocup 2019 - Final


A. Technogoblet of Fire
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 3 1
1 5 3 4 6 7 2
1 3 1 2 1 2 3
3
Output
1
Input
8 4 4
1 2 3 4 5 6 7 8
4 3 2 1 4 3 2 1
3 4 5 6
Output
2
----------------------------------------------------------------------------------------------------
B. System Testing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
49 100
Output
1
Input
4 2
32 100 33 1
Output
2
Input
14 5
48 19 6 9 50 20 3 42 38 43 36 21 44 6
Output
5
----------------------------------------------------------------------------------------------------
C. Diana and Liana
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 3 2 2
1 2 3 3 2 1 2
2 2
Output
1
4 
Input
13 4 3 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
-1
Input
13 4 1 3
3 2 6 4 1 4 4 7 1 3 3 2 4
4 3 4
Output
9
1 2 3 4 5 9 11 12 13
----------------------------------------------------------------------------------------------------
D. Compress String
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 1
aba
Output
7
Input
4 1 1
abcd
Output
4
Input
4 10 1
aaaa
Output
12
----------------------------------------------------------------------------------------------------
E. Once in a casino
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
223
322
Output
2
1 1
2 -1
Input
2
20
42
Output
2
1 1
1 1
Input
2
35
44
Output
-1
----------------------------------------------------------------------------------------------------
F. Power Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5 1 3 2 1
1 2
2 3
2 4
1 5
Output
4 3
2 4 5 
Input
3
1 1 1
1 2
1 3
Output
2 3
1 2 3 
----------------------------------------------------------------------------------------------------
G. The very same Munchhausen
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
Output
6
Input
3
Output
6669
Input
10
Output
-1
----------------------------------------------------------------------------------------------------
H. Secret Letters
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 1 4
0 P
1 W
3 P
5 P
8 P
10
Output
16
Input
10 10 94
17 W
20 W
28 W
48 W
51 P
52 W
56 W
62 P
75 P
78 P
87
Output
916
----------------------------------------------------------------------------------------------------
