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

#include <bits/stdc++.h>
using namespace std;

int n;
char x[200005];
int dp[200005];
long long sump, summ;
int popcnt;

long long fastexp(int base, int index, int mod) {
  if (index == 0)
    return 1 % mod;
  if (index == 1)
    return base % mod;
  long long temp = fastexp(base, index / 2, mod) % mod;
  temp *= temp;
  temp %= mod;
  if (index % 2 == 1)
    temp *= base;
  temp %= mod;
  return temp;
}

int main() {
  scanf("%d", &n);
  scanf(" %s", x);
  for (int i = 0; i < n; i++)
    if (x[i] == '1')
      popcnt++;
  for (int i = 0; i < n; i++) {
    if (x[i] == '1') {
      sump += fastexp(2, n - i - 1, popcnt + 1);
      sump %= popcnt + 1;
      if (popcnt > 1) {
        summ += fastexp(2, n - i - 1, popcnt - 1);
        summ %= popcnt - 1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    dp[i] = dp[i % __builtin_popcount(i)] + 1;
  }
  for (int i = 0; i < n; i++) {
    long long cursum;
    if (x[i] == '0') {
      cursum = sump + fastexp(2, n - i - 1, popcnt + 1);
      cursum %= popcnt + 1;
    } else if (popcnt > 1) {
      cursum = summ - fastexp(2, n - i - 1, popcnt - 1);
      cursum %= popcnt - 1;
      cursum = (cursum + popcnt - 1) % (popcnt - 1);
    } else {
      printf("0\\n");
      continue;
    }
    printf("%d\\n", dp[cursum] + 1);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int n;
char x[200005];
int dp[200005];
long long sump, summ;
int popcnt;

long long fastexp(int base, int index, int mod) {
  if (index == 0)
    return 1 % mod;
  if (index == 1)
    return base % mod;
  long long temp = fastexp(base, index / 2, mod) % mod;
  temp *= temp;
  temp %= mod;
  if (index % 2 == 1)
    temp *= base;
  temp %= mod;
  return temp;
}

int main() {
  scanf("%d", &n);
  scanf(" %s", x);
  for (int i = 0; i < n; i++)
    if (x[i] == '1')
      popcnt++;
  for (int i = 0; i < n; i++) {
    if (x[i] == '1') {
      sump += fastexp(2, n - i - 1, popcnt + 1);
      summ += fastexp(2, n - i - 1, popcnt - 1);
      sump %= popcnt + 1;
      if (popcnt > 1)
        summ %= popcnt - 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    int curcnt = 0;
    for (int j = 1; j <= i; j <<= 1)
      if (i & j)
        curcnt++;
    dp[i] = dp[i % curcnt] + 1;
  }
  for (int i = 0; i < n; i++) {
    long long cursum;
    if (x[i] == '0') {
      cursum = sump + fastexp(2, n - i - 1, popcnt + 1);
      cursum %= popcnt + 1;
    } else if (popcnt > 1) {
      cursum = summ - fastexp(2, n - i - 1, popcnt - 1);
      cursum %= popcnt - 1;
      cursum = (cursum + popcnt - 1) % (popcnt - 1);
    } else {
      printf("0\\n");
      break;
    }
    printf("%d\\n", dp[cursum] + 1);
  }
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> mp;
ll inf = 1e9;

ll func(ll v) {
  ll cnt = 0;
  ll ans = 0;
  while (v != 0) {
    cnt = 0;
    for (ll i = 0; i < 64; i++)
      if ((v >> i) & 1)
        cnt++;
    v %= cnt;
    ans++;
  }
  return ans;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    if (s[i] == '1')
      cnt++;
  }

  ll vp = 0, vu = 0;
  vector<ll> bp(n, 1), bu(n, 1);
  for (ll i = n - 1; i >= 1; i--) {
    bp[i - 1] = (bp[i] * 2) % (cnt + 1);
    if (cnt - 1 != 0)
      bu[i - 1] = (bu[i] * 2) % (cnt - 1);
  }
  for (ll i = n - 1; i >= 0; i--) {
    //  cout<<i<<' '<<"OK"<<endl;
    if (s[i] == '1') {
      vp += bp[i];
      vp %= cnt + 1;
      if (cnt - 1 != 0) {
        vu += bu[i];
        vu %= cnt - 1;
      }
    }
  }

  for (ll i = 0; i < n; i++) {
    if (s[i] == '1') {
      ll c = cnt - 1;
      if (c == 0) {
        cout << c << endl;
        continue;
      }
      ll v = (vu - bu[i] + c) % c;
      cout << func(v) + 1 << endl;
    } else {
      ll c = cnt + 1;
      ll v = (vp + bp[i]) % c;
      cout << func(v) + 1 << endl;
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> mp;
ll inf = 1e9;

ll func(ll v) {
  ll cnt = 0;
  ll ans = 0;
  while (v != 0) {
    cnt = 0;
    for (ll i = 0; i < 64; i++)
      if ((v >> i) & 1)
        cnt++;
    v %= cnt;
    ans++;
  }
  return ans;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  ll cnt = 0;
  for (ll i = 0; i < n; i++) {
    if (s[i] == '1')
      cnt++;
  }

  ll vp = 0, vu = 0;
  vector<ll> bp(n, 1), bu(n, 1);
  for (ll i = n - 1; i >= 1; i--) {
    bp[i - 1] = (bp[i] * 2) % (cnt + 1);
    bu[i - 1] = (bu[i] * 2) % (cnt - 1);
  }
  for (ll i = n - 1; i >= 0; i--) {
    //  cout<<i<<' '<<"OK"<<endl;
    if (s[i] == '1') {
      vp += bp[i];
      vp %= cnt + 1;
      if (cnt - 1 != 0) {
        vu += bu[i];
        vu %= cnt - 1;
      }
    }
  }

  for (ll i = 0; i < n; i++) {
    if (s[i] == '1') {
      ll c = cnt - 1;
      if (c == 0) {
        cout << c << endl;
        continue;
      }
      ll v = (vu - bu[i] + c) % c;
      cout << func(v) + 1 << endl;
    } else {
      ll c = cnt + 1;
      ll v = (vp + bp[i]) % c;
      cout << func(v) + 1 << endl;
    }
  }
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int mod;
ll power(ll a, ll b, ll m) {
  ll ret = 1;
  if (b == 0)
    return ret;
  while (b > 0) {
    if (b % 2 == 1)
      ret = (ret * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ret;
}
int go(int now) {
  int ans = 0;
  while (now > 0) {
    int popcount = 0;
    int temp = now;
    while (temp > 0) {
      if (temp % 2 == 1)
        popcount++;
      temp /= 2;
    }
    now %= popcount;
    ans++;
  }
  return ans;
}
int main() {
  int n, i, j, k, x, y, ans, curr, temp, m;
  int tc;
  cin >> n;
  string s;
  cin >> s;
  ans = 0;
  for (auto x : s) {
    if (x == '1')
      ans++;
  }
  mod = ans;
  int atas = 0, bawah = 0;
  for (i = 0; i < n; i++) {
    curr = s[i] - '0';
    if (curr) {
      if (mod - 1 > 0) {
        bawah += power(2, n - i - 1, mod - 1);
        bawah %= (mod - 1);
      }
      atas += power(2, n - i - 1, mod + 1);
      atas %= (mod + 1);
    }
  }
  for (i = 0; i < n; i++) {
    curr = s[i] - '0';
    int chaeng = 1;
    if (curr) {
      if (mod - 1 == 0) {
        cout << "0" << endl;
        continue;
      }
      int now = bawah;
      now -= power(2, n - i - 1, mod - 1);
      while (now < 0)
        now += (mod - 1);
      chaeng += go(now);
    } else {
      int now = atas;
      now += power(2, n - i - 1, mod + 1);
      now %= (mod + 1);
      chaeng += go(now);
    }
    printf("%d\\n", chaeng);
  }
  return 0;
}


Error: 0

Fixed submission:

/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int mod;
ll power(ll a, ll b, ll m) {
  ll ret = 1;
  if (b == 0)
    return ret;
  while (b > 0) {
    if (b % 2 == 1)
      ret = (ret * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ret;
}
int go(int now) {
  int ans = 0;
  while (now > 0) {
    int popcount = 0;
    int temp = now;
    while (temp > 0) {
      if (temp % 2 == 1)
        popcount++;
      temp /= 2;
    }
    now %= popcount;
    ans++;
  }
  return ans;
}
int main() {
  int n, i, j, k, x, y, ans, curr, temp, m;
  int tc;
  cin >> n;
  string s;
  cin >> s;
  ans = 0;
  for (auto x : s) {
    if (x == '1')
      ans++;
  }
  mod = ans;
  int atas = 0, bawah = 0;
  for (i = 0; i < n; i++) {
    curr = s[i] - '0';
    if (curr) {
      bawah += power(2, n - i - 1, mod - 1);
      bawah %= (mod - 1);
      atas += power(2, n - i - 1, mod + 1);
      atas %= (mod + 1);
    }
  }
  for (i = 0; i < n; i++) {
    curr = s[i] - '0';
    int chaeng = 1;
    if (curr) {
      int now = bawah;
      now -= power(2, n - i - 1, mod - 1);
      while (now < 0)
        now += (mod - 1);
      chaeng += go(now);
    } else {
      int now = atas;
      now += power(2, n - i - 1, mod + 1);
      now %= (mod + 1);
      chaeng += go(now);
    }
    printf("%d\\n", chaeng);
  }
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

long long int mpow(long long int x, int n, int MOD) {
  if (n == 0)
    return 1;

  long long int k = 1;
  while (n > 1) {
    if (n % 2 == 1) {
      k *= x;
      k %= MOD;
    }
    x *= x;
    x %= MOD;
    n /= 2;
  }
  return (k * x) % MOD;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  ll pop = 0;
  rep(i, n) if (s[i] == '1') pop++;

  if (pop == 0) {
    rep(i, n) cout << 1 << "\\n";
    return 0;
  } else if (pop == 1) {
    rep(i, n) {
      if (s[i] == '1') {
        cout << 0 << endl;
      } else {
        if (i == n - 1 || s[n - 1] == '1') {
          cout << 2 << endl;
        } else {
          cout << 1 << endl;
        }
      }
    }
    return 0;
  }

  ll sum1 = 0, sum2 = 0;
  rep(i, n) {
    if (s[i] == '0')
      continue;
    sum1 += mpow(2, n - i - 1, pop + 1);
    sum2 += mpow(2, n - i - 1, pop - 1);
  }
  rep(i, n) {
    if (s[i] == '0') {
      ll MOD = pop + 1;
      ll sum = sum1 + mpow(2, n - i - 1, MOD);
      sum %= MOD;
      int ans = 1;
      while (sum) {
        sum = sum % __builtin_popcount(sum);
        ans++;
      }
      printf("%d\\n", ans);
    } else if (s[i] == '1') {
      ll MOD = pop - 1;
      ll sum = sum2 - mpow(2, n - i - 1, MOD);
      sum %= MOD;
      int ans = 1;
      while (sum) {
        sum = sum % __builtin_popcount(sum);
        ans++;
      }
      printf("%d\\n", ans);
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;

long long int mpow(long long int x, int n, int MOD) {
  if (n == 0)
    return 1;

  long long int k = 1;
  while (n > 1) {
    if (n % 2 == 1) {
      k *= x;
      k %= MOD;
    }
    x *= x;
    x %= MOD;
    n /= 2;
  }
  return (k * x) % MOD;
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  ll pop = 0;
  rep(i, n) if (s[i] == '1') pop++;

  if (pop == 0) {
    rep(i, n) cout << 1 << "\\n";
    return 0;
  }

  ll sum1 = 0, sum2 = 0;
  rep(i, n) {
    if (s[i] == '0')
      continue;
    sum1 += mpow(2, n - i - 1, pop + 1);
    sum2 += mpow(2, n - i - 1, pop - 1);
  }
  rep(i, n) {
    if (s[i] == '0') {
      ll MOD = pop + 1;
      ll sum = sum1 + mpow(2, n - i - 1, MOD);
      sum %= MOD;
      int ans = 1;
      while (sum) {
        sum = sum % __builtin_popcount(sum);
        ans++;
      }
      printf("%d\\n", ans);
    } else if (s[i] == '1') {
      if (pop <= 1) {
        cout << 0 << "\\n";
        continue;
      }
      ll MOD = pop - 1;
      ll sum = sum2 - mpow(2, n - i - 1, MOD);
      sum %= MOD;
      int ans = 1;
      while (sum) {
        sum = sum % __builtin_popcount(sum);
        ans++;
      }
      printf("%d\\n", ans);
    }
  }
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<ll, ll> p;

#define MOD 1000000007

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  string X;
  cin >> X;

  ll mod = 0;

  for (ll i = 0; i < N; i++) {
    if (X[i] == '1')
      mod++;
  }

  ll mod1 = mod + 1LL;
  ll mod2 = mod - 1LL;

  ll c1 = 0;
  ll c2 = 0;

  for (ll i = 0; i < N; i++) {
    if (X[N - i - 1LL] == '0')
      continue;
    c1 += modpow(2LL, i, mod1) % mod1;
    c1 %= mod1;
    if (mod2 <= 0)
      continue;
    c2 += modpow(2LL, i, mod2) % mod2;
    c2 %= mod2;
  }

  for (ll i = 0; i < N; i++) {
    if (X[i] == '0') {
      ll c = c1;
      c += modpow(2LL, N - i - 1LL, mod1) % mod1;
      c %= mod1;
      ll count = 1LL;
      while (c > 0) {
        ll x = __builtin_popcountll(c);
        c %= x;
        count++;
      }
      cout << count << endl;
    } else {
      if (mod2 <= 0) {
        cout << 0 << endl;
        continue;
      }
      ll c = c2;
      c -= modpow(2LL, N - i - 1LL, mod2) % mod2;
      while (c < 0) {
        c += mod2;
      }
      c %= mod2;
      ll count = 1LL;
      while (c > 0) {
        ll x = __builtin_popcountll(c);
        c %= x;
        count++;
      }
      cout << count << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<ll, ll> p;

#define MOD 1000000007

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  string X;
  cin >> X;

  ll mod = 0;

  for (int i = 0; i < N; i++) {
    if (X[i] == '1')
      mod++;
  }

  ll mod1 = mod + 1LL;
  ll mod2 = mod - 1LL;

  ll c1 = 0;
  ll c2 = 0;

  ll b = 1LL;

  for (ll i = 0; i < N; i++) {
    if (X[N - i - 1LL] == '0')
      continue;
    c1 += modpow(2LL, i, mod1) % mod1;
    c1 %= mod1;
    c2 += modpow(2LL, i, mod2) % mod2;
    c2 %= mod2;
  }

  for (ll i = 0; i < N; i++) {
    if (X[i] == '0') {
      ll c = c1;
      c += modpow(2LL, N - i - 1LL, mod1) % mod1;
      c %= mod1;
      ll count = 1LL;
      while (c > 0) {
        ll x = __builtin_popcountll(c);
        c %= x;
        count++;
      }
      cout << count << endl;
    } else {
      ll c = c2;
      c -= modpow(2LL, N - i - 1LL, mod2) % mod2;
      c += mod2;
      c %= mod2;
      ll count = 1LL;
      while (c > 0) {
        ll x = __builtin_popcountll(c);
        c %= x;
        count++;
      }
      cout << count << endl;
    }
  }
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll a, ll b, ll mod) {
  a %= mod;
  ll res = 1;
  while (b > 0) {
    if (b % 2)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
ll getop(ll x, ll mod) {
  if (x != 0)
    return 1 + getop(x % mod, __builtin_popcountll(x % mod));
  else
    return 0;
}
void solve() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll mod = 0;
  for (ll i = n - 1; i >= 0; i--) {
    if (s[i] == '1')
      mod++;
  }
  ll umod = 0, lmod = 0;
  ll um = mod + 1, lm = mod - 1;
  for (ll i = 0, j = n - 1; i < n; i++, j--) {
    if (s[i] == '1') {
      umod = (umod + power(2, j, um)) % um;
      if (mod > 1)
        lmod = (lmod + power(2, j, lm)) % lm;
    }
  }
  // cout<<um<<" "<<lm<<"\\n";
  // cout<<umod<<" "<<lmod<<"\\n";
  for (ll i = 0, j = n - 1; i < n; i++, j--) {
    if (s[i] == '1') {
      if (mod == 1) {
        cout << 0 << "\\n";
        continue;
      }
      ll x = (lmod - power(2, j, lm) + lm) % lm;
      cout << 1 + getop(x, __builtin_popcountll(x)) << "\\n";
    } else {
      ll x = (umod + power(2, j, um) + um) % um;
      cout << 1 + getop(x, __builtin_popcountll(x)) << "\\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll a, ll b, ll mod) {
  a %= mod;
  ll res = 1;
  while (b > 0) {
    if (b % 2)
      res = (res * a) % mod;
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
ll getop(ll x, ll mod) {
  if (x != 0)
    return 1 + getop(x % mod, __builtin_popcountll(x % mod));
  else
    return 0;
}
void solve() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll mod = 0;
  for (ll i = n - 1; i >= 0; i--) {
    if (s[i] == '1')
      mod++;
  }
  ll umod = 0, lmod = 0;
  ll um = mod + 1, lm = mod - 1;
  for (ll i = 0, j = n - 1; i < n; i++, j--) {
    if (s[i] == '1') {
      umod = (umod + power(2, j, um)) % um;
      if (mod != 0)
        lmod = (lmod + power(2, j, lm)) % lm;
    }
  }
  // cout<<um<<" "<<lm<<"\\n";
  // cout<<umod<<" "<<lmod<<"\\n";
  for (ll i = 0, j = n - 1; i < n; i++, j--) {
    if (s[i] == '1') {
      ll x = (lmod - power(2, j, lm) + lm) % lm;
      cout << 1 + getop(x, __builtin_popcountll(x)) << "\\n";
    } else {
      ll x = (umod + power(2, j, um) + um) % um;
      cout << 1 + getop(x, __builtin_popcountll(x)) << "\\n";
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int popcount(int x) {
  vector<int> a;
  while (x != 0) {
    a.emplace_back(x % 2);
    x /= 2;
  }
  int res = 0;
  for (auto p : a) {
    if (p == 1) {
      res++;
    }
  }

  return res;
}

int f(int x) {
  if (x == 0) {
    return 1;
  }
  int pcnt = popcount(x);
  return f(x % pcnt) + 1;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    X[i] = (int)S[i] - (int)'0';
  }

  long long one = 0;
  for (int i = 0; i < N; i++) {
    one += X[i];
  }

  vector<int> m(2, 0);

  for (int i = 0; i < N; i++) {
    m[0] = (m[0] * 2) % (one + 1);
    m[0] += X[i];
  }
  if (one > 1) {
    for (int i = 0; i < N; i++) {
      m[1] = (m[1] * 2) % (one - 1);
      m[1] += X[i];
    }
  }
  // cout<<"m:"<<m[0]<<" "<<m[1]<<endl;

  vector<int> ans(N);
  int k0, k1;
  k0 = 1;
  k1 = 1;
  for (int i = N - 1; i >= 0; i--) {
    if (X[i] == 0) {
      ans[i] = f((m[0] + k0) % (one + 1));

    } else {
      if (one == 1) {
        ans[i] = 0;
      } else {
        ans[i] = f((m[1] - k1 + (one - 1)) % (one - 1));
      }
    }

    k0 = k0 * 2 % (one + 1);
    if (one > 1) {
      k1 = k1 * 2 % (one - 1);
    }
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int popcount(int x) {
  vector<int> a;
  while (x != 0) {
    a.emplace_back(x % 2);
    x /= 2;
  }
  int res = 0;
  for (auto p : a) {
    if (p == 1) {
      res++;
    }
  }

  return res;
}

int f(int x) {
  if (x == 0) {
    return 1;
  }
  int pcnt = popcount(x);
  return f(x % pcnt) + 1;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  vector<int> X(N);
  for (int i = 0; i < N; i++) {
    X[i] = (int)S[i] - (int)'0';
  }

  long long one = 0;
  for (int i = 0; i < N; i++) {
    one += X[i];
  }

  vector<int> m(2, 0);

  for (int i = 0; i < N; i++) {
    m[0] = (m[0] * 2) % (one + 1);
    m[0] += X[i];
  }
  if (one > 1) {
    for (int i = 0; i < N; i++) {
      m[1] = (m[1] * 2) % (one - 1);
      m[1] += X[i];
    }
  }
  // cout<<"m:"<<m[0]<<" "<<m[1]<<endl;

  vector<int> ans(N);
  int k0, k1;
  k0 = 1;
  k1 = 1;
  for (int i = N - 1; i >= 0; i--) {
    if (X[i] == 0) {
      ans[i] = f((m[0] + k0) % (one + 1));

    } else {
      if (one == 1) {
        ans[i] = 0;
      } else {
        ans[i] = f((m[1] - k1 + (one - 1)) % (one - 1));
      }
    }

    k0 = k0 * 2 % (one + 1);
    if (one != 0) {
      k1 = k1 * 2 % (one - 1);
    }
  }

  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define reps(i, a, b) for (int i = a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
  int n;
  string x;
  cin >> n >> x;
  int base_pc = 0;
  vector<int> f(220000, 0);
  vector<int> pcs(220000, 0);
  reps(i, 1, n) {
    pcs[i] = pcs[i / 2] + i % 2;
    f[i] = f[i % pcs[i]] + 1;
  }
  rep(i, n) if (x[i] == '1') base_pc++;
  int one_pc = base_pc - 1;
  int zero_pc = base_pc + 1;
  int one_mod = 0;
  int zero_mod = 0;
  rep(i, n) {
    if (one_pc != 0) {
      one_mod = one_mod * 2 + (x[i] - '0');
      one_mod %= one_pc;
    }
    zero_mod = zero_mod * 2 + (x[i] - '0');
    zero_mod %= zero_pc;
  }
  vector<int> one_pow2_mod(220000, 1);
  vector<int> zero_pow2_mod(220000, 1);
  reps(i, 1, 220000) {
    if (one_pc != 0) {
      one_pow2_mod[i] = one_pow2_mod[i - 1] * 2 % one_pc;
    }
    zero_pow2_mod[i] = zero_pow2_mod[i - 1] * 2 % zero_pc;
  }
  rep(i, n) {
    if (x[i] == '1') {
      if (one_pc == 0) {
        cout << 0 << endl;
        continue;
      }
      int one_ans = one_mod;
      one_ans -= one_pow2_mod[n - 1 - i];
      one_ans += one_pc;
      cout << f[one_ans % one_pc] + 1 << endl;
    } else {
      int zero_ans = zero_mod;
      zero_ans += zero_pow2_mod[n - 1 - i];
      cout << f[zero_ans % zero_pc] + 1 << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
ll n;
string x;
vector<bool> seq;
vector<ll> vec(1, -1);

int main() {
  cin >> n >> x;
  seq.resize(n);
  vec.resize(1e6 + 1, -1);
  ll num = 0;
  rep(i, n) {
    if (x[i] == '1') {
      num += pow(2, n - i - 1);
    }
  }

  rep(i, n) {
    ll tmp = num;
    if (x[i] == '0') {
      tmp += pow(2, n - i - 1);
    } else {
      tmp -= pow(2, n - i - 1);
    }
    ll ans = 0;
    while (tmp) {
      // cout << bin(tmp) << endl;
      tmp %= __builtin_popcount(tmp);
      ans++;
    }
    cout << ans << endl;
  }

  return 0;
}