Kotlin Heroes: Episode 6


A. From Zero To Y
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 7
3 42
25 1337
Output
4
5
20
----------------------------------------------------------------------------------------------------
B. RBS Deletion
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
12 2
(()())((()))
6 3
()()()
8 1
(((())))
Output
4
3
2
----------------------------------------------------------------------------------------------------
C. Two Policemen
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4 1 2
7 7 1
10 2 6
8 5 2
2 1 2
20 4 14
Output
2
3
5
4
0
12
----------------------------------------------------------------------------------------------------
D. Problemsolving Marathon
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 15
3 9
2 6
Output
15
4
4
----------------------------------------------------------------------------------------------------
E. Palindromic Doubles
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
6
2 1 3 1 5 2
6
1 3 3 4 4 1
1
1
2
1 1
7
4 4 2 5 7 2 3
Output
5
4
1
2
3
----------------------------------------------------------------------------------------------------
F. Dogecoin
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4 1 2 3 2
4
1 5
2 4
3 5
5 5
Output
15 9 8 2
----------------------------------------------------------------------------------------------------
G. Painting Numbers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
Output
3 5 6 6 5 0
Input
2
Output
1 0
Input
11
Output
3 6 9 11 12 13 14 14 13 10 0
----------------------------------------------------------------------------------------------------
H. Build From Suffixes
time limit per test: 10 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2
0
1
1
Output
6
10
Input
3 4
0 0
1
2
1
2
Output
20
10
14
20
Input
10 10
0 0 0 1 1 1 0 1 0
4
1
8
4
2
9
5
6
6
8
Output
1815
3201
2710
2776
2290
1644
2668
1271
2668
2436
----------------------------------------------------------------------------------------------------
I. Demonic Invasion
time limit per test: 8 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 4 1
1 2
2 3
3 4
4 1
Output
1
Input
4 4 4
1 2
2 3
3 4
4 1
Output
2
Input
3 2 10
1 2
2 3
Output
1
Input
4 5 1
1 2
2 3
3 4
4 1
3 1
Output
0
----------------------------------------------------------------------------------------------------
J. Flower Shop
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 12
1 2 3 2 1
1 1 5
1 2 3
1 3 1
3 1 5 10
3 4 5 100
1 4 4
1 5 1
3 2 5 7
3 1 1 3
3 1 5 100
2 1 5
3 1 5 100
Output
40
0
28
3
479
79
----------------------------------------------------------------------------------------------------
