Kotlin Heroes: Episode 8


A. Sequence of Comparisons
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
>>>
<><=<
=
<<==
Output
>
?
=
<
----------------------------------------------------------------------------------------------------
B. Epic Novel
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
1 1
100 1
99
4
10 1
20 4
16
100
1 1
100 100
42
100
1 1
100 2
99
Output
1
2
42
1
----------------------------------------------------------------------------------------------------
C. Rhyme
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1
kotlin heroes 1
2
join kotlin 1
episode eight 0
4
abc abcdef 0
xyz zzz 1
aaa bba 0
c d 0
Output
1
0
2
1 2
0
----------------------------------------------------------------------------------------------------
D. Sweepstake
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 2
2 1
2 1
Output
3
Input
3 6
3 1
3 2
2 1
3 2
3 2
3 1
Output
4
----------------------------------------------------------------------------------------------------
E. Fix the String
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
4
))((
1
4
))((
0
4
()()
0
6
))(()(
101
6
))(()(
001
5
(((((
11
Output
2
0
0
4
1
-1
----------------------------------------------------------------------------------------------------
F. Kotlinforces
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 7
3 2
2 2
2 2
Output
2 5 1
Input
1 7
4 2
Output
1
Input
1 7
5 2
Output
-1
Input
2 4
2 1
2 2
Output
-1
Input
2 5
2 1
2 2
Output
4 1
----------------------------------------------------------------------------------------------------
G. A Battle Against a Dragon
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 4
1
2
4
2
10 5
3 4
Output
10
Input
3 3
1
1
0
1
20
2
1
100
3
Output
100
Input
2 1
2
10 10
0 1
2
30 20
0 1
Output
30
----------------------------------------------------------------------------------------------------
H. Laser Beams
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
1 2 2
1 1 500000
Output
6
Input
2 3 2
1 1 500000
2 1 500000
Output
499122187
----------------------------------------------------------------------------------------------------
I. Physical Examination
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3
2 3 1
3 3 2
8
6 6 5 4 9 4 3 6
7 6 10 6 9 6 6 8
2
4 2
4 2
3
2 2 2
3 3 3
1
5
10
Output
1
3 1 2 
3
7 4 6 2 1 8 5 3 
-1
-1
7
1 
----------------------------------------------------------------------------------------------------
J. Two Railroads
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
5
3 4 7 4
8 5 3 5
10 5 3 4 10
4
1 4
1 2
3 4
2 4
Output
9 8 10 9 
----------------------------------------------------------------------------------------------------
