Codeforces Round 852 (Div. 2)


A. Yet Another Promotion
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
5 4
3 1
5 4
3 2
3 4
3 5
20 15
10 2
1000000000 900000000
1000000000 8
Output
9
10
9
135
888888888900000000
----------------------------------------------------------------------------------------------------
B. Fedya and Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3 -2
4 -4
2 -1
5 -3
Output
10
0 1 2 1 0 -1 0 -1 0 1
16
-2 -1 -2 -1 0 1 2 3 4 5 4 3 2 1 0 -1 
6
1 0 -1 0 1 0
16
2 3 2 1 0 -1 0 -1 0 -1 0 1 2 1 0 1
----------------------------------------------------------------------------------------------------
C. Dora and Search
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
1 2 3
4
2 1 4 3
7
1 3 2 4 6 5 7
6
2 3 6 5 4 1
Output
-1
1 4
2 6
-1
----------------------------------------------------------------------------------------------------
D. Moscow Gorillas
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 3 2
2 1 3
Output
2
Input
7
7 3 6 2 1 5 4
6 7 2 5 3 1 4
Output
16
Input
6
1 2 3 4 5 6
6 5 4 3 2 1
Output
11
----------------------------------------------------------------------------------------------------
E. Velepin and Marketing
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 2 2 2
3
2
3
4
Output
5
5
3
Input
6
1 2 3 4 5 6
2
2
3
Output
5
4
Input
6
4 4 1 4 4 4
3
2
3
4
Output
6
5
1
----------------------------------------------------------------------------------------------------
F. Rebrending
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 3 2
1 2
2 3
1 3
Output
2
1
1
Input
5 3
4 1 5 3 2
1 2
3 4
2 4
Output
3
2
2
Input
7 4
2 6 1 7 3 5 4
4 6
1 2
3 6
1 3
Output
2
4
2
1
----------------------------------------------------------------------------------------------------
