Codeforces Round 863 (Div. 3)


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

Examples
Input
11
5 4
76543
1 0
1
2 5
44
3 6
666
5 6
13579
5 8
97531
19 4
9876543210123456789
5 7
73737
8 1
20000000
7 0
7058959
12 1
828127127732
Output
765443
10
544
6666
613579
987531
98765443210123456789
773737
210000000
70589590
8281271277321
----------------------------------------------------------------------------------------------------
B. Conveyor Belts
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 1 1 2 2
4 1 4 3 3
8 1 3 4 6
100 10 20 50 100
1000000000 123456789 987654321 998244353 500000004
Output
0
1
2
9
10590032
----------------------------------------------------------------------------------------------------
C. Restore the Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
11
5
3 4 4 5
4
2 2 1
5
0 0 0 0
6
0 3 4 4 3
2
10
4
3 3 3
5
4 2 5 5
4
3 3 3
4
2 1 0
3
4 4
6
8 1 3 5 10
Output
3 0 4 0 5
2 2 1 1
0 0 0 0 0
0 0 3 4 3 3
10 10
3 3 3 1
4 2 2 5 5
3 3 3 3
2 1 0 0
2 4 4
8 1 1 3 5 10
----------------------------------------------------------------------------------------------------
D. Umka and a Long Flight
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
12
1 1 1
2 1 2
3 1 4
3 3 2
4 4 6
4 3 3
5 6 5
5 4 12
5 2 12
4 2 1
1 1 2
44 758465880 1277583853
Output
YES
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
NO
----------------------------------------------------------------------------------------------------
E. Living Sequence
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
3
5
22
10
100
12345
827264634912
Output
3
6
25
11
121
18937
2932285320890
----------------------------------------------------------------------------------------------------
F. Is It Flower?
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
9 12
1 2
3 1
2 3
1 6
4 1
6 4
3 8
3 5
5 8
9 7
2 9
7 2
8 12
1 2
3 1
2 3
1 6
4 1
6 4
3 8
3 5
5 8
8 7
2 8
7 2
4 3
1 2
4 2
3 1
6 8
6 3
6 4
5 3
5 2
3 2
3 1
2 1
2 4
5 7
2 4
2 5
3 4
3 5
4 1
4 5
1 5
Output
YES
NO
NO
NO
NO
Input
4
2 1
1 2
8 9
1 2
8 4
8 2
6 4
6 5
4 7
3 2
3 7
2 5
9 12
2 9
2 8
6 9
6 8
6 5
6 1
9 8
9 3
9 1
8 3
8 7
5 7
3 3
1 2
1 3
2 3
Output
NO
NO
NO
NO
----------------------------------------------------------------------------------------------------
G1. Vlad and the Nice Paths (easy version)
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5 2
1 2 3 4 5
7 2
1 3 1 3 3 1 3
11 4
1 1 1 1 1 1 1 1 1 1 1
5 2
1 1 2 2 2
5 1
1 2 3 4 5
Output
1
4
165
3
1
----------------------------------------------------------------------------------------------------
G2. Vlad and the Nice Paths (hard version)
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
5 2
1 2 3 4 5
7 2
1 3 1 3 3 1 3
11 4
1 1 1 1 1 1 1 1 1 1 1
5 2
1 1 2 2 2
5 1
1 2 3 4 5
Output
1
4
165
3
1
----------------------------------------------------------------------------------------------------
