-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15824.cpp
More file actions
42 lines (33 loc) · 716 Bytes
/
15824.cpp
File metadata and controls
42 lines (33 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include<iostream>
#include<vector>
#include<algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;
vector<ll> arr;
ll power(ll a, ll exp)
{
if(exp==0) return 1;
return exp%2 ? (a*power(a, exp/2)*power(a, exp/2))%MOD : power(a, exp/2)*power(a, exp/2)%MOD;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
int n, i;
cin >> n;
for(i=1; i<=n; i++){
ll x;
cin >> x;
arr.push_back(x);
}
sort(arr.begin(), arr.end());
ll ans=0;
for(i=0; i<n; i++){
ans+=(arr[i]%MOD)*(power(2,i)-power(2,n-i-1))%MOD;
ans%=MOD;
if(ans<0) ans+=MOD;
}
cout << ans;
return 0;
}