Технокубок 2022 - Финал


A. Maximum Cake Tastiness
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
6
5 2 1 4 7 3
3
32 78 78
3
69 54 91
8
999021 999021 999021 999021 999652 999021 999021 999021
2
1000000000 1000000000
Output
12
156
160
1998673
2000000000
----------------------------------------------------------------------------------------------------
B. Prefix Removals
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
abcabdc
a
bbbbbbbbbb
codeforces
cffcfccffccfcffcfccfcffccffcfccf
zyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw
Output
abdc
a
b
deforces
cf
xyzzw
----------------------------------------------------------------------------------------------------
C. Alice and the Cake
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
14
1
327
2
869 541
2
985214736 985214737
3
2 3 1
3
2 3 3
6
1 1 1 1 1 1
6
100 100 100 100 100 100
8
100 100 100 100 100 100 100 100
8
2 16 1 8 64 1 4 32
10
1 2 4 7 1 1 1 1 7 2
10
7 1 1 1 3 1 3 3 2 3
10
1 4 4 1 1 1 3 3 3 1
10
2 3 2 2 1 2 2 2 2 2
4
999999999 999999999 999999999 999999999
Output
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
NO
YES
----------------------------------------------------------------------------------------------------
D. Potion Brewing Class
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
3 2 3 4
1 2 4 3
1 4 2 4
8
5 4 2 3
6 4 5 4
1 3 5 2
6 8 2 1
3 5 3 4
3 2 2 5
6 7 4 3
17
8 7 4 16
9 17 4 5
5 14 13 12
11 1 17 14
6 13 8 9
2 11 3 11
4 17 7 2
17 16 8 6
15 5 1 14
16 7 1 10
12 17 13 10
11 16 7 2
10 11 6 4
13 17 14 6
3 11 15 8
15 6 12 8
Output
69
359
573672453
----------------------------------------------------------------------------------------------------
E. Arithmetic Operations
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
9
3 2 7 8 6 9 5 4 1
Output
6
Input
14
19 2 15 8 9 14 17 13 4 14 4 11 15 7
Output
10
Input
10
100000 1 60000 2 20000 4 8 16 32 64
Output
7
Input
4
10000 20000 10000 1
Output
2
----------------------------------------------------------------------------------------------------
F. Minimal String Xoration
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2
acba
Output
abca
Input
3
bcbaaabb
Output
aabbbcba
Input
4
bdbcbccdbdbaaccd
Output
abdbdccacbdbdccb
Input
5
ccfcffccccccffcfcfccfffffcccccff
Output
cccccffffcccccffccfcffcccccfffff
Input
1
zz
Output
zz
----------------------------------------------------------------------------------------------------
G. Snowy Mountain
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
6
1 1 0 0 0 0
1 3
2 4
3 4
4 5
5 6
Output
0 0 1 1 3 5 
Input
9
0 0 0 0 0 0 1 1 1
1 3
2 3
2 5
3 6
4 5
4 7
5 8
6 9
Output
5 3 2 1 1 1 0 0 0 
Input
14
0 0 0 0 0 0 0 0 0 1 1 1 1 1
1 2
2 5
3 4
4 5
3 6
4 8
5 9
7 8
6 11
7 12
8 13
9 14
10 11
Output
8 5 4 3 2 2 1 1 1 0 0 0 0 0 
Input
20
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 1 0 1
17 3
11 12
6 10
18 19
8 14
16 20
5 3
2 11
7 10
2 15
8 3
3 15
9 16
7 13
16 1
19 2
2 16
6 1
4 17
Output
2 2 1 5 3 4 8 1 2 6 4 6 10 0 0 0 3 0 1 0 
----------------------------------------------------------------------------------------------------
