Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!
ALGOR Contest: Round #2
Problem C · 150 points · ICPC rules

~/algor $ cat contests/round-2/C

C. Third one free

1000 ms 128 MB

A shop runs a promotion: at the checkout items can be paid for in groups of three, and in every full group of three the cheapest item is free. You choose the groups yourself; items left outside full groups of three are paid at full price. The prices of n items are given. What is the smallest amount you have to pay to buy all of them?

Third one free: paying 30 + 20 + 0 = 50

Input

The first line contains n — the number of items. The second line contains n integers — the prices.

Output

One integer — the smallest amount to pay.

Note

1 ≤ n ≤ 200 000; 1 ≤ price ≤ 10⁹. The answer may not fit into a 32-bit integer.

Examples

Input #1
6
5 1 3 4 2 6
Output #1
16
Input #2
3
10 10 10
Output #2
20

Sign in to submit a solution

Signing up is free and takes a minute.