Codeforces Round 318 [RussianCodeCup Thanks-Round] (Div. 1)


A. Bear and Poker
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
75 150 75 50
Output
Yes
Input
3
100 150 250
Output
No
----------------------------------------------------------------------------------------------------
B. Bear and Blocks
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2 1 4 6 2 2
Output
3
Input
7
3 3 3 1 3 3 3
Output
2
----------------------------------------------------------------------------------------------------
C. Bear and Drawing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
1 2
1 3
1 6
6 4
6 7
6 5
7 8
Output
Yes
Input
13
1 2
1 3
1 4
2 5
2 6
2 7
3 8
3 9
3 10
4 11
4 12
4 13
Output
No
----------------------------------------------------------------------------------------------------
D. Bear and Cavalry
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 10 100 1000
3 7 2 5
2 4
2 4
Output
5732
7532
Input
3 3
7 11 5
3 2 1
1 2
1 3
2 3
Output
44
48
52
Input
7 4
1 2 4 8 16 32 64
87 40 77 29 50 11 18
1 5
2 7
6 2
5 6
Output
9315
9308
9315
9315
----------------------------------------------------------------------------------------------------
E. Bear and Bowling
time limit per test: 6 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
-2 -8 0 5 -3
Output
13
Input
6
-10 20 -30 40 -50 60
Output
400
----------------------------------------------------------------------------------------------------
