Codeforces Round 642 (Div. 3)


A. Most Unstable Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 100
2 2
5 5
2 1000000000
1000000000 1000000000
Output
0
2
10
1000000000
2000000000
----------------------------------------------------------------------------------------------------
B. Two Arrays And Swaps
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 1
1 2
3 4
5 5
5 5 6 6 5
1 2 5 4 3
5 3
1 2 3 4 5
10 9 10 10 9
4 0
2 2 4 3
2 4 2 3
4 4
1 2 2 1
4 4 5 4
Output
6
27
39
11
17
----------------------------------------------------------------------------------------------------
C. Board Moves
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1
5
499993
Output
0
40
41664916690999888
----------------------------------------------------------------------------------------------------
D. Constructing the Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1
2
3
4
5
6
Output
1 
1 2 
2 1 3 
3 1 2 4 
2 4 1 3 5 
3 4 1 5 2 6 
----------------------------------------------------------------------------------------------------
E. K-periodic Garland
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
9 2
010001010
9 3
111100000
7 4
1111111
10 3
1001110101
1 1
1
1 1
0
Output
1
2
5
4
0
0
----------------------------------------------------------------------------------------------------
F. Decreasing Heights
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
3 4
1 2 3 4
5 6 7 8
9 10 11 12
5 5
2 5 4 8 3
9 10 11 5 1
12 8 4 2 5
2 2 5 4 1
6 8 2 4 2
2 2
100 10
10 1
1 2
123456789876543 987654321234567
1 1
42
Output
9
49
111
864197531358023
0
----------------------------------------------------------------------------------------------------
