Problem p02815 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define SIZE 200005
#define M 1000000007
ll power(ll a, ll b) {
  if (b == 0)
    return 1;
  ll p = power(a, b / 2);
  p = (p * p) % M;
  if (b % 2 == 0) {
    return p;
  } else {
    return (p * a) % M;
  }
}
ll arr[SIZE];
ll presum[SIZE];
// ll binomial[SIZE];
// ll binomialCoeff(ll n, ll k)
// {
// 	if(n==0)
// 		return 1;

//     ll res = 1;

//     // Since C(n, k) = C(n, n-k)
//     if ( k > n - k )
//         k = n - k;

//     // Calculate value of
//     // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
//     for (ll i = 0; i < k; ++i)
//     {
//         res *= (n - i);
//         res /= (i + 1);
//     }

//     return res;
// }

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  for (ll i = 1; i <= N; ++i) {
    cin >> arr[i];
  }
  sort(arr + 1, arr + N + 1, greater<ll>());
  ll ans = 0, ans2 = 0;
  presum[0] = 1;
  for (ll i = 1; i <= N; ++i) {
    // ll temp=0;
    // for(ll j=0;j<i;++j){
    // 	temp+=(j+1)*binomialCoeff(i-1,j);
    // }
    // ans2=(ans2+((power(2,i)*temp)%M*(arr[i]*power(2,2*(N-i)))%M)%M)%M;
    ans = (ans + (((power(2, i) * presum[i - 1]) % M) *
                  ((arr[i] * power(2, 2 * (N - i))) % M) % M)) %
          M;
    presum[i] = ((2 * presum[i - 1]) % M + power(2, i - 1)) % M;
    // cout<<arr[i]<<" "<<ans<<" "<<presum[i-1]<<":"<<ans2<<" "<<temp<<endl;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define SIZE 200005
#define M 1000000007
ll power(ll a, ll b) {
  if (b == 0)
    return 1;
  ll p = power(a, b / 2);
  p = (p * p) % M;
  if (b % 2 == 0) {
    return p;
  } else {
    return (p * a) % M;
  }
}
ll arr[SIZE];
ll presum[SIZE];
// ll binomial[SIZE];
// ll binomialCoeff(ll n, ll k)
// {
// 	if(n==0)
// 		return 1;

//     ll res = 1;

//     // Since C(n, k) = C(n, n-k)
//     if ( k > n - k )
//         k = n - k;

//     // Calculate value of
//     // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
//     for (ll i = 0; i < k; ++i)
//     {
//         res *= (n - i);
//         res /= (i + 1);
//     }

//     return res;
// }

int main() {
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  // #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  for (ll i = 1; i <= N; ++i) {
    cin >> arr[i];
  }
  sort(arr + 1, arr + N + 1, greater<ll>());
  ll ans = 0, ans2 = 0;
  presum[0] = 1;
  for (ll i = 1; i <= N; ++i) {
    // ll temp=0;
    // for(ll j=0;j<i;++j){
    // 	temp+=(j+1)*binomialCoeff(i-1,j);
    // }
    // ans2=(ans2+((power(2,i)*temp)%M*(arr[i]*power(2,2*(N-i)))%M)%M)%M;
    ans = (ans + (((power(2, i) * presum[i - 1]) % M) *
                  ((arr[i] * power(2, 2 * (N - i))) % M) % M)) %
          M;
    presum[i] = ((2 * presum[i - 1]) % M + power(2, i - 1)) % M;
    // cout<<arr[i]<<" "<<ans<<" "<<presum[i-1]<<":"<<ans2<<" "<<temp<<endl;
  }
  cout << ans << endl;
}