Kotlin Heroes: Episode 9 (Unrated, T-Shirts + Prizes!)


A. Username
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
user0125
a1
kotlin990000
1code0forces101
Output
user0
a
kotlin9
1code0forces
----------------------------------------------------------------------------------------------------
B. Security Guard
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
-+
+-
+++-
---++
+
-
Output
1 2
1 1
1 1
-1
1 1
-1
----------------------------------------------------------------------------------------------------
C. Poisonous Swamp
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
5
*..**
.**..
1
*
.
3
...
***
Output
2
0
2
----------------------------------------------------------------------------------------------------
D. Remove and Add
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
4
4 4 1 5
5
4 4 1 5 5
2
10 5
3
1 2 3
3
2 1 1
4
1 1 1 1
4
1 3 1 2
5
1 1 3 3 1
Output
YES
NO
YES
YES
YES
NO
YES
YES
----------------------------------------------------------------------------------------------------
E. Maximum Sum Subarrays
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
3
5 2
1 2
2 3
3 4
4 5
4 4
1 2
1 3
1 4
5 3
1 2
1 3
2 4
2 5
Output
34
9
26
----------------------------------------------------------------------------------------------------
G. Pool Records
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1
42
4
3 4 6 8
5
1 2 3 4 5
3
999999998 999999999 1000000000
5
4 6 8 12 16
4
6 11 12 14
2
10 30
Output
VALID
VALID
VALID
INVALID
VALID
INVALID
INVALID
----------------------------------------------------------------------------------------------------
H. Sum of Digits of Sums
time limit per test: 6 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
1 3 3 7
Output
18 17 17 15 
Input
3
42 1337 999
Output
38 53 47 
----------------------------------------------------------------------------------------------------
I. Inverse Problem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2 2
a
Output
6
Input
5 3 3
bc
Output
15
Input
34 12 26
codeforces
Output
988024123
Input
5 3 1
aa
Output
1
----------------------------------------------------------------------------------------------------
J. Two Colors
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1 0 0
3 4 50
3 2 100
2 1 100
Output
350
Input
6
0 1 0 1 0 1
1 2 1
1 4 1
1 6 1
6 5 100
6 3 100
Output
203
Input
3
1 1 1
1 2 100
2 3 100
Output
Infinity
----------------------------------------------------------------------------------------------------
