Problem:
Score : 300 points

Problem Statement

There are 3N participants in AtCoder Group Contest.
The strength of the i-th participant is represented by an integer a_i.
They will form N teams, each consisting of three participants.
No participant may belong to multiple teams.

The strength of a team is defined as the second largest strength among its members.
For example, a team of participants of strength 1, 5, 2 has a strength 2, and a team of three participants of strength 3, 2, 3 has a strength 3.

Find the maximum possible sum of the strengths of N teams.

Constraints

1 ≤ N ≤ 10^5

1 ≤ a_i ≤ 10^{9}

a_i are integers.

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 ... a_{3N}

Output

Print the answer.

Sample Input 1

2
5 2 8 5 1 5

Sample Output 1

10

The following is one formation of teams that maximizes the sum of the strengths of teams:

Team 1: consists of the first, fourth and fifth participants.

Team 2: consists of the second, third and sixth participants.

Sample Input 2

10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 2

10000000000

The sum of the strengths can be quite large.

Solution in C++14 (GCC 5.4.1) (judge verdict: Accepted)




#include "bits/stdc++.h"

#include <unordered_set>
#include <unordered_map>

//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
//#include <algorithm>
//#include <cstring>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define dd(n) cout<<fixed<<setprecision(n)
#define inp(x) (cin>>x,x)
#define ind(x) (cin>>x,--x)
//#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define repi(i,a,b) for(int i=(a);i<b;++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define repir(i,a,b) for(int i=(a)-1, i##_first=(b); i>=i##_first; --i)
#define repr(i,n) repir(i,n,0)
#define repir_(i,a,b) for(int i=(a), i##_first=(b); i>=i##_first; --i)
#define repr_(i,n) repir_(i,n,0)
#define prep(i,n) for(int i=0;i*i<n;++i)
#define prepi(i,a,b) for(int i=a;i*i<b;++i)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define vcsort(v,c) sort((v).begin(),(v).end(),c)
#define vrev(v) reverse((v).begin(), (v).end())
#define fnd(v,x) ((v).find(x)!=string::npos)
#define mod(a,b) (a<0?a%b+abs(b):a%b)
#define cl(a,b) (a+b-1/b)

//template<typename T> T vpop(vector<T> *v) {
//	T d = v->back();
//	v->pop_back();
//	return d;
//}
//char vpop(string *v) {
//	char d = v->back();
//	v->pop_back();
//	return d;
//}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define pi 3.14159265358979
#define co(x) cout<<x<<el
#define coc(c, a, b) co(((c)?a:b))
#define cim(x) {cin>>x;--x;}
#define cim2(a,b) {cin>>a>>b;--a;--b;}
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()
#define noway() {co(-1);gc();return 0;}

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);
const int _10j9p7 = 1000000007;

//#define lint long long
typedef long long lint;
typedef vector<int> IV; typedef vector<string> SV;
typedef vector<lint> LIV;
typedef vector<vector<int>> IVV;
typedef pair<int,int> P; typedef pair<lint,lint> LP;
typedef vector<P> PV; typedef vector<LP> LPV;

const int
dx8[8] ={ 0,1,1,1,0,-1,-1,-1 },
dy8[8] ={ 1,1,0,-1,-1,-1,0,1 },
dx9[9] ={ 0,1,1,1,0,0,-1,-1,-1 },
dy9[9] ={ 1,1,0,-1,0,-1,-1,0,1 },
dx5[5] ={ 0,1,0,0,-1 },
dy5[5] ={ 1,0,0,-1,0 },
dx4[4] ={ 0,1,0,-1 },
dy4[4] ={ 1,0,-1,0 };
//template<class... A> void cim_(A... args) {
//	for (A *i : initializer_list<A*>{ args... }) {
//		cin>>*i;--*i;
//	}
//	return;
//}

