Codeforces Round 841 (Div. 2) and Divide by Zero 2022


A. Joey Takes Money
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
2 3 2
2
1 3
3
1000000 1000000 1
Output
28308
8088
2022000000004044
----------------------------------------------------------------------------------------------------
B. Kill Demodogs
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2
3
50
1000000000
Output
14154
44484
171010650
999589541
----------------------------------------------------------------------------------------------------
C. Even Subarrays
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
3 1 2
5
4 2 1 5 3
4
4 4 4 4
7
5 7 3 7 1 7 3
Output
4
11
0
20
----------------------------------------------------------------------------------------------------
D. Valiant's New Map
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
2 2
2 3
4 5
1 3
1 2 3
2 3
4 4 3
2 1 4
5 6
1 9 4 6 5 8
10 9 5 8 11 6
24 42 32 8 11 1
23 1 9 69 13 3
13 22 60 12 14 17
Output
2
1
1
3
----------------------------------------------------------------------------------------------------
E. Graph Cost
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 1
6 10
9 4
10 11
Output
2
-1
7
21
----------------------------------------------------------------------------------------------------
F. Function Sum
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
Output
28
Input
5 6
Output
34475
Input
12 30
Output
920711694
----------------------------------------------------------------------------------------------------
