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

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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() {
  int N;
  cin >> N;
  string x;
  cin >> x;
  vector<int> bi(N);
  int cnt = 0;
  rep(i, N) {
    bi[i] = x[i] - '0';
    if (bi[i] == 1)
      cnt++;
  }

  ll MOD1 = cnt - 1, MOD2 = cnt + 1;
  ll can1 = 0, can2 = 0, exp = 0;

  for (int i = N - 1; i > -1; i--) {
    if (MOD1 > 0)
      can1 += modpow(2, exp, MOD1) * bi[i] % MOD1;
    can2 += modpow(2, exp, MOD2) * bi[i] % MOD2;
    exp++;
  }

  for (int i = 0; i < N; i++) {
    bool judge = 0;
    ll first;
    if (bi[i] == 0) {
      first = (can2 + modpow(2, N - 1 - i, MOD2)) % MOD2;
    } else {
      if (MOD1 <= 0)
        first = 0, judge = 1;
      else
        first = (can1 - modpow(2, N - 1 - i, MOD1)) % MOD1;
    }

    int ans;
    if (judge)
      ans = 0;
    else
      ans = 1;
    while (first != 0) {
      first %= __builtin_popcount(first);
      ans++;
    }
    cout << ans << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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() {
  int N;
  cin >> N;
  string x;
  cin >> x;
  vector<int> bi(N);
  int cnt = 0;
  rep(i, N) {
    bi[i] = x[i] - '0';
    if (bi[i] == 1)
      cnt++;
  }

  ll MOD1 = cnt - 1, MOD2 = cnt + 1;
  ll can1 = 0, can2 = 0, exp = 0;

  for (int i = N - 1; i > -1; i--) {
    if (MOD1 > 0)
      can1 += modpow(2, exp, MOD1) * bi[i] % MOD1;
    can2 += modpow(2, exp, MOD2) * bi[i] % MOD2;
    exp++;
  }

  for (int i = 0; i < N; i++) {
    ll first;
    if (bi[i] == 0) {
      first = (can2 + modpow(2, N - 1 - i, MOD2)) % MOD2;
    } else {
      if (MOD1 > 0)
        first = 0;
      first = (can1 - modpow(2, N - 1 - i, MOD1)) % MOD1;
    }

    int ans = 1;
    while (first != 0) {
      first %= __builtin_popcount(first);
      ans++;
    }
    cout << ans << endl;
  }
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\\n"

int solve(int n) {
  int ans = 0;
  while (n) {
    int pop = __builtin_popcount(n);
    n %= pop;
    ans++;
  }
  return ans;
}
const int N = 2e5;
int conf[1 + N];
int n;
int getReminder(int d) {
  if (d == 0)
    return -1;
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = (ans * 2 + conf[i]) % d;
  return ans;
}

int lgput(int a, int b, int d) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1ll * ans * a % d;
    a = 1ll * a * a % d;
    b /= 2;
  }
  return ans;
}

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

  cin >> n;
  string x;
  cin >> x;
  x = " " + x;
  int nr1 = 0;
  for (int i = 1; i <= n; i++) {
    conf[i] = x[i] - '0';
    nr1 += conf[i];
  }
  int reminderPlus = getReminder(nr1 + 1);
  int reminderMinus = getReminder(nr1 - 1);
  for (int i = 1; i <= n; i++) {
    if (conf[i] == 0) {
      /// +
      int reminder = (reminderPlus + lgput(2, n - i, nr1 + 1)) % (nr1 + 1);
      cout << solve(reminder) + 1 << "\\n";
    } else {
      /// -
      if (reminderMinus == -1)
        cout << 0 << "\\n";
      else {
        int reminder =
            (reminderMinus - lgput(2, n - i, nr1 - 1) + nr1 - 1) % (nr1 - 1);
        cout << solve(reminder) + 1 << "\\n";
      }
    }
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define pb push_back
#define dbg(x) cerr << #x << " " << x << "\\n"

int solve(int n) {
  int ans = 0;
  while (n) {
    int pop = __builtin_popcount(n);
    n %= pop;
    ans++;
  }
  return ans;
}
const int N = 2e5;
int conf[1 + N];
int n;
int getReminder(int d) {
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = (ans * 2 + conf[i]) % d;
  return ans;
}

int lgput(int a, int b, int d) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = 1ll * ans * a % d;
    a = 1ll * a * a % d;
    b /= 2;
  }
  return ans;
}

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

  cin >> n;
  string x;
  cin >> x;
  x = " " + x;
  int nr1 = 0;
  for (int i = 1; i <= n; i++) {
    conf[i] = x[i] - '0';
    nr1 += conf[i];
  }
  int reminderPlus = getReminder(nr1 + 1);
  int reminderMinus = getReminder(nr1 - 1);
  for (int i = 1; i <= n; i++) {
    if (conf[i] == 0) {
      /// +
      int reminder = (reminderPlus + lgput(2, n - i, nr1 + 1)) % (nr1 + 1);
      cout << solve(reminder) + 1 << "\\n";
    } else {
      /// -
      int reminder =
          (reminderMinus - lgput(2, n - i, nr1 - 1) + nr1 - 1) % (nr1 - 1);
      cout << solve(reminder) + 1 << "\\n";
    }
  }
  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 < (n); i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9 + 7;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int mod = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == '1')
      mod++;
  int mod1 = mod + 1, mod2 = mod - 1;
  ll x1 = 0, x2 = 0;
  vector<ll> cur1(n, 1), cur2(n, 1);

  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      if (mod1 > 0)
        (x1 += cur1[i]) %= mod1;
      if (mod2 > 0)
        (x2 += cur2[i]) %= mod2;
    }
    if (i != 0) {
      if (mod1 > 0)
        cur1[i - 1] = (cur1[i] * 2) % mod1;
      if (mod2 > 0)
        cur2[i - 1] = (cur2[i] * 2) % mod2;
    }
  }

  vector<int> cnt(200001, 0);
  auto calc = [&](int x) {
    int ret = 0;
    while (x != 0) {
      int tmp = __builtin_popcount(x);
      x = x % tmp;
      ret++;
    }
    return ret;
  };
  for (int i = 0; i <= 200000; i++) {
    cnt[i] = calc(i);
  }

  for (int i = 0; i < n; i++) {
    ll res = -1;
    ll cur = 0;
    int c = 0;
    if (s[i] == '1') {
      if (mod2 > 0) {
        res = x2;
        cur = cur2[i];
        (res = res - cur + mod2) %= mod2;
        c = 1;
      }
    } else {
      if (mod1 > 0) {
        res = x1;
        cur = cur1[i];
        (res += cur) %= mod1;
        c = 1;
      }
    }
    int ans = 0;
    if (res != -1)
      ans += cnt[res];
    cout << ans + c << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9 + 7;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int mod = 0;
  for (int i = 0; i < n; i++)
    if (s[i] == '1')
      mod++;
  int mod1 = mod + 1, mod2 = mod - 1;
  ll x1 = 0, x2 = 0;
  vector<ll> cur1(n, 1), cur2(n, 1);
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == '1') {
      (x1 += cur1[i]) %= mod1;
      (x2 += cur2[i]) %= mod2;
    }
    if (i != 0) {
      cur1[i - 1] = (cur1[i] * 2) % mod1;
      cur2[i - 1] = (cur2[i] * 2) % mod2;
    }
  }

  vector<int> cnt(200001, 0);
  auto calc = [&](int x) {
    int ret = 0;
    while (x != 0) {
      int tmp = __builtin_popcount(x);
      x = x % tmp;
      ret++;
    }
    return ret;
  };
  for (int i = 0; i <= 200000; i++) {
    cnt[i] = calc(i);
  }

  for (int i = 0; i < n; i++) {
    ll res = 0;
    ll cur = 0;
    if (s[i] == '1') {
      res = x2;
      cur = cur2[i];
      (res = res - cur + mod2) %= mod2;
    } else {
      res = x1;
      cur = cur1[i];
      (res += cur) %= mod1;
    }
    cout << cnt[res] + 1 << endl;
  }
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 200010;
int n, pw2u[N], pw2d[N];

