Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct ModInt {
  using M = ModInt;
  long long v;
  ModInt(long long _v = 0) : v(_v % MOD + MOD) { norm(); }
  M& norm() {
    v = (v < MOD) ? v : v - MOD;
    return *this;
  }
  M operator+(const M& x) const { return M(v + x.v); }
  M operator-(const M& x) const { return M(v + MOD - x.v); }
  M operator*(const M& x) const { return M(v * x.v % MOD); }
  M operator/(const M& x) const { return M(v * x.inv().v); }
  M& operator+=(const M& x) { return *this = *this + x; }
  M& operator-=(const M& x) { return *this = *this - x; }
  M& operator*=(const M& x) { return *this = *this * x; }
  M& operator/=(const M& x) { return *this = *this / x; }
  friend istream& operator>>(istream& input, M& x) {
    return input >> x.v, x.norm(), input;
  }
  friend ostream& operator<<(ostream& output, const M& x) {
    return output << x.v;
  }
  M pow(long long n) const {
    M x(v), res(1);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  M inv() const { return this->pow(MOD - 2); }
  // M inv() const {
  //   int x, y;
  //   extgcd(this->v, MOD, x, y);
  //   return *this + M(x);
  // }

  static long long MOD;
  static vector<M> fact, finv;
  static void build(int n) {
    fact.assign(n + 1, 1);
    for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
    finv.assign(n + 1, fact[n].inv());
    for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * M(i);
  }
  static M comb(int n, int k) {
    if (n < k || k < 0) return M(0);
    return fact[n] * finv[n - k] * finv[k];
  }
  static M extgcd(int a, int b, int* x, int* y) {
    M d(a);
    if (b) {
      d = extgcd(b, a % b, y, x);
      *y -= (a / b) * *x;
    } else {
      *x = 1, *y = 0;
    }
    return d;
  }
};
vector<ModInt> ModInt::fact = vector<ModInt>();
vector<ModInt> ModInt::finv = vector<ModInt>();
long long ModInt::MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> o(120, vector<int>(n + 1, 0));
  vector<vector<int>> x(120, vector<int>(n + 1, 0));
  for (int b = 0; b < 120; b++) {
    for (int i = 0; i < n; i++) {
      o[b][i + 1] += o[b][i];
      x[b][i + 1] += x[b][i];
      if (a[i] >> min(60, b) & 1) {
        o[b][i + 1]++;
      } else {
        x[b][i + 1]++;
      }
    }
  }
  vector<ll> v(120);
  ll nxt = 0;
  for (int b = 0; b < 120; b++) {
    ll c = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] >> min(60, b) & 1) {
        c += x[b][i];
      } else {
        c += o[b][i];
      }
    }
    v[b] = (nxt + c) % 2;
    nxt = (nxt + c) / 2;
  }
  ModInt ans = 0;
  for (int b = 119; b >= 0; b--) {
    ans *= 2;
    ans += v[b];
  }
  cout << ans << endl;
}


Fixed submission:
#!/usr/bin/env python3
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<= 1
    c = sum(a[i] >> b & 1 for i in range(n))
    ans = (ans + c * (n - c)) % MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<= 1
    c = sum(a[i] >> b & 1 for i in range(n))
    ans = (ans + c * (n - c)) % MOD
print(ans)


Fixed submission:
#!/usr/bin/env python3
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<= 1
    c = sum(a[i] >> b & 1 for i in range(n))
    ans = (ans + c * (n - c)) % MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
o = [[0] * (n + 1) for _ in range(100)]
x = [[0] * (n + 1) for _ in range(100)]
for b in range(100):
    for i in range(n):
        o[b][i + 1] += o[b][i]
        x[b][i + 1] += x[b][i]
        if a[i] >> b & 1 == 1:
            o[b][i + 1] += 1
        else:
            x[b][i + 1] += 1
li = []
nxt = 0
for b in range(100):
    c = 0
    for i in range(n):
        if a[i] >> b & 1 == 1:
            c += x[b][i]
        else:
            c += o[b][i]
    li.append((nxt + c) % 2)
    nxt = (nxt + c) // 2
ans = 0
for b in range(100)[::-1]:
    ans *= 2
    ans += li[b]
    ans %= MOD
print(ans)


Fixed submission:
#!/usr/bin/env python3
MOD = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<= 1
    c = sum(a[i] >> b & 1 for i in range(n))
    ans = (ans + c * (n - c)) % MOD
print(ans)