Problem p02838 (C++)

Buggy submission (status: Runtime Error):
/************************************************************
        > File Name: d.cpp
        > Author: TSwiftie
        > Mail: 2224273204@qq.com
        > Created Time: Fri 20 Dec 2019 03:02:31 AM CST
************************************************************/

#pragma GCC optimize(2)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <unordered_map>
#define lowbit(x) (x & -x)
#define lc (o << 1)
#define rc (o << 1 | 1)
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
const int MAXM = 2e5 + 5;
const int MOD = 1e9 + 7;
const int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
ll n;
ll a[MAXN];
int bit[65];
int main(void) {
  IOS;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int j = 0; j < 62; j++)
      if (a[i] & (1ll << j))
        bit[j]++;
  }
  ll ans = 0;
  for (int i = 0; i < 62; i++)
    ans = (ans + ((bit[i] * (n - bit[i]) % MOD) * ((1ll << i) % MOD)) % MOD) %
          MOD;
  cout << ans << endl;
  return 0;
}

Fixed submission:
/************************************************************
        > File Name: d.cpp
        > Author: TSwiftie
        > Mail: 2224273204@qq.com
        > Created Time: Fri 20 Dec 2019 03:02:31 AM CST
************************************************************/

#pragma GCC optimize(2)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
// #include <unordered_map>
#define lowbit(x) (x & -x)
#define lc (o << 1)
#define rc (o << 1 | 1)
#define IOS                                                                    \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 3e5 + 5;
const int MAXM = 2e5 + 5;
const int MOD = 1e9 + 7;
const int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
ll n;
ll a[MAXN];
int bit[65];
int main(void) {
  IOS;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int j = 0; j < 62; j++)
      if (a[i] & (1ll << j))
        bit[j]++;
  }
  ll ans = 0;
  for (int i = 0; i < 62; i++)
    ans = (ans + ((bit[i] * (n - bit[i]) % MOD) * ((1ll << i) % MOD)) % MOD) %
          MOD;
  cout << ans << endl;
  return 0;
}