#include<bits/stdc++.h>
using namespace std;
#define mod  1000000007
#define int long long

int dp[100001][2], dp1[100001][2], n, arr[100001];

int fun1(int ind, int sign) {
    if ( ind == n ) return 1;
    if ( dp1[ind][sign] != - 1 ) return dp1[ind][sign];
    int res = 0;

    if ( sign ) {
        res = (fun1(ind + 1, sign)%mod)%mod;
        res = (res%mod + fun1(ind + 1, 0)%mod )%mod;
    } else {
        res = ( fun1(ind + 1, 1)%mod)%mod;
    }
    return dp1[ind][sign] = res;
}

int fun(int ind, int sign) {
    if ( ind == n ) return 0;
    if ( dp[ind][sign] != - 1 ) return dp[ind][sign];
    int res = 0;

    if ( sign ) {
        res = ( (arr[ind]%mod*fun1(ind + 1, sign)%mod)%mod + fun(ind + 1, sign)%mod)%mod;
        res = (res%mod + fun(ind + 1, 0)%mod - (arr[ind]%mod*fun1(ind + 1, 0)%mod)%mod + mod)%mod;
    } else {
        res = ((arr[ind]%mod*fun1(ind + 1, 1)%mod )%mod+ fun(ind + 1, 1)%mod)%mod;
    }
    return dp[ind][sign] = res;
}
void solve() {
    memset(dp, -1, sizeof(dp));
    memset(dp1, -1, sizeof(dp));
    cin >> n;
    for ( int i=0; i<n; i++ ) cin >> arr[i];
    cout << fun(0,0) << '\n';
}
 
signed main() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin); 
        //freopen("output.txt", "w", stdout);
    #endif
 
ios_base::sync_with_stdio(false); cin.tie(NULL);
 
    int tc = 1;
    // cin >> tc;
    while( tc-- ) {
        solve();
    }
}
 
// Tarun IIITA

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[200010],sum[200010];
int main(){
    ll i,n; cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    sort(a,a + n);
    sum[0] = 0;
    for(i=1;i<=n;i++) sum[i] = sum[i - 1] + a[i - 1];
    ll ans = 0;
    for(i=0;i<n;i++){
        ans -= (n - 1 - 2*i)*a[i];
    }
    cout << ans << endl;
}