An advertisement in a bookstore says, "buy ~3~, get ~1~ free, pay for ~2~." Thus, each customer who buys three books will get the cheapest one of the three for free. Customers can buy as many books as they want, depending on how they arrange the books into groups of three to get the free one.
For example, if a customer buys books priced at ~10~, ~3~, ~2~, ~4~, ~6~, ~4~, ~9~, and they arrange the books into groups as follows: ~(10, 3, 2)~, ~(4, 6, 4)~, and ~(9)~, they will get the book priced at ~2~ for free from the first group, the book priced at ~4~ for free from the second group, and no book for free from the third group because it has only one book.
The shopkeeper is kind-hearted and always wants each customer to pay the least amount of money possible.
Task: Given the prices of the books, help the shopkeeper arrange the books into groups so that the total amount the customer has to pay is minimized. Note that the shopkeeper can arrange the books into groups with at least ~1~ book or at most ~3~ books.
Input
- The first line contains an integer ~N ~ (~ N \leq 10^5 ~) – the number of books the customer buys.
- The next line contain ~N~ integer numbers ~ A_i ~ (~ A_i \leq 10^9 ~) – the price of each book. The numbers in the input file are separated by spaces.
Output
- Print a single integer, the minimum amount of money the customer has to pay.
Sample Input
6
6 4 5 5 5 5
Sample Output
21
Bình luận