Codeforces Round 728 (Div. 1)


A. Great Graphs
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
0 2 3
2
0 1000000000
1
0
Output
-3
0
0
----------------------------------------------------------------------------------------------------
B. Tree Array
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2
1 3
Output
166666669
Input
6
2 1
2 3
6 1
1 4
2 5
Output
500000009
Input
5
1 2
1 3
1 4
2 5
Output
500000007
----------------------------------------------------------------------------------------------------
C1. Converging Array (Easy Version)
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3 4
2 1
1
-1
Output
56
----------------------------------------------------------------------------------------------------
C2. Converging Array (Hard Version)
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3 4
2 1
5
-1 0 1 -100000 100000
Output
56
28
4
60
0
----------------------------------------------------------------------------------------------------
D. Inverse Inversions
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
0 0 0
7
2 1
2 2
2 3
1 2 1
2 1
2 2
2 3
Output
1
2
3
2
1
3
Input
5
0 1 2 3 4
15
2 1
2 2
1 2 1
2 2
2 3
2 5
1 3 0
1 4 0
2 3
2 4
2 5
1 4 1
2 3
2 4
2 5
Output
5
4
4
3
1
4
5
1
5
4
1
----------------------------------------------------------------------------------------------------
E. Tasty Dishes
time limit per test: 10 seconds
memory limit per test: 64 megabytes
input: standard input
output: standard output

Examples
Input
5
1 0 -2 -2 4
4 2 3 4 5
1 3
1 4
1 5
0
7
1 1 1 5
2 4 3
1 1 1 5
2 3 2
1 2 2 4
2 5 1
1 981 4 5
Output
57
71
316
278497818
----------------------------------------------------------------------------------------------------
