Discounts#80

Discounts

1 second
64 megabytes
Very easy

When you visit a large shop before New Year, you select many gifts for your family and friends. To help you save money, the shop offers two types of pre-New Year discounts:

  1. If you buy three items, you pay only for the two most expensive ones.

  2. If you buy four items, you pay only for the three most expensive ones.

Thus, you can group certain items into triplets or quadruplets to pay less. Only consecutive items can be grouped together. Your task is to find the minimum total amount of money needed to buy all the gifts.

For example, suppose you have selected five gifts with prices: , , , , . You can buy the first four items together and get a discount, then buy the remaining item at its full price. The total cost will be monetary units instead of .

Write a program that, given the prices of all the gifts, determines the minimal total amount of money needed to buy all of them.

Input

The first line contains one integer (1 \leq N \leq 10000) — the number of gifts. The second line contains positive integers — the prices of the gifts. The total sum of gift prices does not exceed 10^9. Only consecutive items can be grouped together.

Output

Print a single integer — the minimum total amount of money needed to buy all gifts.

Examples

Example 1

Loading
Loading