Codeforces Round 248 (Div. 2)


A. Kitahara Haruki's Gift
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
----------------------------------------------------------------------------------------------------
B. Kuriyama Mirai's Stones
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
6 4 2 7 2 7
3
2 3 6
1 3 4
1 1 6
Output
24
9
28
Input
4
5 5 2 3
10
1 2 4
2 1 4
1 1 1
2 1 4
2 1 2
1 1 1
1 3 3
1 1 3
1 4 4
1 2 2
Output
10
15
5
15
5
5
2
12
3
5
----------------------------------------------------------------------------------------------------
C. Ryouko's Memory Note
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 6
1 2 3 4 3 2
Output
3
Input
10 5
9 4 3 8 8
Output
6
----------------------------------------------------------------------------------------------------
D. Nanami's Digital Board
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4 5
0 1 1 0
1 0 0 1
0 1 1 0
2 2 2
2 1 2
1 2 2
1 2 3
2 2 2
Output
0
2
6
Input
3 3 4
1 1 1
1 1 1
1 1 1
2 2 2
1 2 2
2 1 1
2 2 1
Output
6
3
3
----------------------------------------------------------------------------------------------------
E. Tachibana Kanade's Tofu
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 10 1
1 1
3 1 0 0
1 1 1
1 0 1
Output
97
Input
2 10 12
2 5 9
6 6 3 5 4 9 7
2 0 6 1
3 6 7 2 1
Output
635439
Input
4 2 6
6 1 0 1 1 1 0
6 1 1 0 1 0 0
1 1 2
3 0 1 0 5
4 0 1 1 0 4
3 1 0 1 2
Output
2
----------------------------------------------------------------------------------------------------
