/*input
6
1 2 3 4 5 6
*/
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define F(i,a,b) for(ll i = a; i <= b; i++)
#define RF(i,a,b) for(ll i = a; i >= b; i--)
#define pii pair<ll,ll>
#define PI 3.14159265358979323846264338327950288
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
ll powertwo[400005],arr[400005];
int main()
{
std::ios::sync_with_stdio(false);
powertwo[0]=1;
F(i,1,400000)
powertwo[i] = (powertwo[i-1]*2ll)%mod;
ll n;
cin>>n;
F(i,0,n-1)
cin>>arr[i];
sort(arr,arr+n);
ll ans = 0;
ll p=n-1,q=0;
RF(i,n-1,0)
{
ll add = powertwo[p] - 1ll;
add %= mod;
add = add*arr[i];
add %= mod;
ans += add;
ans %= mod;
ll sub = powertwo[q] - 1ll;
sub %= mod;
sub = sub*arr[i];
ans -= sub;
ans += mod*100000000ll;
ans %= mod;
p--;
q++;
}
cout<<ans<<endl;
return 0;
}
LyppbnB1dAo2CjEgMiAzIDQgNSA2CiovCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgojaW5jbHVkZTxzdGRpby5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwojZGVmaW5lIEYoaSxhLGIpIGZvcihsbCBpID0gYTsgaSA8PSBiOyBpKyspCiNkZWZpbmUgUkYoaSxhLGIpIGZvcihsbCBpID0gYTsgaSA+PSBiOyBpLS0pCiNkZWZpbmUgcGlpIHBhaXI8bGwsbGw+CiNkZWZpbmUgUEkgMy4xNDE1OTI2NTM1ODk3OTMyMzg0NjI2NDMzODMyNzk1MDI4OAojZGVmaW5lIGxsIGxvbmcgbG9uZwojZGVmaW5lIGZmIGZpcnN0CiNkZWZpbmUgc3Mgc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