Codeforces Round 823 (Div. 2)


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

Examples
Input
4
10 1
2 1 4 5 2 4 5 5 1 2
5 2
3 2 1 2 2
2 2
1 1
2 2
1 2
Output
4
4
2
2
Input
1
1 100
1
Output
1
----------------------------------------------------------------------------------------------------
B. Meeting on the Line
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6
Output
0
2
2.5
2
1
3
6
----------------------------------------------------------------------------------------------------
C. Minimum Notation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
04829
9
01
314752277691991
Output
02599
9
01
111334567888999
----------------------------------------------------------------------------------------------------
D. Prefixes and Suffixes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
3
cbc
aba
5
abcaa
cbabb
5
abcaa
cbabz
1
a
a
1
a
b
6
abadaa
adaaba
8
abcabdaa
adabcaba
Output
YES
YES
NO
YES
NO
NO
YES
----------------------------------------------------------------------------------------------------
E. Maximums and Minimums
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
1
1
2
2 4
2
2 3
4
2 4 7 14
7
16 5 18 7 7 12 14
6
16 14 2 6 16 2
Output
1
3
2
7
10
19
----------------------------------------------------------------------------------------------------
F. Almost Sorted
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
1
Output
0
Input
3 1
2 3 1
Output
1
Input
5 2
5 4 3 2 1
Output
6
Input
10 3
5 8 6 10 2 7 4 1 9 3
Output
18
----------------------------------------------------------------------------------------------------
