The Zerg army is working on mining more minerals. They have found a mineral patch of length .
They have a single drone who will mine the minerals.
This drone needs to divide this mineral patch into sections of length through
. The drone
can cut a mineral patch of length
into two mineral patches, one with length
and the other
with length
. It will take the drone
seconds to perform one such cut. It is guaranteed
that
. The patches are unordered.
What is the minimum amount of time it will take this single drone to divide the mineral patch into the desired sections?
Constraints
Input Specification
The first line will contain a single integer .
Each of the next lines will contain a single integer,
.
Output Specification
Output the number of seconds it will take for the drone to divide the mineral patch accordingly.
Sample Input
3
8
5
8
Sample Output
34
Comments