#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
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> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
// Modint
// modint<MOD> で宣言
template<long long MOD>
struct modint{
  long long x;
  long long mod = MOD;
  modint(long long x=0):x(x%MOD){}
  modint& operator+=(const modint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  modint& operator-=(const modint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  modint& operator*=(const modint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  modint operator+(const modint a) const{
    modint res(*this);
    return res+=a;
  }
  modint operator-(const modint a) const{
    modint res(*this);
    return res-=a;
  }
  modint operator*(const modint a) const{
    modint res(*this);
    return res*=a;
  }
  modint pow(long long t) const{
    if(!t) return 1;
    modint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  modint inv() const{
    return pow(MOD-2);
  }
  modint& operator/=(const modint a){
    return (*this) *= a.inv();
  }
  modint operator/(const modint a) const{
    modint res(*this);
    return res/=a;
  }
};
using mint = modint<1000000007>;

const int NMAX=1000010; // we can calculate nCk until n is equal to NMAX
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;	
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}



int main()
{
  int n; cin >> n;
  vi a(n);
  rep(i,n) {
    cin >> a[i];
  }

  vector<mint> dpp(n+1),cntp(n+1);
  vector<mint> dpm(n+1),cntm(n+1);
  dpp[0].x = a[0];
  cntp[0].x = 1;
  rep(i,n-1) {
    cntp[i+1] = cntp[i] + cntm[i];
    cntm[i+1] = cntp[i];
    dpp[i+1] = dpp[i] + dpm[i] + cntp[i+1] * (mint)a[i+1];
    dpm[i+1] = dpp[i] - cntm[i+1] * mint(a[i+1]);
    //cout << dpp[i].x << ":" << dpm[i].x << "\n";
  }
  cout << (dpp[n-1] + dpm[n-1]).x << "\n";
  return 0;
}

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int prime=1000000007;
	int N;
	cin>>N;
	vector <int> arr(N,0);
	for(int i=0;i<N;i++){
		int k;
		cin>>k;
		arr[i]=k;
	}
	sort(arr.begin(),arr.end());
	int dif[N];
	dif[0]=arr[0];
	for(int i=0;i<N-1;i++){
		dif[i+1]=arr[i+1]-arr[i];
	}
	long long int out=1;
	for(int i=0;i<N;i++){
		out*=(dif[i]+1);
		out%=prime;
	}
	cout<<out<<endl;
}