Codeforces Round 250 (Div. 1)


A. The Child and Toy
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
10 20 30 40
1 4
1 2
2 3
Output
40
Input
4 4
100 100 100 100
1 2
2 3
2 4
3 4
Output
400
Input
7 10
40 10 20 10 20 80 40
1 5
4 7
4 5
5 2
5 7
6 4
1 6
1 3
4 3
1 4
Output
160
----------------------------------------------------------------------------------------------------
B. The Child and Zoo
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 3
10 20 30 40
1 3
2 3
4 3
Output
16.666667
Input
3 3
10 20 30
1 2
2 3
3 1
Output
13.333333
Input
7 8
40 20 10 30 20 50 40
1 2
2 3
3 4
4 5
5 6
6 7
1 4
5 7
Output
18.571429
----------------------------------------------------------------------------------------------------
C. The Child and Polygon
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
0 0
0 1
1 1
1 0
Output
2
Input
4
0 0
1 0
0 1
-1 0
Output
1
Input
5
0 0
1 0
1 1
0 1
-2 -1
Output
3
----------------------------------------------------------------------------------------------------
D. The Child and Sequence
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 2 3 4 5
2 3 5 4
3 3 5
1 2 5
2 1 3 3
1 1 3
Output
8
5
Input
10 10
6 9 6 7 6 1 10 10 9 5
1 3 9
2 7 10 9
2 5 10 8
1 4 7
3 3 7
2 7 9 9
1 2 4
1 6 6
1 5 9
3 1 10
Output
49
15
23
1
9
----------------------------------------------------------------------------------------------------
E. The Child and Binary Tree
time limit per test: 7 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 2
Output
1
3
9
Input
3 10
9 4 3
Output
0
0
1
1
0
2
4
2
6
15
Input
5 10
13 10 6 4 15
Output
0
0
0
1
0
1
0
2
0
5
----------------------------------------------------------------------------------------------------
