Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
const ll INF = 1e18 + 18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  vector<ll> Cou(200010, 0);
  for (ll i = 1; i <= N; i++) {
    ll j = i;
    ll cou = 0;
    while (j > 0) {
      if (j % 2)
        cou++;
      j /= 2;
    }
    ll k = i % cou;
    Cou[i] = Cou[k] + 1;
  }
  ll Cnt = 0;
  rep(i, N) {
    if (S.at(i) == '1')
      Cnt++;
  }
  if (Cnt == 0) {
    rep(i, N) cout << 1 << endl;
    return 0;
  }
  if (Cnt == 1) {
    if (S.at(N - 1) == '1') {
      rep(i, N - 1) cout << 2 << endl;
      cout << 0 << endl;
      return 0;
    } else {
      rep(i, N - 1) {
        if (S.at(i) == '1') {
          cout << 0 << endl;
        } else {
          cout << 1 << endl;
        }
      }
      cout << 2 << endl;
      return 0;
    }
  }
  ll Inc = 0;
  ll Dec = 0;
  ll In = 1;
  ll Dn = 1;
  vector<ll> InV(N + 10, 0);
  vector<ll> DcV(N + 10, 0);
  rep(i, N) {
    if (S.at(N - 1 - i) == '1') {
      Inc += In;
      Dec += Dn;
    }
    InV[N - 1 - i] = In;
    DcV[N - 1 - i] = Dn;
    In *= 2;
    In %= (Cnt + 1);
    Dn *= 2;
    Dn %= (Cnt - 1);
    Inc %= (Cnt + 1);
    Dec %= (Cnt - 1);
  }

  // cout<<Cnt<<endl;
  // rep(i, N){
  // cout<<InV[i]<<" "<<DcV[i]<<endl;
  //}
  // cout<<Inc<<endl;
  // cout<<Dec<<endl;
  // cout<<endl;
  rep(i, N) {
    if (S.at(i) == '1') {
      ll Num = Dec - DcV[i] + (Cnt - 1);
      Num %= (Cnt - 1);
      cout << Cou[Num] + 1 << endl;
    } else {
      ll Num = Inc + InV[i];
      Num %= (Cnt + 1);
      cout << Cou[Num] + 1 << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a) (a).begin(), (a).end()
const ll INF = 1e18 + 18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;

int main() {
  ll N;
  cin >> N;
  string S;
  cin >> S;
  vector<ll> Cou(200010, 0);
  for (ll i = 1; i <= N; i++) {
    ll j = i;
    ll cou = 0;
    while (j > 0) {
      if (j % 2)
        cou++;
      j /= 2;
    }
    ll k = i % cou;
    Cou[i] = Cou[k] + 1;
  }
  ll Cnt = 0;
  rep(i, N) {
    if (S.at(i) == '1')
      Cnt++;
  }
  if (Cnt == 0) {
    rep(i, N) cout << 1 << endl;
    return 0;
  }
  if (Cnt == 1) {
    return -1;
    if (S.at(N - 1) == '1') {
      rep(i, N - 1) cout << 2 << endl;
      cout << 0 << endl;
      return 0;
    } else {
      rep(i, N) {
        if (S.at(i) == '1') {
          cout << 0 << endl;
        } else {
          cout << 1 << endl;
        }
      }
      return 0;
    }
  }
  ll Inc = 0;
  ll Dec = 0;
  ll In = 1;
  ll Dn = 1;
  vector<ll> InV(N + 10, 0);
  vector<ll> DcV(N + 10, 0);
  rep(i, N) {
    if (S.at(N - 1 - i) == '1') {
      Inc += In;
      Dec += Dn;
    }
    InV[N - 1 - i] = In;
    DcV[N - 1 - i] = Dn;
    In *= 2;
    In %= (Cnt + 1);
    Dn *= 2;
    Dn %= (Cnt - 1);
    Inc %= (Cnt + 1);
    Dec %= (Cnt - 1);
  }

  // cout<<Cnt<<endl;
  // rep(i, N){
  // cout<<InV[i]<<" "<<DcV[i]<<endl;
  //}
  // cout<<Inc<<endl;
  // cout<<Dec<<endl;
  // cout<<endl;
  rep(i, N) {
    if (S.at(i) == '1') {
      ll Num = Dec - DcV[i] + (Cnt - 1);
      Num %= (Cnt - 1);
      cout << Cou[Num] + 1 << endl;
    } else {
      ll Num = Inc + InV[i];
      Num %= (Cnt + 1);
      cout << Cou[Num] + 1 << endl;
    }
  }
}