fork download
  1. /*input
  2. 6
  3. 1 2 3 4 5 6
  4. */
  5. #include <bits/stdc++.h>
  6. #include<stdio.h>
  7. using namespace std;
  8. #define F(i,a,b) for(ll i = a; i <= b; i++)
  9. #define RF(i,a,b) for(ll i = a; i >= b; i--)
  10. #define pii pair<ll,ll>
  11. #define PI 3.14159265358979323846264338327950288
  12. #define ll long long
  13. #define ff first
  14. #define ss second
  15. #define pb(x) push_back(x)
  16. #define mp(x,y) make_pair(x,y)
  17. #define debug(x) cout << #x << " = " << x << endl
  18. #define INF 1000000009
  19. #define mod 1000000007
  20. #define S(x) scanf("%d",&x)
  21. #define S2(x,y) scanf("%d%d",&x,&y)
  22. #define P(x) printf("%d\n",x)
  23. #define all(v) v.begin(),v.end()
  24. ll powertwo[400005],arr[400005];
  25. int main()
  26. {
  27. std::ios::sync_with_stdio(false);
  28. powertwo[0]=1;
  29. F(i,1,400000)
  30. powertwo[i] = (powertwo[i-1]*2ll)%mod;
  31. ll n;
  32. cin>>n;
  33. F(i,0,n-1)
  34. cin>>arr[i];
  35. sort(arr,arr+n);
  36. ll ans = 0;
  37. ll p=n-1,q=0;
  38. RF(i,n-1,0)
  39. {
  40. ll add = powertwo[p] - 1ll;
  41. add %= mod;
  42. add = add*arr[i];
  43. add %= mod;
  44. ans += add;
  45. ans %= mod;
  46. ll sub = powertwo[q] - 1ll;
  47. sub %= mod;
  48. sub = sub*arr[i];
  49. ans -= sub;
  50. ans += mod*100000000ll;
  51. ans %= mod;
  52. p--;
  53. q++;
  54. }
  55. cout<<ans<<endl;
  56. return 0;
  57. }
Success #stdin #stdout 0s 22312KB
stdin
Standard input is empty
stdout
0