Codeforces Round 582 (Div. 3)


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

Examples
Input
3
1 2 3
Output
1
Input
5
2 2 2 3 3
Output
2
----------------------------------------------------------------------------------------------------
B. Bad Prices
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
6
3 9 4 6 7 5
1
1000000
2
2 1
10
31 41 59 26 53 58 97 93 23 84
7
3 2 1 2 3 4 5
Output
3
0
1
8
2
----------------------------------------------------------------------------------------------------
C. Book Reading
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
1 1
10 1
100 3
1024 14
998244353 1337
123 144
1234312817382646 13
Output
1
45
153
294
3359835
0
427262129093995
----------------------------------------------------------------------------------------------------
D1. Equalizing by Division (easy version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 2 2 4 5
Output
1
Input
5 3
1 2 3 4 5
Output
2
Input
5 3
1 2 3 3 3
Output
0
----------------------------------------------------------------------------------------------------
D2. Equalizing by Division (hard version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 2 2 4 5
Output
1
Input
5 3
1 2 3 4 5
Output
2
Input
5 3
1 2 3 3 3
Output
0
----------------------------------------------------------------------------------------------------
E. Two Small Strings
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
ab
bc
Output
YES
acbbac
Input
3
aa
bc
Output
YES
cacbacbab
Input
1
cb
ac
Output
YES
abc
----------------------------------------------------------------------------------------------------
F. Unstable String Sort
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 2 3
1 3 2
Output
YES
abb
----------------------------------------------------------------------------------------------------
G. Path Queries
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7 5
1 2 1
3 2 3
2 4 1
4 5 2
5 7 4
3 6 2
5 2 3 4 1
Output
21 7 15 21 3 
Input
1 2
1 2
Output
0 0 
Input
3 3
1 2 1
2 3 2
1 3 2
Output
1 3 3 
----------------------------------------------------------------------------------------------------
