Codeforces Round 757 (Div. 2)


A. Divan and a Store
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
3 1 100 100
50 100 50
6 3 5 10
1 2 3 4 5 6
6 3 5 21
1 2 3 4 5 6
10 50 69 100
20 30 40 77 1 1 12 4 70 10000
3 50 80 30
20 60 70
10 2 7 100
2 2 2 2 2 7 7 7 7 7
4 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000
1 1 1 1
1
Output
2
2
3
0
0
10
1
1
----------------------------------------------------------------------------------------------------
B. Divan and a New Project
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
5
3 8 10 6 1
5
1 1 1 1 1
1
0
Output
14
2 4 1 3
78
1 -1 0 2 3 4
18
3 6 1 5 2 4
0
1 2
----------------------------------------------------------------------------------------------------
C. Divan and bitwise operations
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 1
1 2 2
3 2
1 3 5
2 3 5
5 4
1 2 7
3 3 7
4 4 0
4 5 2
Output
4
20
112
----------------------------------------------------------------------------------------------------
D1. Divan and Kostomuksha (easy version)
time limit per test: 4 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
6
2 3 1 2 6 2
Output
14
Input
10
5 7 10 3 1 10 100 3 42 54
Output
131
----------------------------------------------------------------------------------------------------
D2. Divan and Kostomuksha (hard version)
time limit per test: 4 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
6
2 3 1 2 6 2
Output
14
Input
10
5 7 10 3 1 10 100 3 42 54
Output
131
----------------------------------------------------------------------------------------------------
E. Divan and a Cottage
time limit per test: 2 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
3
50
3
1 2 3
50
3
4 5 6
0
3
7 8 9
Output
2
5
9
15
22
30
38
47
53
Input
4
728
3
859 1045 182
104
1
689
346
6
634 356 912 214 1 1
755
3
241 765 473
Output
858
1902
2083
2770
3401
3754
4663
4874
4872
4870
5107
5868
6337
Input
2
500000000
3
1000000000 999999999 888888888
250000000
5
777777777 666666666 555555555 444444444 333333333
Output
999999999
999999996
888888882
666666656
333333321
888888874
333333317
666666648
----------------------------------------------------------------------------------------------------
