Educational Codeforces Round 59 (Rated for Div. 2)


A. Digits Sequence Dividing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
6
654321
4
1337
2
33
4
2122
Output
YES
3
6 54 321
YES
3
1 3 37
NO
YES
2
21 22
----------------------------------------------------------------------------------------------------
B. Digital root
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 5
5 2
3 1
Output
5
38
19
----------------------------------------------------------------------------------------------------
C. Brutality
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 3
1 5 16 18 7 2 10
baaaaca
Output
54
Input
5 5
2 4 1 3 1000
aaaaa
Output
1010
Input
5 4
2 4 1 3 1000
aaaaa
Output
1009
Input
8 1
10 15 2 1 4 8 15 16
qqwweerr
Output
41
Input
6 3
14 18 9 19 2 15
cccccc
Output
52
Input
2 1
10 10
qq
Output
10
----------------------------------------------------------------------------------------------------
D. Compression
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
E7
E7
E7
00
00
E7
E7
E7
Output
1
Input
4
7
F
F
F
Output
1
----------------------------------------------------------------------------------------------------
E. Vasya and Binary String
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1101001
3 4 9 100 1 2 3
Output
109
Input
5
10101
3 10 15 15 15
Output
23
----------------------------------------------------------------------------------------------------
F. Vasya and Endless Credits
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
10 9 2
20 33 1
30 115 1
5 3 2
Output
32
Input
3
40 1 2
1000 1100 5
300 2 1
Output
1337
----------------------------------------------------------------------------------------------------
G. Vasya and Maximum Profit
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 10
1 15
5 3
6 11
7 2
11 22
Output
13
Input
3 5
1 8
2 19
3 11
Output
0
----------------------------------------------------------------------------------------------------
