PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000128. Khuyến mãi mua ba trả hai (Akcija)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Khuyến mãi mua ba trả hai (Akcija)

Akcija

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A bookstore offers one free cheapest book in every group of three purchased books; the two more expensive ones must be paid for. Remaining books may be purchased separately. Given all nn book prices, find the minimum amount paid.

Input

The first line contains nn. Each of the next nn lines contains one price cic_i.

Output

Print the minimum total price paid.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤ci≤1000001\le c_i\le100000.
  • Subtask 2 (30 points): 1≤n≤12001\le n\le 1200; 1≤ci≤1000001\le c_i\le100000.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤ci≤1000001\le c_i\le100000.

Examples

Input

6
10
9
8
7
6
5

Output

32

Explanation

Group prices 10,9,810,9,8 and 7,6,57,6,5. Prices 88 and 55 are free; from total 4545, pay 45−13=3245-13=32.