M!das goes Shopping

0

0 votes
Easy
Problem

It is winter dhamaka super sale extraordinaire and all the shops have various offers. Midas selected N items to buy and he is standing in the billing queue. He then noticed the offer "Buy two, get two". That means for every two items you buy, you get two items for free. However, items can be of different prices, you are always charged for 2 most costly items and get the other 2 for free. For example, if the items cost 1, 1, 2, 2, then you have to pay 4 and take all 4 items.

Midas is busy reordering his items to reduce the total price he has to pay. He can separate the items and get them on different bills if needed. What is the least price Midas has to pay to buy all the N items?

Input:

First line has an integer N. Second line has N space separated integers, which are the costs of items Midas wants to buy.

Output:

Print a single integer containing the required answer(i.e, least price possible)

Constraints

1 = N = 1000 1 = Cost of items = 1000

Examples

Input: 1. 4 1 1 2 2 2. 2 10 200 3. 7 1 1 10 2 2 2 1

Output: 1. 4 2. 210 3. 14

Explanation:

Example case 1

Midas pays for 2 costly items and gets other 2 for free.

Example case 2

Midas has to pay for both the items, he wont get anything for free.

Example case 3

Midas separates the items into 2 bills. In one bill he pays 12. And in another bill he pays 2.

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?