You have gone to a large store before the New Year, selecting many gifts for friends and family. To save a certain amount of money, you can take advantage of two types of discounts offered at the store before the New Year:
When you buy three products, you pay for the two most expensive ones.
When you buy four products, you pay for the three most expensive.
Therefore, certain products can be combined in threes or fours to pay less. Your task is to determine the minimum total amount possible to acquire all gifts.
For example, if the prices of the five selected gifts are 50,80,50,100,20, you can buy the first four products separately to obtain a discount and pay for the remaining one at its full price. The total purchase cost will be 250 instead of 300.
Determine the minimum amount sufficient to purchase all gifts based on their prices.
The first line of the input file contains a number (1 \le N \le 10000). The next line contains natural numbers representing the prices of the gifts. The total of all gift prices does not exceed 10^9. The products can be selected and grouped in any order.
Output the minimum amount needed to purchase all the gifts.
Example 1