template<class T>inline bool maxi(T &a,const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T>inline bool mini(T &a,const T &b){ if(b < a){ a = b; return 1; } return 0; }

#define MAX_N 100000
const int md = 1e9+7;

int main(){
	setc;

	lint n;cin>>n;
	LIV a(3*n);rep(i,3*n)cin>>a[i];vcsort(a,greater<lint>());
	lint ans=0;
	rep(i,n)ans+=a[2*i+1];co(ans);
	gc();
}


////https://beta.atcoder.jp/contests/abc075/tasks/abc075_d
////座標圧縮
//struct C{
//	int x,y;
//};
//
//vector<C> vector_name;//this to
//bool table[50][50]={};//this
//map <lint,lint> yax,xax;//table[yax[y]][xax[x]]とすることでそこにあるかわかる
//bool cmp_C_xless(C a,C b){ return a.x<b.x; }
//bool cmp_C_yless(C a,C b){ return a.y<b.y; }
//P coordsCompress(lint n=siz(vector_name)){
//	P ret={0,0};
//	vcsort(vector_name,cmp_C_xless);
//	lint r=n, prv=-inf;
//	lint kaburi=0;
//	rep(i,r){
//		xax.insert({ vector_name[i].x,i });
//		if(prv==vector_name[i].x){
//			continue;
//		}prv=vector_name[i].x;
//		++ret.first;
//	}
//	vcsort(vector_name,cmp_C_yless);
//	r=n;prv=-inf;
//	rep(i,r){
//		yax.insert({ vector_name[i].y,i });
//		if(prv==vector_name[i].y){
//			table[i-++kaburi][xax[vector_name[i].x]]=1;
//			continue;
//		}prv=vector_name[i].y;
//		table[i-kaburi][xax[vector_name[i].x]]=1;
//		++ret.second;
//	}
//	return ret;
//}
//
//int main(){
//	setc;
//
//	lint n,k;cin>>n>>k;
//	vector_name.resize(n);
//	rep(i,n){
//		cin>>vector_name[i].x>>vector_name[i].y;//--vector_name[i].x;--vector_name[i].y;
//	}
//	P b=coordsCompress(n);
//	rep(j,b.second){
//		rep(i,b.first){
//			cout<<(table[j][i]?'#':'.');
//		}cout<<el;
//	}
//	co("x scales:");
//	for(auto i:xax){
//		cout<<i.first<<sp;
//	}cout<<el;
//	co("y scales:");
//	for(auto j:yax){
//		cout<<j.first<<sp;
//	}cout<<el;
//	lint p,q;
//	co("input coords to get if there is a point (input -1 -1 to finish)");
//	while(cin>>p>>q){
//		if(p==-1)break;
//		Yes(table[yax[q]][xax[p]]);
//		co("input coords to get if there is a point:");
//	}
//
//	gc();
//}


//https://beta.atcoder.jp/contests/abc080/tasks/abc080_d
//SSSCon #8
//lint a[100010]={};
//
//int main(){
//	setc;
//
//	lint n,C;cin>>n>>C;
//	lint s,t,c;
//
//	rep(i,n){
//		cin>>s>>t>>c;
//		++a[max(s-2,(lint)0)];--a[--t];
//	}
//	lint tmp=0,ans=0;
//	rep(i,100005){
//		tmp+=a[i];
//		maxi(ans,tmp);
//	}
//	co(min(ans,C));
//	gc();
//}


//
//LIV d;
//void divisors(lint n) {
//	for (int i = 1; i*i <= n; ++i) {
//		if (n % i != 0) continue;
//		d.push_back(i);
//		if (n/i == i) continue; // 上の行で追加済み。
//		d.push_back(n/i);
//	}
//}
//
//lint dp[100010][100];
//
//int main(){
//	setc;
//
//	lint n,m;cin>>n>>m;
//	divisors(m);vsort(d);
//	lint s=siz(d);
//
//	rep(i,n)dp[i][0]=1;rep(j,s)dp[0][j]=1;
//	lint tmp;
//	auto b=d.begin();
//	repi(i,1,n){
//		repi(j,1,s){tmp=dp[i-1][j];
//			repi(k,1,s){
//				if(d[j]<d[k])break;
//				if (d[j]%d[k])continue;
//				tmp=(tmp+dp[i-1][lower_bound(all(d), d[j]/d[k])-b])%1000000007;//lower_bound(all(d),d[j]/d[k])-b
//			}
//			dp[i][j]=tmp;
//		}
//	}
//	co(dp[n-1][s-1]);
//	gc();
//}
//
//