Kotlin Heroes: Episode 4


A. Color Revolution
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
40 3
1200 7
320802005 400
4 1
Output
1 3 9 27
3 21 147 1029
5 2000 800000 320000000
1 1 1 1
----------------------------------------------------------------------------------------------------
B. Boot Camp
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 5 7
1011
4 4 10
0101
5 3 4
11011
6 4 6
011101
Output
12
8
8
14
----------------------------------------------------------------------------------------------------
C. Spring Cleaning
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
5 4 3 5
1 2 2 3 5
5 3 4 5
1 5 1 5 5
5 4 5 6
1 2 5 3 5
4 3 2 10
4 4 1 1
4 3 10 2
4 4 1 1
4 1 5 4
1 2 1 3
Output
3
9
6
4
2
9
----------------------------------------------------------------------------------------------------
D. Constructing the Dungeon
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 2
1 2 1
2 3 1
5 7
3 2 7
3 4 9
1 5 5
1 2 5
4 1 5
4 2 7
3 1 5
4 4
1 2 5
3 2 2
4 1 3
3 4 4
Output
YES
1 1 1
YES
5 7 9 9 5
NO
----------------------------------------------------------------------------------------------------
E. Magic Tricks
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 5 1
3 4
2 1
4 1
3 1
3 1
Output
2 0 3 1 
Input
5 7 4
3 2
3 2
4 2
3 4
4 1
3 2
5 2
Output
2 2 0 3 1 
Input
7 15 5
5 3
4 2
6 1
2 4
1 6
3 7
5 6
4 2
6 4
2 6
6 3
6 3
7 6
2 6
7 2
Output
-1 1 1 1 2 1 0 
----------------------------------------------------------------------------------------------------
F. Dune II: Battle For Arrakis
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 1
1 2 3
2 1 2
1 1 2
2 3 100
Output
21 22 
Input
4 4 3
2 5 6 3
4 8 10 5
2 6 7 1
8 4 2 1
1 1 8
2 3 4
4 4 5
Output
123 135 129 145 
----------------------------------------------------------------------------------------------------
G. Two IP Cameras
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 5
3 5 7
1 4 5 7 12
Output
YES
1 3
5 7
Input
3 2
1 2 3
1 10
Output
YES
1 1
10 1
Input
3 4
1 2 3
5 7 9 11
Output
YES
5 1
5 1
Input
3 4
10 20 100
2 3 4 7
Output
NO
----------------------------------------------------------------------------------------------------
H. Game with Segments
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
1 1
4 7
4 7
Output
0
Input
1 2
2 5
2 4
3 5
Output
-1
Input
2 1
1 5
1 4
2 3
Output
-1 1
----------------------------------------------------------------------------------------------------
I. Pac-Man 2.0
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4 2 1
3 1 2
1 2
2 1
1 3
3 1
5 8
Output
1
3
Input
5 7 4 2
1 3 2 2 1
2 3
4 2
3 4
3 1
1 4
5 4
4 5
7 14 23 27
Output
2
6
10
13
Input
4 4 3 3
2 3 1 4
3 4
4 1
1 2
2 3
13 42 1337
Output
3
13
401
----------------------------------------------------------------------------------------------------
