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?
The first line will contain a single integer .
Each of the next lines will contain a single integer, .
Output the number of seconds it will take for the drone to divide the mineral patch accordingly.
3 8 5 8