eolymp
bolt
Try our new interface for solving problems
Problems

Discount

Discount

In the supermarket there is an action --- "Buying any two goods, the third you receive free of charge, out of three selected goods you pay the two most expensive." Mamed, going to the supermarket, knows what goods he wants to buy, and knows their value. Determine the minimum amount of money that he needs to take with him to buy these goods. \InputFile The first line contains one number $n~(1 \le n \le 1000)$. Second line contains $n$ numbers --- the prices of goods chosen by Mamed. All prices are positive integers, no more than $10000$. \OutputFile Print one number --- the minimum amount of money that Mamed should take with him to the supermarket. \Examples Mamed will first pass through the cash register with goods worth $1, 3$ and $4$ --- will pay $7$ rubles and a commodity worth $1$ will receive as a gift, and then again go into supermarket and will buy goods worth $5$ and $7$, another product of cost $5$ received as a gift.
Time limit 1 second
Memory limit 128 MiB
Input example #1
6
1 5 4 3 5 7
Output example #1
19
Source 2018 Azerbaijan School Competition, II Stage, April 8, Problem I