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

#GD0000053. Tuyển đội thi ICPC (ICPC Team Selection)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tuyển đội thi ICPC (ICPC Team Selection)

ICPC Team Selection

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

There are 3n3n students of skills sis_i, to be split into nn teams of exactly three. Each team score is the median skill of its three members. Maximize the total team score.

Input

Line 1: nn, the number of teams. Line 2: 3n3n skills sis_i.

Output

Print the maximum sum of team scores.

Subtasks

  • Subtask 1 (20 points): 1≤n≤31\le n\le 3; 1≤si≤1091\le s_i\le 10^9 for every ii.
  • Subtask 2 (30 points): 1≤n≤5001\le n\le 500; 1≤si≤1091\le s_i\le 10^9 for every ii.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; 1≤si≤1091\le s_i\le 10^9 for every ii.

Examples

Input

3
4 4 4 10 10 10 99 99 99

Output

119

Explanation

Form teams (99,99,4)(99,99,4), (99,10,4)(99,10,4) and (10,10,4)(10,10,4). Their medians are 99, 10, 10; total 119, compared with 113 for three consecutive blocks.