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: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;

using LL=long long;
using Point=pair<int,int>;
const int MX=4005,mod=1000000007;
#define st first
#define nd second

int N,ans,fac[MX],inv[MX];
int Pool[MX][MX],*f[MX],**dp;
Point P[MX];

inline int read()
{
    int x=0,c=getchar();
    while(!isdigit(c))c=getchar();
    while(isdigit(c))x=x*10+c-'0',c=getchar();
    return x;
}
inline void update(int& a,int b){((a+=b)>=mod)&&(a-=mod);}
int Inv(int u){return u==1?1:LL(mod-mod/u)*Inv(mod%u)%mod;}
inline int C(int n,int m){return (LL)fac[n]*inv[m]%mod*inv[n-m]%mod;}

int main()
{
    N=read();
    for(int i=0;i<=4000;i++)f[i]=Pool[i]+2000;
    dp=f+2000;
    fac[0]=1;
    for(int i=1;i<=4000;i++)fac[i]=(LL)fac[i-1]*i%mod;
    inv[4000]=Inv(fac[4000]);
    for(int i=4000;i;i--)inv[i-1]=(LL)inv[i]*i%mod;
    for(int i=1,x,y;i<=N;i++)
        x=read(),y=read(),update(dp[-x][-y],1),P[i]=make_pair(x,y);
    for(int i=-1999;i<=2000;i++)update(dp[-2000][i],dp[-2000][i-1]);
    for(int i=-1999;i<=2000;i++)update(dp[i][-2000],dp[i-1][-2000]);
    for(int i=-1999;i<=2000;i++)for(int j=-1999;j<=2000;j++)
        update(dp[i][j],dp[i-1][j]),update(dp[i][j],dp[i][j-1]);
    for(int i=1;i<=N;i++)update(ans,dp[P[i].st][P[i].nd]);
    for(int i=1;i<=N;i++)update(ans,mod-C((P[i].st+P[i].nd)*2,P[i].st*2));
    printf("%lld\n",(LL)ans*Inv(2)%mod);
    return 0;
}