int subtract(int a, int b, int mod) {
  return (a - b) % mod + (a >= b ? 0 : mod);
}

int calc(int a) {
  int res = 0;
  while (a) {
    a %= __builtin_popcount(a);
    res++;
  }
  return res;
}

int main() {
  string x;
  cin >> n >> x;
  int mod = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] == '1')
      mod++;
  }
  int up = 0, down = 0;
  for (int i = 0; i < n; i++) {
    up = (up * 2) % (mod + 1);
    down = (down * 2) % max(mod - 1, 1);
    if (x[i] == '1')
      up++, down++;
  }
  pw2u[0] = pw2d[0] = 1;
  for (int i = 1; i <= n; i++) {
    pw2u[i] = (2 * pw2u[i - 1]) % (mod + 1);
    pw2d[i] = (2 * pw2d[i - 1]) % max(mod - 1, 1);
  }
  for (int i = 0; i < n; i++) {
    if (x[i] == '1')
      printf("%d\\n", calc(subtract(down, pw2d[n - i - 1], max(mod - 1, 1))) +
                         (mod > 1));
    else
      printf("%d\\n", calc((up + pw2u[n - i - 1]) % (mod + 1)) + 1);
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N = 100'010;
string x;
int n, pw2u[N], pw2d[N];

int subtract(int a, int b, int mod) {
  return (a - b) % mod + (a >= b ? 0 : mod);
}

int calc(int a) {
  int res = 0;
  while (a) {
    a %= __builtin_popcount(a);
    res++;
  }
  return res;
}

int main() {
  cin >> n >> x;
  int mod = 0;
  for (int i = 0; i < n; i++) {
    if (x[i] == '1')
      mod++;
  }
  int up = 0, down = 0;
  for (int i = 0; i < n; i++) {
    up = (up * 2) % (mod + 1);
    down = (down * 2) % max(mod - 1, 1);
    if (x[i] == '1')
      up++, down++;
  }
  pw2u[0] = pw2d[0] = 1;
  for (int i = 1; i <= n; i++) {
    pw2u[i] = (2 * pw2u[i - 1]) % (mod + 1);
    pw2d[i] = (2 * pw2d[i - 1]) % max(mod - 1, 1);
  }
  for (int i = 0; i < n; i++) {
    if (x[i] == '1')
      printf("%d\\n", calc(subtract(down, pw2d[n - i - 1], max(mod - 1, 1))) +
                         (mod > 1));
    else
      printf("%d\\n", calc((up + pw2u[n - i - 1]) % (mod + 1)) + 1);
  }
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

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

const int mxN = 2e5;

int modpow(int base, int power, int mod) {
  int res = 1;
  while (power) {
    if (power % 2) {
      res = (1ll * res * base) % mod;
    }
    power /= 2;
    base = (1ll * base * base) % mod;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<int> dp(mxN + 1);
  for (int i = 1; i <= mxN; i++) {
    int count = 0;
    for (int bit = 1; bit <= mxN; bit *= 2) {
      if (i & bit) {
        count++;
      }
    }
    dp[i] = dp[i % count] + 1;
  }
  int n;
  string s;
  cin >> n >> s;
  int pc = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      pc++;
    }
  }
  int c1 = 0, c2 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      if (pc >= 2) {
        c1 += modpow(2, n - 1 - i, pc - 1);
        c1 %= pc - 1;
      }
      c2 += modpow(2, n - 1 - i, pc + 1);
      c2 %= pc + 1;
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      int next = (c2 + modpow(2, n - 1 - i, pc + 1)) % (pc + 1);
      cout << dp[next] + 1 << '\\n';
    } else {
      if (pc >= 2) {
        int next = ((c1 - modpow(2, n - 1 - i, pc - 1)) % (pc - 1) + (pc - 1)) %
                   (pc - 1);
        cout << dp[next] + 1 << '\\n';
      } else {
        cout << "0\\n";
      }
    }
  }
}


