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

#GD0000129. Người mê mua sắm (Shopaholic)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Người mê mua sắm (Shopaholic)

Shopaholic

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

In a buy-three-pay-two promotion the cheapest item of each group of three is free. You must buy all nn items and may choose their grouping. Find the maximum total discount, not the amount paid.

Input

The first line contains nn. The next line contains nn prices pip_i.

Output

Print the maximum total discount.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤pi≤200001\le p_i\le20000.
  • Subtask 2 (30 points): 1≤n≤7001\le n\le 700; 1≤pi≤200001\le p_i\le20000.
  • Subtask 3 (50 points): 1≤n≤200001\le n\le 20000; 1≤pi≤200001\le p_i\le20000.

Examples

Input

7
400 350 300 250 200 150 100

Output

450

Explanation

Sorted descending, groups [400,350,300][400,350,300] and [250,200,150][250,200,150] give free items 300300 and 150150, for a saving of 450450.