alexjercan/bugnet huggingface dataset:
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F(i, a, b) for (int i = a; i <= b; ++i)
const int maxn = 2e5 + 5;
int n, a[maxn], pw1[maxn], pw2[maxn], f[maxn], sum1 = 0, sum2 = 0, tot = 0;
char s[maxn];
int pct(int x) { return x == 0 ? x : pct(x >> 1) + (x & 1); }
void run(int p) {
  a[p] ^= 1;
  int x = 0, pc = 0;
  if (a[p])
    pc = tot + 1;
  else
    pc = tot - 1;
  if (!pc) {
    a[p] ^= 1;
    f[p] = 0;
    return;
  }
  if (pc == tot - 1)
    x = (sum1 + tot - 1 - pw1[p]) % (tot - 1);
  else
    x = (sum2 + pw2[p]) % (tot + 1);
  ++f[p];
  while (x) {
    pc = pct(x);
    x %= pc;
    ++f[p];
  }
  a[p] ^= 1;
}
int main() {
  // freopen("data.in","r",stdin);
  // freopen("data.out","w",stdout);
  scanf("%d", &n);
  scanf("%s", s + 1);
  F(i, 1, n)
  if (s[i] == '1')
    a[i] = 1, ++tot;
  LL all = 0;
  for (int i = n; i; --i)
    all += a[i] * (1LL << (n - i));
  int tmp = 1;
  if (tot > 1) {
    F(i, 1, n) sum1 = (2 * sum1 + a[i]) % (tot - 1);
    for (int i = n; i; --i)
      pw1[i] = tmp, tmp = tmp * 2 % (tot - 1);
  }
  if (tot < n) {
    tmp = 1;
    F(i, 1, n)
    sum2 = (2 * sum2 + a[i]) % (tot + 1);
    for (int i = n; i; --i)
      pw2[i] = tmp, tmp = tmp * 2 % (tot + 1);
  }
  F(i, 1, n) run(i);
  F(i, 1, n) printf("%d\\n", f[i]);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define F(i, a, b) for (int i = a; i <= b; ++i)
const int maxn = 2e5 + 5;
int n, a[maxn], pw1[maxn], pw2[maxn], f[maxn], sum1 = 0, sum2 = 0, tot = 0;
char s[maxn];
int pct(int x) { return x == 0 ? x : pct(x >> 1) + (x & 1); }
void run(int p) {
  a[p] ^= 1;
  int x = 0, pc = 0;
  if (a[p])
    pc = tot + 1;
  else
    pc = tot - 1;
  if (!pc) {
    a[p] ^= 1;
    f[p] = 0;
    return;
  }
  if (pc == tot - 1)
    x = (sum1 + tot - 1 - pw1[p]) % (tot - 1);
  else
    x = (sum2 + pw2[p]) % (tot + 1);
  ++f[p];
  while (x) {
    pc = pct(x);
    x %= pc;
    ++f[p];
  }
  a[p] ^= 1;
}
int main() {
  // freopen("data.in","r",stdin);
  // freopen("data.out","w",stdout);
  scanf("%d", &n);
  scanf("%s", s + 1);
  F(i, 1, n)
  if (s[i] == '1')
    a[i] = 1, ++tot;
  LL all = 0;
  for (int i = n; i; --i)
    all += a[i] * (1LL << (n - i));
  int tmp = 1;
  if (tot) {
    F(i, 1, n) sum1 = (2 * sum1 + a[i]) % (tot - 1);
    for (int i = n; i; --i)
      pw1[i] = tmp, tmp = tmp * 2 % (tot - 1);
  }
  if (tot < n) {
    tmp = 1;
    F(i, 1, n)
    sum2 = (2 * sum2 + a[i]) % (tot + 1);
    for (int i = n; i; --i)
      pw2[i] = tmp, tmp = tmp * 2 % (tot + 1);
  }
  F(i, 1, n) run(i);
  F(i, 1, n) printf("%d\\n", f[i]);
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============modpow============================
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  string X;
  cin >> X;
  reverse(X.begin(), X.end());
  ll pc = 0;
  for (ll i = 0; i < N; ++i) {
    if (X.at(i) == '1') {
      pc += 1;
    }
  }
  ll s = 0, l = 0;
  for (ll i = 0; i < N; ++i) {
    if (X.at(i) == '1') {
      if (pc != 1) {
        s += modpow(2, i, pc - 1);
        s %= (pc - 1);
      }
      l += modpow(2, i, pc + 1);
      l %= (pc + 1);
    }
  }
  for (ll i = N - 1; i >= 0; --i) {
    ll now;
    ll ans = 1;
    if (X.at(i) == '1') {
      if (pc == 1) {
        cout << '0' << "\\n";
        continue;
      }
      now = s;
      now -= modpow(2, i, pc - 1);
      if (now < 0) {
        now += pc - 1;
      }
      now %= (pc - 1);
    } else {
      now = l;
      now += modpow(2, i, pc + 1);
      now %= (pc + 1);
    }
    // cout << now << "\\n";
    while (now != 0) {
      now %= __builtin_popcountll(now);
      ans += 1;
    }
    cout << ans << "\\n";
  }
  // cout << s << m << l << "\\n";
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

//=============modpow============================
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  string X;
  cin >> X;
  reverse(X.begin(), X.end());
  ll pc = 0;
  for (ll i = 0; i < N; ++i) {
    if (X.at(i) == '1') {
      pc += 1;
    }
  }
  ll s = 0, l = 0;
  for (ll i = 0; i < N; ++i) {
    if (X.at(i) == '1') {
      s += modpow(2, i, pc - 1);
      s %= (pc - 1);
      l += modpow(2, i, pc + 1);
      l %= (pc + 1);
    }
  }
  for (ll i = N - 1; i >= 0; --i) {
    ll now;
    ll ans = 1;
    if (X.at(i) == '1') {
      now = s;
      now -= modpow(2, i, pc - 1);
      if (now < 0) {
        now += pc - 1;
      }
      now %= (pc - 1);
    } else {
      now = l;
      now += modpow(2, i, pc + 1);
      now %= (pc + 1);
    }
    // cout << now << "\\n";
    while (now != 0) {
      now %= __builtin_popcountll(now);
      ans += 1;
    }
    cout << ans << "\\n";
  }
  // cout << s << m << l << "\\n";
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;
bool debug = true;

//=============modpow============================
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  string X;
  cin >> N >> X;
  ll pc = 0;
  for (ll i = 0; i < N; ++i) {
    if (X.at(i) == '1') {
      pc += 1;
    }
  }
  ll chose1 = 0;
  ll chose0 = 0;
  for (ll i = 0; i < N; ++i) {
    if (X.at(i) == '1') {
      chose0 += modpow(2, (N - i - 1), pc + 1);
      chose0 %= pc + 1;
      if (pc - 1 != 0) {
        chose1 += modpow(2, (N - i - 1), pc - 1);
        chose1 %= pc - 1;
      }
    }
  }
  for (ll i = 0; i < N; ++i) {
    ll left;
    ll ans = 1;
    if (X.at(i) == '1') {
      if (pc - 1 == 0) {
        cout << 0 << "\\n";
        continue;
      }
      left = chose1 - modpow(2, (N - i - 1), pc - 1);
      if (left < 0) {
        left += pc - 1;
      }
      left %= pc - 1;
    } else {
      left = chose0 + modpow(2, (N - i - 1), pc + 1);
      left %= pc + 1;
    }
    // cout << "left" << left << "\\n";
    while (left != 0) {
      left %= __builtin_popcount(left);
      ans += 1;
    }
    cout << ans << "\\n";
  }
}


Error: 0

Fixed submission:

#include <iostream>
#include <string>
#define MAX 200000
using namespace std;

/*
popcount(n)
f(n) = n%popcount(n)が0になるまで
*/

long long n;
string X;

void f(long long k, long long n) {
  if (n == 0)
    printf("%lld\\n", k);
  else {
    // cは1の個数
    long long m = n, c = 0;
    while (m) {
      c += m & 1;
      m >>= 1;
    }
    f(k + 1, n % c);
  }
}

int main() {

  cin >> n;
  cin >> X;

  long long num = 0;

  // 1の数を数える
  for (int i = 0; i < n; i++) {
    if (X[i] == '1')
      num++;
  }

  long long x[MAX], y[MAX], z[MAX], b = 1;

  x[n - 1] = 1 % num;
  y[n - 1] = 1 % (num + 1);
  z[n - 1] = 1 % (num - 1);

  for (int i = n - 2; i >= 0; i--) {
    // i桁目が1だったときの mod num + 1
    y[i] = (2 * y[i + 1]) % (num + 1);
    // i桁目が1だったときの mod num - 1
    z[i] = (2 * z[i + 1]) % (num - 1);
  }

  // mod num + 1のときの値
  long long ans1 = 0;
  for (int j = 0; j < X.size(); j++) {
    if (X[j] == '1')
      ans1 = (ans1 + y[j]) % (num + 1);
  }

  // mod num - 1のときの値
  long long ans2 = 0;
  for (int j = 0; j < X.size(); j++) {
    if (X[j] == '1')
      ans2 = (ans2 + z[j]) % (num - 1);
  }

  for (int i = 0; i < n; i++) {

    string s;
    long long mod = num;
    long long c = 0;
    s = X;
    if (X[i] == '0') {
      s[i] = '1';
      mod++;

      c = (ans1 + y[i]) % mod;
    }
    if (X[i] == '1') {
      s[i] = '0';
      mod--;

      c = (ans2 - z[i] + mod) % mod;
    }

    if (c != 0) {

      f(1, c);
    } else {
      cout << "1" << endl;
    }
  }

  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

ll sol(string s, ll mod) {
  if (mod <= 0)
    return 0;
  reverse(s.begin(), s.end());
  ll n = s.size();
  ll p = 1;
  ll rem = 0;

  for (ll i = 0; i < n; i++) {
    rem += (s[i] - '0') * p;
    p *= 2;
    rem %= mod;
    p %= mod;
  }

  return rem;
}

ll bigMod(ll a, ll b, ll mod) {
  if (mod == 0)
    return 0;
  if (b == 0)
    return 1;
  ll x = bigMod(a, b / 2, mod);
  if (b % 2 == 0)
    return (x * x) % mod;
  x = (x * x) % mod;
  return (x * a) % mod;
}
ll solve(ll ans, ll mod) {
  ll res = 1;
  if (mod == 0)
    return 0;
  while (ans) {
    ll cnt = __builtin_popcount(ans);
    ans %= cnt;
    res++;
  }

  return res;
}
int main() {

  ll n, cnt = 0, i;
  string s;
  cin >> n >> s;

  for (i = 0; i < n; i++)
    cnt += (s[i] == '1');

  ll rem1 = sol(s, cnt + 1);
  ll rem2 = sol(s, cnt - 1);

  for (i = 0; i < n; i++) {
    ll ans;
    ll modu;
    if (s[i] == '0') {
      ll rem = bigMod(2, (n - i - 1), cnt + 1);
      ans = rem1 + rem;
      ans = (ans) % (cnt + 1);
      modu = cnt + 1;

    } else {
      modu = cnt - 1;
      if (modu == 0) {
        cout << 0 << endl;
        continue;
      }
      ll mod = cnt - 1;
      ll rem = bigMod(2, (n - i - 1), cnt - 1);
      ans = (((rem2 - rem) % mod) + mod) % mod;
      ans = ans % mod;
    }
    cout << solve(ans, modu) << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

ll sol(string s, ll mod) {
  if (mod < 0)
    return 0;
  reverse(s.begin(), s.end());
  ll n = s.size();
  ll p = 1;
  ll rem = 0;

  for (ll i = 0; i < n; i++) {
    rem += (s[i] - '0') * p;
    p *= 2;
    rem %= mod;
    p %= mod;
  }

  return rem;
}

ll bigMod(ll a, ll b, ll mod) {
  if (b == 0)
    return 1;
  ll x = bigMod(a, b / 2, mod);
  if (b % 2 == 0)
    return (x * x) % mod;
  x = (x * x) % mod;
  return (x * a) % mod;
}
ll solve(ll ans, ll mod) {
  ll res = 1;

  while (ans) {
    ll cnt = __builtin_popcount(ans);
    ans %= cnt;
    res++;
  }

  return res;
}
int main() {

  ll n, cnt = 0, i;
  string s;
  cin >> n >> s;

  for (i = 0; i < n; i++)
    cnt += (s[i] == '1');

  ll rem1 = sol(s, cnt + 1);
  ll rem2 = sol(s, cnt - 1);

  for (i = 0; i < n; i++) {
    ll ans;
    ll modu;
    if (s[i] == '0') {
      ll rem = bigMod(2, (n - i - 1), cnt + 1);
      ans = rem1 + rem;
      ans = (ans) % (cnt + 1);
      modu = cnt + 1;

    } else {
      modu = cnt - 1;
      ll mod = cnt - 1;
      ll rem = bigMod(2, (n - i - 1), cnt - 1);
      ans = (((rem2 - rem) % mod) + mod) % mod;
      ans = ans % mod;
    }
    cout << solve(ans, modu) << endl;
  }

  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);
#define endl '\\n'
#define cerr
#endif
#define _ << ' ' <<
#define Fr(i, s, e) for (auto i = s; i < e; ++i)
#define All(v) v.begin(), v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 1e9 + 7;

signed main() {
  FAST;

  int n;
  string x;
  cin >> n >> x;
  reverse(All(x));
  vector<int> ans(n);
  int c = 0;
  Fr(j, 0, n) c += x[j] == '1';
  auto f = [&](char t, int z) {
    const int mod = c + z;
    if (!mod)
      return;
    int k = 0, r = 1;
    Fr(i, 0, n) {
      k = (k + r * (x[i] == '1')) % mod;
      r = r * 2 % mod;
    }
    r = (z + mod) % mod;
    Fr(i, 0, n) {
      if (x[i] == t) {
        ans[i] = 1;
        int y = (k + r) % mod;
        while (y) {
          ans[i]++;
          y = y % __builtin_popcount(y);
        }
      }
      r = r * 2 % mod;
    }
  };
  f('1', -1);
  f('0', +1);
  reverse(All(ans));
  Fr(i, 0, n) cout << ans[i] << endl;
}


Error: 0

Fixed submission:

#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST                                                                   \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);
#define endl '\\n'
#define cerr
#endif
#define _ << ' ' <<
#define Fr(i, s, e) for (auto i = s; i < e; ++i)
#define All(v) v.begin(), v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 1e9 + 7;

signed main() {
  FAST;

  int n;
  string x;
  cin >> n >> x;
  reverse(All(x));
  vector<int> ans(n);
  int c = 0;
  Fr(j, 0, n) c += x[j] == '1';
  auto f = [&](char t, int z) {
    const int mod = c + z;
    int k = 0, r = 1;
    Fr(i, 0, n) {
      k = (k + r * (x[i] == '1')) % mod;
      r = r * 2 % mod;
    }
    r = (z + mod) % mod;
    Fr(i, 0, n) {
      if (x[i] == t) {
        ans[i] = 1;
        int y = (k + r) % mod;
        while (y) {
          ans[i]++;
          y = y % __builtin_popcount(y);
        }
      }
      r = r * 2 % mod;
    }
  };
  f('1', -1);
  f('0', +1);
  reverse(All(ans));
  Fr(i, 0, n) cout << ans[i] << endl;
}
Problem p02609 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;

ll solve(ul num) {
  ul pop = __builtin_popcount(num);
  if (pop == 0) {
    return 0;
  }
  return solve(num % pop) + 1;
}

int main() {
  ll n;
  string x;
  cin >> n >> x;

  ll pop = 0;
  rep(i, n) {
    if (x[i] == '1') {
      pop++;
    }
  }

  ll mod_memo[2];
  ll base_memo[2][n];
  rep(i, 2) {
    ll pop_temp = pop;
    if (i == 0)
      pop_temp++;
    else
      pop_temp--;

    if (pop_temp == 0) {
      mod_memo[i] = 0;
      continue;
    }

    ul base = 1;
    ll mod = 0;
    rep(j, n) {
      ll index = n - j - 1;
      base_memo[i][index] = base;
      if (x[index] == '1') {
        mod += base;
        mod %= pop_temp;
      }
      base *= 2;
      base %= pop_temp;
    }
    mod_memo[i] = mod;
  }

  rep(i, n) {
    ll mod_temp;
    ll pop_temp = pop;

    if (x[i] == '0') {
      pop_temp++;
      mod_temp = mod_memo[0] + base_memo[0][i];
      mod_temp %= pop_temp;
    } else {
      pop_temp--;
      if (pop_temp == 0) {
        cout << 0 << endl;
        continue;
      }
      mod_temp = mod_memo[1] - base_memo[1][i] + pop_temp;
      mod_temp %= pop_temp;
    }
    cout << solve(mod_temp) + 1 << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;

ll solve(ul num) {
  ul pop = __builtin_popcount(num);
  if (pop == 0) {
    return 0;
  }
  return solve(num % pop) + 1;
}

int main() {
  ll n;
  string x;
  cin >> n >> x;

  ll pop = 0;
  rep(i, n) {
    if (x[i] == '1') {
      pop++;
    }
  }

  rep(i, n) {
    ll pop_temp = pop;
    if (x[i] == '0') {
      pop_temp++;
    } else {
      pop_temp--;
    }
    if (pop_temp == 0) {
      cout << 0 << endl;
      continue;
    }

    ul base = 1;
    ll mod = 0;
    rep(j, n) {
      ll index = n - j - 1;
      if (index != i) {
        if (x[index] == '1') {
          mod += base;
        }
      } else {
        if (x[index] == '0') {
          mod += base;
        }
      }
      base *= 2;
      base %= pop_temp;
    }
    mod %= pop_temp;
    // cout << mod << endl;
    cout << solve(mod) + 1 << endl;
  }
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for (i64 i = 0; i < N; i++)
#define Rep(i, k, N) for (i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {
  if (b) {
    return "Yes";
  } else {
    return "No";
  }
}
string YES(bool b) {
  if (b) {
    return "YES";
  } else {
    return "NO";
  }
}

i64 f(i64 n) {
  int cnt = 0;
  while (n) {
    n %= bitset<64>(n).count();
    cnt++;
  }
  return cnt;
}

i64 POW2[2][200010]; // [2^k % (popcount(X) + 1),  2^k % (popcount(X) - 1)]
i64 XmPC[2];         // [X % (popcount(X) + 1),  X % popcount(X - 1)]

int main() {
  int N;
  string X;
  cin >> N >> X;

  i64 popcnt = count(X.begin(), X.end(), '1');
  POW2[0][0] = 1 % (popcnt + 1);
  if (popcnt - 1 > 0)
    POW2[1][0] = 1 % (popcnt - 1);

  for (int i = 0; i < N; i++) {
    XmPC[0] = ((2 * XmPC[0]) + (X[i] - '0')) % (popcnt + 1);
    POW2[0][i + 1] = (2 * POW2[0][i]) % (popcnt + 1);
    if (popcnt - 1 > 0) {
      XmPC[1] = ((2 * XmPC[1]) + (X[i] - '0')) % (popcnt - 1);
      POW2[1][i + 1] = (2 * POW2[1][i]) % (popcnt - 1);
    }
  }

  for (int i = 0; i < N; i++) {
    i64 b = (X[i] - '0');
    i64 p = (1 - 2 * b);
    i64 n = (XmPC[b] + p * POW2[b][N - i - 1]);
    while (n < 0)
      n += (popcnt + p);
    if (popcnt + p < 1)
      cout << 0 << endl;
    else
      cout << f(n % (popcnt + p)) + 1 << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for (i64 i = 0; i < N; i++)
#define Rep(i, k, N) for (i64 i = k; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {
  if (b) {
    return "Yes";
  } else {
    return "No";
  }
}
string YES(bool b) {
  if (b) {
    return "YES";
  } else {
    return "NO";
  }
}

i64 f(i64 &n) {
  int cnt = 0;
  while (n) {
    n %= __builtin_popcount(n);
    cnt++;
  }
  return cnt;
}

i64 POW2[2][200010]; // [2^k % (popcount(X) + 1),  2^k % (popcount(X) - 1)]
i64 XmPC[2];         // [X % (popcount(X) + 1),  X % popcount(X - 1)]

int main() {
  int N;
  string X;
  cin >> N >> X;

  i64 popcnt = count(X.begin(), X.end(), '1');
  POW2[0][0] = 1 % (popcnt + 1);
  if (popcnt - 1 > 0)
    POW2[1][0] = 1 % (popcnt - 1);

  for (int i = 0; i < N; i++) {
    XmPC[0] = ((2 * XmPC[0]) + (X[i] - '0')) % (popcnt + 1);
    POW2[0][i + 1] = (2 * POW2[0][i]) % (popcnt + 1);
    if (popcnt - 1 > 0) {
      XmPC[1] = ((2 * XmPC[1]) + (X[i] - '0')) % (popcnt - 1);
      POW2[1][i + 1] = (2 * POW2[1][i]) % (popcnt - 1);
    }
  }

  for (int i = 0; i < N; i++) {
    i64 b = (X[i] - '0');
    i64 p = (1 - 2 * b);
    i64 n = (XmPC[b] + p * POW2[b][N - i - 1]);
    while (n < 0)
      n += (popcnt + p);
    n %= (popcnt + p);
    cout << f(n) + 1 << endl;
  }
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e6 + 10;
char s[maxn];
int fac1[maxn], fac2[maxn], mod1 = 0, mod2 = 0;
int get_step(int x) {
  int cnt = 0;
  while (x) {
    x %= __builtin_popcount(x);
    cnt++;
  }
  return cnt;
}
int main() {
  int n = read();
  scanf("%s", s + 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1') {
      cnt++;
    }
  }
  mod1 = cnt + 1;
  mod2 = cnt - 1;
  fac1[n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    fac1[i] = fac1[i + 1] * 2;
    fac1[i] %= mod1;
  }
  fac2[n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    fac2[i] = fac2[i + 1] * 2;
    if (mod2)
      fac2[i] %= mod2;
  }
  LL ans1 = 0, ans2 = 0;
  for (int i = 1; i <= n; i++) {
    ans1 = ans1 * 2 + s[i] - '0';
    ans1 %= mod1;
    ans2 = ans2 * 2 + s[i] - '0';
    if (mod2)
      ans2 %= mod2;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == '0') {
      LL ans = ans1 + fac1[i];
      ans %= mod1;
      cout << 1 + get_step(ans) << endl;
    } else {
      LL ans = ans2 - fac2[i];
      if (mod2) {
        ans = (ans % mod2 + mod2) % mod2;
        cout << 1 + get_step(ans) << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline long long read() {
  long long f = 1, x = 0;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-')
      f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int maxn = 1e6 + 10;
char s[maxn];
int fac1[maxn], fac2[maxn], mod1 = 0, mod2 = 0;
int get_step(int x) {
  int cnt = 0;
  while (x) {
    x %= __builtin_popcount(x);
    cnt++;
  }
  return cnt;
}
int main() {
  int n = read();
  scanf("%s", s + 1);
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (s[i] == '1') {
      cnt++;
    }
  }
  mod1 = cnt + 1;
  mod2 = cnt - 1;
  fac1[n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    fac1[i] = fac1[i + 1] * 2;
    fac1[i] %= mod1;
  }
  fac2[n] = 1;
  for (int i = n - 1; i >= 1; i--) {
    fac2[i] = fac2[i + 1] * 2;
    fac2[i] %= mod2;
  }
  LL ans1 = 0, ans2 = 0;
  for (int i = 1; i <= n; i++) {
    ans1 = ans1 * 2 + s[i] - '0';
    ans1 %= mod1;
    ans2 = ans2 * 2 + s[i] - '0';
    ans2 %= mod2;
  }
  for (int i = 1; i <= n; i++) {
    if (s[i] == '0') {
      // cout << ans1 << ' ' << fac1[i] << endl;
      LL ans = ans1 + fac1[i];
      ans %= mod1;
      // cout << ans << ' ' << i << endl;
      cout << 1 + get_step(ans) << endl;
    } else {
      LL ans = ans2 + fac2[i];
      ans %= mod2;
      cout << 1 + get_step(ans) << endl;
    }
  }
  return 0;
}