
#include <bits/stdc++.h>

using ll =long long;
using namespace std;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main(){
    
    int N;
    cin>>N;
    
    set<ll> st;
    
    ll a;
    
    for(int i=0;i<N;i++){
        cin>>a;
        st.insert(a);
        
    }
    
    mint pre(0);
    mint ans(1);
    for(auto s:st){
        ans=ans*(mint(s)-pre+1);
        pre=s;
        
    }
    
    cout<<ans<<endl;
}

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

int main(){
  ll N;
  cin >> N;
  
  vector<ll> A(N);
  for (ll i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  
  ll ans = 0, prevsum = 0;
  for (ll i = N - 2; i >= 0; i--){
    prevsum += A[N - 1] - A[i];
  }
  ans = prevsum;
  
  for (ll i = N - 2; i >= 0; i--){
    prevsum = prevsum - (i + 1) * (A[i + 1] - A[i]);
    ans += prevsum;
  }
  
  cout << ans << endl;
}