Kotlin Heroes: Episode 3


A. Likes Display
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
9
999
123
0
1782
31415926
1500
999999
35499710
2000000000
Output
999
123
0
2K
31M
2K
1M
35M
2000M
----------------------------------------------------------------------------------------------------
B. Cartoons
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1
1 1
3
2 1000000000
2 500000000
500000002 1000000000
3
1 2
3 4
1 4
2
4 11
4 9
3
1 5
10 10
1 5
Output
1
500000001
-1
10
10
----------------------------------------------------------------------------------------------------
C. Dream Team
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5
1 -1 1 -1 1
2
11 1
3
5 -3 4
3
5 3 -4
5
-1 0 3 -3 0
Output
2
11101
11
10
6
111
5
100
2
10100
----------------------------------------------------------------------------------------------------
D. Bonus Distribution
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
4 1
3 1 4 2
2 3
10 2
4 1000000000
987654321 1000000000 999999999 500000000
8 9
5 6 1 8 3 4 2 7
6 1
6 3 1 8 5 9
Output
0 0 1 0 
0 3 
134259259 121913582 121913582 621913577 
2 2 0 2 0 1 0 2 
1 0 0 0 0 0 
----------------------------------------------------------------------------------------------------
E. Modernization of Treeland
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
10 4
4 5
5 2
2 1
1 3
1 9
9 10
2 7
7 8
5 6
4 3
1 2
2 3
3 4
5 3
1 2
1 3
1 4
1 5
4 1
1 2
2 4
2 3
Output
Yes
9
1 2 4 5 6 7 8 9 10 
No
Yes
4
1 3 4 5 
Yes
1
4 
----------------------------------------------------------------------------------------------------
F. Movie Fan
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
7 2
1 2
1 3
2 2
2 3
1 1
2 3
1 2
5 3
1 1
1 1
1 1
1 1
1 1
6 1
13 13
31 31
25 25
12 12
14 14
10 10
Output
1
1 3 2 3 1 4 2 
1
1 1 1 2 2 
0
13 31 25 12 14 10 
----------------------------------------------------------------------------------------------------
G. M-numbers
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
24 9
Output
226
Input
24 1
Output
38
Input
5040 1000000000
Output
111121111315213227111
Input
2020 2020
Output
-1
----------------------------------------------------------------------------------------------------
H. Paint the String
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
kotlin
codeforces
abacaba
ffccgc
yz
Output
RRRRBB
RRRRRRRBBB
RRRRBBB
RBBBBR
RR
----------------------------------------------------------------------------------------------------
I. Falling Blocks
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2
2 3
1 3
Output
1
2
1
Input
8 6
1 2
3 3
2 3
1 3
2 4
3 6
1 5
1 5
Output
1
2
3
1
2
3
4
4
----------------------------------------------------------------------------------------------------