Error: 0

Fixed submission:

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

const int mxN = 2e5;

int modpow(int base, int power, int mod) {
  int res = 1;
  while (power) {
    if (power % 2) {
      res = (1ll * res * base) % mod;
    }
    power /= 2;
    base = (1ll * base * base) % mod;
  }
  return res;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<int> dp(mxN + 1);
  for (int i = 1; i <= mxN; i++) {
    int count = 0;
    for (int bit = 1; bit <= mxN; bit *= 2) {
      if (i & bit) {
        count++;
      }
    }
    dp[i] = dp[i % count] + 1;
  }
  int n;
  string s;
  cin >> n >> s;
  int pc = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      pc++;
    }
  }
  int c1 = 0, c2 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') {
      if (pc >= 2) {
        c1 += modpow(2, n - 1 - i, pc - 1);
      }
      c2 += modpow(2, n - 1 - i, pc + 1);
    }
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0') {
      int next = (c2 + modpow(2, n - 1 - i, pc + 1)) % (pc + 1);
      cout << dp[next] + 1 << '\\n';
    } else {
      if (pc >= 2) {
        int next = ((c1 - modpow(2, n - 1 - i, pc - 1)) % (pc - 1) + (pc - 1)) %
                   (pc - 1);
        cout << dp[next] + 1 << '\\n';
      } else {
        cout << "0\\n";
      }
    }
  }
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define END '\\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr << x << END;
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, b, a) for (int i = (b); i > (a); --i)
const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int inf = 92233720000000000ll;
string s;
int n;
int power(int base, int n, int m) {
  if (n == 0)
    return 1;
  if (n & 1) {
    int y = power(base, n - 1, m);
    return (y * base) % m;
  } else {
    int y = power(base, n / 2, m);
    return (y * y) % m;
  }
}
int calc(int x) {
  int steps = 0;
  while (x != 0) {
    int one = __builtin_popcount(x);
    x %= one;
    steps++;
  }
  return steps;
}
void solve() {
  cin >> n >> s;
  int one = 0;
  loop(i, 0, n) one += (s[i] == '1');
  int lo = 0, hi = 0;
  loop(i, 0, n) if (s[i] == '1') {
    if (one > 1)
      (lo += power(2ll, n - i - 1, one - 1)) %= (one - 1);
    (hi += power(2ll, n - i - 1, one + 1)) %= (one + 1);
  }
  loop(i, 0, n) {
    int ans, num;
    if (s[i] == '1') {
      if (one == 1)
        ans = 0;
      else {
        num = lo;
        int now = power(2, n - i - 1, one - 1);
        num = (num - now + one - 1) % (one - 1);
        ans = calc(num) + 1;
      }
    } else {
      num = hi;
      int now = power(2, n - i - 1, one + 1);
      num = (num + now) % (one + 1);
      ans = calc(num) + 1;
    }
    cout << ans << END;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  // cerr<<1.0*clock();

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define END '\\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define trace(x) cerr << x << END;
#define loop(i, a, b) for (int i = (a); i < (b); i++)
#define loopb(i, b, a) for (int i = (b); i > (a); --i)
const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int inf = 9223372036854775807ll;
int str_modulo(string s, int k) {
  int ans = 0;
  int n = s.size();
  loop(i, 0, n) {
    int now = ((s[i] - '0') * (1 << n - i - 1)) % k;
    ans = (ans + now) % k;
  }
  return ans;
}
int calc(string s, int k) {
  int m = str_modulo(s, k);
  int steps = 1;
  while (m > 0) {
    int popc = __builtin_popcount(m);
    m = m % popc;
    steps++;
  }
  return steps;
}
void solve() {
  int n;
  string x;
  cin >> n >> x;
  int one = 0;
  loop(i, 0, n) one += (x[i] == '1');
  loop(i, 0, n) {
    string s = x;
    int popc = one;
    if (x[i] == '1') {
      popc--;
      s[i] = '0';
    } else {
      popc++;
      s[i] = '1';
    }
    int ans = calc(s, popc);
    cout << ans << END;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  // cerr<<END<<1.0*clock();
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bitset>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>

#define MAX_N 200005

typedef long long ll;

using namespace std;

int N;
string X;

map<ll, ll> memo;

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;
}

ll solve(ll x) {
  if (memo.count(x) > 0) {
    return memo[x];
  }

  int mod = 0;
  for (int i = 1; i < MAX_N; i = (i << 1)) {
    if (x & i)
      mod++;
  }
  if (mod == 0) {
    return memo[x] = 0;
  }

  return memo[x] = 1 + solve(x % mod);
}

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

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

  ll baseg = 0, basel = 0;
  for (int i = 0; i < N; i++) {
    char c = X[i];
    if (c == '1') {
      baseg = (baseg + modpow(2, N - 1 - i, mod + 1)) % (mod + 1);
      if (mod - 1 != 0) {
        basel = (basel + modpow(2, N - 1 - i, mod - 1)) % (mod - 1);
      }
    }
  }

  for (int i = 0; i < N; i++) {
    ll next;
    if (X[i] == '1') {
      int m = mod - 1;

      if (m == 0) {
        printf("0\\n");
      } else {
        next = (basel - modpow(2, N - 1 - i, m) + m) % m;
        printf("%lld\\n", m == 0 ? 0 : (1 + solve(next)));
      }
    } else {
      int m = mod + 1;
      next = (baseg + modpow(2, N - 1 - i, m)) % m;
      printf("%lld\\n", m == 0 ? 0 : (1 + solve(next)));
    }
  }
}


Error: 0

Fixed submission:

#include <bitset>
#include <cstdio>
#include <iostream>
#include <map>
#include <sstream>
#include <string>

#define MAX_N 200005

typedef long long ll;

using namespace std;

int N;
string X;

map<ll, ll> memo;

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;
}

ll solve(ll x) {
  if (memo.count(x) > 0) {
    return memo[x];
  }

  int mod = 0;
  for (int i = 1; i < MAX_N; i = (i << 1)) {
    if (x & i)
      mod++;
  }
  if (mod == 0) {
    return memo[x] = 0;
  }

  return memo[x] = 1 + solve(x % mod);
}

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

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

  ll baseg = 0, basel = 0;
  for (int i = 0; i < N; i++) {
    char c = X[i];
    if (c == '1') {
      baseg = (baseg + modpow(2, N - 1 - i, mod + 1)) % (mod + 1);
      basel = (basel + modpow(2, N - 1 - i, mod - 1)) % (mod - 1);
    }
  }

  for (int i = 0; i < N; i++) {
    ll next;
    if (X[i] == '1') {
      next = (basel - modpow(2, N - 1 - i, mod - 1) + (mod - 1)) % (mod - 1);
    } else {
      next = (baseg + modpow(2, N - 1 - i, mod + 1)) % (mod + 1);
    }

    if (mod == 0) {
      printf("0\\n");
    } else {
      printf("%lld\\n", 1 + solve(next));
    }
  }
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int num = 0;
  for (int i = 0; i < N; i++)
    if (s[i] == '1')
      num++;
  int amari[200000][2];
  amari[0][0] = 1;
  amari[0][1] = 1;
  int judge[2] = {0, 0};
  for (int i = 1; i < N; i++) {
    if (num != 1)
      amari[i][0] = (amari[i - 1][0] * 2) % (num - 1);
    amari[i][1] = (amari[i - 1][1] * 2) % (num + 1);
  }
  for (int i = 0; i < N; i++) {
    if (s[N - i - 1] == '1') {
      if (num != 1)
        judge[0] = (judge[0] + amari[i][0]) % (num - 1);
      judge[1] = (judge[1] + amari[i][1]) % (num + 1);
    }
  }
  for (int i = 0; i < N; i++) {
    int k;
    if (s[i] == '1') {
      if (num != 1)
        k = (judge[0] + num - 1 - amari[N - i - 1][0]) % (num - 1);
      else
        k = -1;
    } else
      k = (judge[1] + amari[N - i - 1][1]) % (num + 1);
    if (k != -1) {
      int answer = 1;
      while (k > 0) {
        int l = 0;
        long long zwei = 1;
        while (zwei <= k) {
          if ((k % (zwei * 2)) / zwei == 1)
            l++;
          zwei *= 2;
        }
        k %= l;
        answer++;
      }
      cout << answer << endl;
    }
    if (k == -1)
      cout << 0 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int N;
  cin >> N;
  string s;
  cin >> s;
  int num = 0;
  for (int i = N - 1; i >= 0; i--)
    if (s[i] == '1')
      num++;
  int amari[200000][2];
  amari[0][0] = 1;
  amari[0][1] = 1;
  int judge[2] = {0, 0};
  for (int i = 1; i < N; i++) {
    amari[i][0] = (amari[i - 1][0] * 2) % (num - 1);
    amari[i][1] = (amari[i - 1][1] * 2) % (num + 1);
  }
  for (int i = 0; i < N; i++) {
    if (s[N - i - 1] == '1') {
      judge[0] = (judge[0] + amari[i][0]) % (num - 1);
      judge[1] = (judge[1] + amari[i][1]) % (num + 1);
    }
  }
  for (int i = 0; i < N; i++) {
    int k;
    if (s[i] == '1')
      k = (judge[0] + num - 1 - amari[N - i - 1][0]) % (num - 1);
    else
      k = (judge[1] + amari[N - i - 1][1]) % (num + 1);
    int answer = 1;
    while (k > 0) {
      int l = 0;
      long long zwei = 1;
      while (zwei <= k) {
        if ((k % (zwei * 2)) / zwei == 1)
          l++;
        zwei *= 2;
      }
      k %= l;
      answer++;
    }
    cout << answer << endl;
  }

  return 0;
}