Problem:
Score : 200 points

Problem Statement

Snuke is having a barbeque party.

At the party, he will make N servings of Skewer Meal.

Example of a serving of Skewer Meal

He has a stock of 2N skewers, all of which will be used in Skewer Meal. The length of the i-th skewer is L_i.
Also, he has an infinite supply of ingredients.

To make a serving of Skewer Meal, he picks 2 skewers and threads ingredients onto those skewers.
Let the length of the shorter skewer be x, then the serving can hold the maximum of x ingredients.

What is the maximum total number of ingredients that his N servings of Skewer Meal can hold, if he uses the skewers optimally?

Constraints

1≦N≦100

1≦L_i≦100

For each i, L_i is an integer.

Input

The input is given from Standard Input in the following format:

N
L_1 L_2 ... L_{2N}

Output

Print the maximum total number of ingredients that Snuke's N servings of Skewer Meal can hold.

Sample Input 1

2
1 3 1 2

Sample Output 1

3

If he makes a serving using the first and third skewers, and another using the second and fourth skewers, each serving will hold 1 and 2 ingredients, for the total of 3.

Sample Input 2

5
100 1 2 3 14 15 58 58 58 29

Sample Output 2

135

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

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
void QuickSort(int* pnData, int nNumOf);

int main(){

    int n,ans = 0;
    int l[200];

    cin >> n;

    FOR(i,0,2*n){
        cin >> l[i];
    }

    QuickSort(l,2*n);

    for(int i = 0; i < 2*n; i+=2){
        ans += l[i];
    }

    cout << ans;

    return 0;
}



static void Sub_QuickSort(int* pnData, int nFirst, int nLast);

// クイックソート
void QuickSort(int* pnData, int nNumOf)
{
    Sub_QuickSort(pnData, 0, nNumOf - 1);
}

// 再帰関数
// nFirst : ブロックの最初のインデックス
// nLast  : ブロックの最後のインデックス
static void Sub_QuickSort(int* pnData, int nFirst, int nLast)
{
    int iLess    = nFirst;  // 前半のインデックス
    int iGreater = nLast;   // 後半のインデックス
    int x;                  // 「ある値」

    // 「ある値」は両端の要素の平均値にする
    x = (pnData[nFirst] + pnData[nLast]) / 2;

    // 交換ループ
    // 位置が逆になると終了
    while(iLess < iGreater)
    {
        // x より小さい要素は無視
        while(pnData[iLess] < x)
            iLess++;
        // x より大きい要素は無視
        while(pnData[iGreater] > x)
            iGreater--;

        // 位置がちゃんとしているときは交換し、
        // iLess と iGreater を１つずつ進める
        if(iLess < iGreater)
            swap(pnData[iLess++], pnData[iGreater--]);
    }
    // iLess == iGreater で終わった時は、
    // iGreater < iLess になるようにする
    if(iLess == iGreater)
    {
        if(pnData[iLess] < x)
            iLess++;
        else if(pnData[iLess] > x)
            iGreater--;
    }

    // 次のブロックのサイズが２以上の時は再帰
    if(iLess >= nFirst + 2)
        Sub_QuickSort(pnData, nFirst, iLess - 1);
    if(iGreater <= nLast - 2)
        Sub_QuickSort(pnData, iGreater + 1, nLast);
}