Problem p02838 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define MAX 1000001
#define pb push_back
#define mk make_pair
#define ll long long
#define pii pair<int, int>
ll M = 1000000000 + 7;
ll sum[200005][65];
ll pot[63];
int main() {
  pot[0] = 1LL;
  for (int i = 1; i < 62; i++) {
    pot[i] = (pot[i - 1] * 2LL) % M;
  }
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);
  int n;
  cin >> n;
  vector<ll> arr;
  ll temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    arr.pb(temp);
  }
  for (int i = 0; i < n; i++) {
    vector<int> many;
    for (int x = 0; x < 61; x++) {
      if (((1LL << x) & arr[i]) == (1LL << x)) {
        many.pb(1LL);
      } else {
        many.pb(0);
      }
    }
    for (int x = 0; x < 61; x++) {
      if (i != 0) {
        sum[i][x] = sum[i - 1][x] + many[x];
      } else {
        sum[i][x] = many[x];
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    for (int x = 0; x < 61; x++) {
      // cout << "sum[i][x] = " << i << " " << x << " " << sum[i][x] << endl;
      if (((1LL << x) & arr[i]) == (1LL << x)) {
        ll times = (1LL * i) - sum[i - 1][x];

        ll add = (times * pot[x]) % M;
        // cout << "times = " << times << endl;
        // cout << "add= " << add << endl;
        ans = (ans + add) % M;
      } else {
        ll times = sum[i - 1][x];
        ll add = (times * pot[x]) % M;
        // cout << "times = " << times << endl;
        // cout << "add= " << add << endl;
        ans = (ans + add) % M;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define MAX 1000001
#define pb push_back
#define mk make_pair
#define ll long long
#define pii pair<int, int>
ll M = 1000000000 + 7;
ll sum[300005][65];
ll pot[63];
int main() {
  pot[0] = 1LL;
  for (int i = 1; i < 62; i++) {
    pot[i] = (pot[i - 1] * 2LL) % M;
  }
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);
  int n;
  cin >> n;
  vector<ll> arr;
  ll temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    arr.pb(temp);
  }
  for (int i = 0; i < n; i++) {
    vector<int> many;
    for (int x = 0; x < 61; x++) {
      if (((1LL << x) & arr[i]) == (1LL << x)) {
        many.pb(1LL);
      } else {
        many.pb(0);
      }
    }
    for (int x = 0; x < 61; x++) {
      if (i != 0) {
        sum[i][x] = sum[i - 1][x] + many[x];
      } else {
        sum[i][x] = many[x];
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i < n; i++) {
    for (int x = 0; x < 61; x++) {
      // cout << "sum[i][x] = " << i << " " << x << " " << sum[i][x] << endl;
      if (((1LL << x) & arr[i]) == (1LL << x)) {
        ll times = (1LL * i) - sum[i - 1][x];

        ll add = (times * pot[x]) % M;
        // cout << "times = " << times << endl;
        // cout << "add= " << add << endl;
        ans = (ans + add) % M;
      } else {
        ll times = sum[i - 1][x];
        ll add = (times * pot[x]) % M;
        // cout << "times = " << times << endl;
        // cout << "add= " << add << endl;
        ans = (ans + add) % M;
      }
    }
  }
  cout << ans << endl;
  return 0;
}