Codeforces Round 179 (Div. 1)


A. Greg and Array
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
----------------------------------------------------------------------------------------------------
B. Greg and Graph
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
0
1
Output
0 
Input
2
0 5
4 0
1 2
Output
9 0 
Input
4
0 3 1 1
6 0 400 1
2 4 0 1
1 1 1 0
4 1 2 3
Output
17 23 404 0 
----------------------------------------------------------------------------------------------------
C. Greg and Friends
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 50
50
Output
1
1
Input
3 100
50 50 100
Output
5
2
Input
2 50
50 50
Output
-1
0
----------------------------------------------------------------------------------------------------
D. Greg and Caves
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
Output
0
Input
4 4
Output
485
Input
3 5
Output
451
----------------------------------------------------------------------------------------------------
E. Yaroslav and Points
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
36 50 28 -75 40 -60 -95 -48
20
2 -61 29
1 5 -53
1 1 429
1 5 130
2 -101 -71
2 -69 53
1 1 404
1 5 518
2 -101 53
2 50 872
1 1 -207
2 -99 -40
1 7 -389
1 6 -171
1 2 464
1 7 -707
1 1 -730
1 1 560
2 635 644
1 7 -677
Output
176
20
406
1046
1638
156
0
----------------------------------------------------------------------------------------------------
