#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/priority_queue.hpp>
//#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define pb push_back
#define mkp make_pair
#define endl '\n'
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

//typedef gp_hash_table<int, int> hashmap;
//typedef tree<pii, null_type, std::less<pii>, splay_tree_tag, tree_order_statistics_node_update> splaytree;
//typedef tree<pii, null_type, std::less<pii>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
//typedef __gnu_pbds::priority_queue<int, std::greater<int>, __gnu_pbds::binary_heap_tag> binheap;
//typedef __gnu_pbds::priority_queue<int, std::greater<int>, __gnu_pbds::pairing_heap_tag> pairingheap;

template <typename T>
inline void read(T &x)
{
    T data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    x = f * data;
}
template <typename T, typename... Args>
inline void read(T &t, Args &...args)
{
    read(t);
    read(args...);
}

//mt19937 rnd(time(0));
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2e5 + 9;
const ll mod = 1e9 + 7;
vi a;
signed main()
{
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    //std::cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1, x; i <= n; ++i)
    {
        cin >> x;
        a.pb(x);
    }
    sort(a.begin(), a.end());
    ll ans = a[0] + 1;
    for (int i = 1; i < n; ++i)
        ans = ans * (a[i] - a[i - 1] + 1) % mod;
    cout << ans << endl;
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
    int n;
    cin>>n;
    V<ll> l(n),r(n);
    for(int i=0;i<2*n;i++){
         if(i<n)cin>>l[i];
         else cin>>r[i-n];
    }
    reverse(all(l));
    ll ans=-inf,res=0;
    priority_queue<ll,V<ll>,greater<ll>> a,b;
    a.emplace(l[0]);
    for(int i=1;i<n;i++){
        a.emplace(l[i]);
        b.emplace(r[i]);
        if(a.top()<b.top()){
              a.pop();
        }else{
             b.pop();
        }
    }
    while(a.size()){
          res+=a.top();
          a.pop();
    }
    while(b.size()){
          res+=b.top();
          b.pop();
    }
    ans=res;
    res=0;
    b.emplace(r[0]);
    for(int i=1;i<n;i++){
        a.emplace(l[i]);
        b.emplace(r[i]);
        if(a.top()<b.top()){
              a.pop();
        }else{
             b.pop();
        }
    }
    while(a.size()){
          res+=a.top();
          a.pop();
    }
    while(b.size()){
          res+=b.top();
          b.pop();
    }
    cout<<max(ans,res)<<"\n";
}