D. Apple Orchard
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Example
Input
3 4 2 1 10 10 20 1
Output
7