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

int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int> a(2*n);
    for(int i=0;i<2*n;++i) cin>>a[i];
    ll ans=0;
    priority_queue<int,vector<int>,greater<int>> q;
    for(int i=n-1;i>=0;--i) {
        int l=a[i],r=a[2*n-1-i];
        if(l>r) swap(l,r);
        if(!q.empty() && q.top()<l) {
            ans-=q.top(),q.pop();
            q.push(l);ans+=l;
        }
        q.push(r);ans+=r;
    }
    cout<<ans<<endl;
}
#include<bits/stdc++.h>
#define FORz(i,t,n) for(int i=t;i<=n;i++)
#define FORf(i,n,t) for(int i=n;i>=t;i--)
#define SCC(x) scanf("%d",&x)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
using namespace std;
const int N=1e5+5;
const ll MOD=1e9+7;
// inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;}
//ll pow1(ll a,ll b){ll r=1;while(b){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
//ll pow2(ll a,ll b,ll mod){ll r=1;while(b){if(b&1)r=r*a%mod;a=a*a%mod;b>>=1;}return r%mod;}
//ll gcd(ll a,ll b){ll m=a%b;while(m){a=b;b=m;m=a%b;}return b;}
//void exgcd(ll a, ll b, ll &d, ll &x, ll &y){if(!b) { d = a; x = 1; y = 0;}else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }}
//ll inv(ll a){ll d, x, y;exgcd(a, MOD, d, x, y);return d == 1 ? (x + MOD) % MOD : -1;}struct node{ll mat[105][105];};node mul(node x,node y,int n,ll mod){node tmp;for(int i=0;i<n;i++)for(int j=0;j<n;j++){tmp.mat[i][j]=0;for(int k=0;k<n;k++)tmp.mat[i][j]+=(x.mat[i][k]*y.mat[k][j])%mod;tmp.mat[i][j]%=mod;}return tmp;}
// node matpow(node x,node y,ll num,int n,ll mod){while(num){if(num&1){y=mul(x,y,n,mod);}x=mul(x,x,n,mod);num=num>>1;}return y;}
//for(ll i=2;i<N-1;i++){if(!a[i]) b[++cnt]=i;for(ll j=1;j<=cnt&&i*b[j]<N;j++){a[i*b[j]]=1;if(i%b[j]==0) break;}}
//int find(int x){return a[x]==x?x:a[x]=find(a[x]);}
//void merge(int x,int y){a[find(y)]=a[find(x)];}
ll n;
ll a[N];
int main()
{
    cin>>n;
    FORz(i,1,n) cin>>a[i];
    sort(a+1,a+n+1);
    ll sum=1;
    FORz(i,1,n) sum=sum*(a[i]-a[i-1]+1)%MOD;
    cout<<sum;
}
