alexjercan/bugnet huggingface dataset:
Problem p02608 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip> // std::setprecision
#include <iostream>
#include <map>
#include <numeric> // std::accumulate
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
#define ll long long
#define all(v) (v).begin(), (v).end()
#define v vector<int>
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define ii pair<ll, ll>
#define sz(v) ((int)((v).size()))
#define lp(i, a, b) for (int i = a; i < b; i++)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define EPS 1e-9
#define endl "\\n"
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
const double PI = 3.14159265358979323846;

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}

int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
long long power(ll n, ll k) {
  if (k == 0)
    return 1;
  ll sq = (power(n, k / 2));
  sq = (sq * sq);
  if (k % 2 == 1)
    sq = (sq * n);
  return sq;
}
bool isPrime(int n) {
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;

  if (n % 2 == 0 || n % 3 == 0)
    return false;

  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;

  return true;
}
string to_binary(int x) {
  string s;
  while (x > 0) {
    s += (x % 2 ? '1' : '0');
    x /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
bool isPerfect(ll x) {
  if (x < 1)
    return false;
  ll root(round(sqrt(x)));
  return x == root * root;
}
void solve() {
  int n;
  cin >> n;

  v ans(10050 + 3);
  for (int i = 1; i <= 105; i++) {
    int x = 0;
    for (int j = 1; j <= 105; j++) {
      for (int k = 1; k <= 105; k++) {
        x = i * i + j * j + k * k + i * j + j * k + k * i;
        if (x < 10050)
          ans[x]++;
      }
    }
  }

  for (int i = 1; i <= n; i++)
    cout << ans[i] << "\\n";
}

int main() {
  IOS;

  int tt;
  tt = 1;
  // cin >> tt;
  while (tt--) {
    solve();
  }
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n, cnt = 0;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      for (int k = 1; k <= i; k++) {
        for (int l = 1; l <= i; l++) {
          if ((j + l) * (j + l) + (j + k) * (j + k) + (l + k) * (l + k) ==
              2 * i) {
            cnt++;
          }
        }
      }
    }
    cout << cnt << "\\n";
    cnt = 0;
  }
}
Problem p02608 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int f(int x, int y, int z) {
  return (x * x) + (y * y) + (z * z) + (x * y) + (y * z) + (z * x);
}

int main() {
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    arr[i] = 0;
  for (int x = 1; (x * x) <= n; x++) {
    for (int y = 1; ((x * x) + (y * y) + (x * y)) <= n; y++) {
      for (int z = 1; f(x, y, z) <= n; z++) {
        int result = f(x, y, z);
        if (result <= n)
          arr[result - 1]++;
      }
    }
  }
  for (int i = 0; i < n; i++)
    cout << arr[i] << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
void n(int n) {
  for (int i = 1; i <= n; ++i) {
    int ans = 0;
    for (int x = 1; x <= i / 5; ++x) {
      int y = x;
      for (int z = 1; z <= i / 5; ++z) {
        if (x * x + y * y + z * z + x * y + y * z + x * z == i) {
          ans++;
          if (z != x)
            ans += 2;
        }
      }
    }
    cout << ans << endl;
  }
}
int main() {
  int N;
  cin >> N;
  n(N);
}
Problem p02608 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int counter(int x, int y, int z) {
  if (x == y && x == z)
    return 1;
  if (x != y && x != z && y != z)
    return 6;
  return 3;
}

int the_sol(int ind) {
  int sum = 0;
  for (int x = 1; x * x <= ind; x++) {
    for (int y = x; y * y <= ind; y++) {
      for (int z = y; z * z <= ind; z++) {
        if (x * x + y * y + z * z + x * y + x * z + y * z == ind)
          sum += counter(x, y, z);
      }
    }
  }
  return sum;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cout << the_sol(i) << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    int cnt = 0;
    for (int x = 1; x <= 100; x++) {
      for (int y = 1; y <= 100; y++) {
        for (int z = 1; z <= 100; z++) {
          if ((x * x) + (y * y) + (z * z) + (z * x) + (x * y) + (z * y) == i)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p02608 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;

void fun(long long n = 10000) {
  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        m[(pow(x, 2) + pow(y, 2) + pow(z, 2) + x * y + y * z + x * z)]++;
      }
    }
  }
}

int main() {
  fun();
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++)
    cout << m[i] << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int N = 0;
  cin >> N;
  int increament = 0;
  int counter = 0;

  for (int i = 1; i <= N; i++) {
    for (int x = 1; x < sqrt(i); x++) {
      for (int y = 1; y < sqrt(i); y++) {
        for (int z = 1; z < sqrt(i); z++) {
          if (x * x + y * y + z * z + x * y + x * z + z * y == i) {
            counter++;
          }
        }
      }
    }
    string str = to_string(counter);
    const char *l = str.c_str();
    printf(l);
    printf("\\n");
    counter = 0;
  }
  return 0;
}
Problem p02608 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <assert.h>
#include <bits/stdc++.h>
#include <bits/stdtr1c++.h>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 100005;
const int MOD = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 0; i <= n; i++)
    a[i] = 0;
  for (int i = 1; i * i <= n - 1; i++) {
    for (int j = 1; j * j <= n - 1; j++) {
      for (int k = 1; k * k <= n - 1; k++) {
        int sum = i * i + j * j + k * k + i * j + j * k + k * i;
        if (sum <= n)
          a[sum]++;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bits/stdc++.h>
#include <bits/stdtr1c++.h>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 100005;
const int MOD = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 0; i <= n; i++)
    a[i] = 0;
  for (int i = 1; i <= n - 1; i++) {
    for (int j = 1; j <= n - 1; j++) {
      for (int k = 1; k <= n - 1; k++) {
        int sum = i * i + j * j + k * k + i * j + j * k + k * i;
        if (sum <= n)
          a[sum]++;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    cout << a[i] << endl;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/11/20 19:53:47
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int mpow(int x, int p, int mod) {
  ll u = x;
  ll t = 1;
  while (p) {
    if (p & 1)
      (t *= u) %= mod;
    (u *= u) %= mod;
    p >>= 1;
  }
  return t;
}

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

  int n;
  cin >> n;
  string x;
  cin >> x;
  int pc = 0;
  for (auto c : x)
    if (c == '1')
      pc++;

  vector<int> ans(n);
  int a = pc + 1;
  int b = pc - 1;
  int nma = 0, nmb = 0;
  for (int i = 0; i < n; i++) {
    if (x[n - 1 - i] == '0')
      continue;
    (nma += mpow(2, i, a)) %= a;
    if (b > 0)
      (nmb += mpow(2, i, b)) %= b;
  }

  for (int i = 0; i < n; i++) {
    if (x[i] == '0') {
      int cnma = (nma + mpow(2, n - 1 - i, a)) % a;
      int cnt = 1;
      while (cnma) {
        cnma %= __builtin_popcount(cnma);
        cnt++;
      }
      ans[i] = cnt;
    } else {
      if (b == 0) {
        ans[i] = 0;
        continue;
      }
      int cnmb = (nmb + b - mpow(2, n - 1 - i, b)) % b;
      int cnt = 1;
      while (cnmb) {
        cnmb %= __builtin_popcount(cnmb);
        cnt++;
      }
      ans[i] = cnt;
    }
  }

  for (auto a : ans)
    cout << a << endl;

  return 0;
}


Error: 0

Fixed submission:

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 07/11/20 19:53:47
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int mpow(int x, int p, int mod) {
  if (mod == 0)
    return 0;
  ll u = x;
  ll t = 1;
  while (p) {
    if (p & 1)
      (t *= u) %= mod;
    (u *= u) %= mod;
    p >>= 1;
  }
  return t;
}

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

  int n;
  cin >> n;
  string x;
  cin >> x;
  int pc = 0;
  for (auto c : x)
    if (c == '1')
      pc++;

  vector<int> ans(n);
  if (pc == 0) {
    ans.assign(n, 0);

  } else {
    int a = pc + 1;
    int b = pc - 1;
    int nma = 0, nmb = 0;
    for (int i = 0; i < n; i++) {
      if (x[n - 1 - i] == '0')
        continue;
      (nma += mpow(2, i, a)) %= a;
      (nmb += mpow(2, i, b)) %= b;
    }

    for (int i = 0; i < n; i++) {
      if (x[i] == '0') {
        int cnma = (nma + mpow(2, n - 1 - i, a)) % a;
        int cnt = 1;
        while (cnma) {
          cnma %= __builtin_popcount(cnma);
          cnt++;
        }
        ans[i] = cnt;
      } else {
        if (b == 0) {
          ans[i] = 0;
          continue;
        }
        int cnmb = (nmb + b - mpow(2, n - 1 - i, b)) % b;
        int cnt = 1;
        while (cnmb) {
          cnmb %= __builtin_popcount(cnmb);
          cnt++;
        }
        ans[i] = cnt;
      }
    }
  }

  for (auto a : ans)
    cout << a << endl;

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> dp(n + 1);
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 0; j < 20; j++)
      if (i & (1 << j))
        cnt++;
    dp[i] = dp[i % cnt] + 1;
  }
  int modulo = 0;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    x[i] = c - '0';
    if (x[i])
      modulo++;
  }
  reverse(x.begin(), x.end());
  int modulo1 = modulo - 1;
  int modulo2 = modulo + 1;
  if (modulo1 <= 0)
    modulo1 = 1;
  vector<int> p1(n);
  vector<int> p2(n);
  p1[0] = 1 % modulo1;
  p2[0] = 1 % modulo2;
  for (int i = 1; i < n; i++) {
    p1[i] = p1[i - 1] * 2 % modulo1;
    p2[i] = p2[i - 1] * 2 % modulo2;
  }
  int sum1 = 0;
  int sum2 = 0;
  for (int i = 0; i < n; i++) {
    sum1 = (sum1 + p1[i] * x[i]) % modulo1;
    sum2 = (sum2 + p2[i] * x[i]) % modulo2;
  }
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    if (x[i] == 0) {
      int tmp = sum2;
      tmp = (tmp + p2[i]) % modulo2;
      ans[i] = 1 + dp[tmp];
      continue;
    }
    if (modulo == 1) {
      ans[i] = 0;
      continue;
    }
    int tmp = sum1;
    tmp = (tmp - p1[i] + modulo1) % modulo1;
    ans[i] = 1 + dp[tmp];
  }
  reverse(ans.begin(), ans.end());
  for (auto &now : ans)
    cout << now << '\\n';
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> dp(n + 1);
  for (int i = 1; i <= n; i++) {
    int cnt = 0;
    for (int j = 0; j < 20; j++)
      if (i & (1 << j))
        cnt++;
    dp[i] = dp[i % cnt] + 1;
  }
  int modulo = 0;
  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    x[i] = c - '0';
    if (x[i])
      modulo++;
  }
  reverse(x.begin(), x.end());
  int modulo1 = modulo - 1;
  int modulo2 = modulo + 1;
  if (modulo1 < 0)
    modulo1 = 1;
  vector<int> p1(n);
  vector<int> p2(n);
  p1[0] = 1 % modulo1;
  p2[0] = 1 % modulo2;
  for (int i = 1; i < n; i++) {
    p1[i] = p1[i - 1] * 2 % modulo1;
    p2[i] = p2[i - 1] * 2 % modulo2;
  }
  int sum1 = 0;
  int sum2 = 0;
  for (int i = 0; i < n; i++) {
    sum1 = (sum1 + p1[i] * x[i]) % modulo1;
    sum2 = (sum2 + p2[i] * x[i]) % modulo2;
  }
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    if (x[i] == 0) {
      int tmp = sum2;
      tmp = (tmp + p2[i]) % modulo2;
      ans[i] = 1 + dp[tmp];
      continue;
    }
    if (modulo == 1) {
      ans[i] = 0;
      continue;
    }
    int tmp = sum1;
    tmp = (tmp - p1[i] + modulo1) % modulo1;
    ans[i] = 1 + dp[tmp];
  }
  reverse(ans.begin(), ans.end());
  for (auto &now : ans)
    cout << now << '\\n';
  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++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;

int pcnt(int n) { return __builtin_popcount(n); }

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> x(n);
  rep(i, n) x.at(i) = s.at(i) - '0';

  int pc = 0;
  rep(i, n) pc += x.at(i);
  vector<int> ans(n);

  rep(b, 2) {
    int npc = pc;
    if (b == 0)
      npc++;
    else
      npc--;
    if (npc <= 0)
      continue;
    int r0 = 0;
    rep(j, n) {
      r0 = (r0 * 2) % npc;
      r0 += x.at(j);
    }

    int k = 1;
    for (int j = n - 1; j >= 0; j--) {
      if (x.at(j) == b) {
        int r = r0;
        if (b == 0)
          r = (r + k) % npc;
        else
          r = (r - k + npc) % npc;
        ans.at(j) = f(r) + 1;
      }
      k = (k * 2) % npc;
    }
  }
  rep(i, n) cout << ans.at(i) << endl;
}


Error: 0

Fixed submission:

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

int pcnt(int n) { return __builtin_popcount(n); }

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> x(n);
  rep(i, n) x.at(i) = s.at(i) - '0';

  int pc = 0;
  rep(i, n) pc += x.at(i);
  vector<int> ans(n);

  rep(b, 2) {
    int npc = pc;
    if (b == 0)
      npc++;
    else
      npc--;
    if (pc <= 0)
      continue;
    int r0 = 0;
    rep(j, n) {
      r0 = (r0 * 2) % npc;
      r0 += x.at(b);
    }

    int k = 1;
    for (int j = n - 1; j >= 0; j--) {
      if (x.at(j) == b) {
        int r = r0;
        if (b == 0)
          r = (r + k) % npc;
        else
          r = (r - k + npc) % npc;
        ans.at(j) = f(r) + 1;
      }
      k = (k * 2) % npc;
    }
  }
  rep(i, n) cout << ans.at(i) << endl;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ones = 0;
  cin >> n;
  string s;
  cin >> s;
  lvector d, REM(n, 0), rem(n, 0);
  rep(i, n) {
    d.emplace_back(s[i] - '0');
    if (d.back() == 1)
      ones++;
  }
  ll m1 = ones + 1, m2 = max(1ll, ones - 1ll);
  REM[0] = 1 % m1, rem[0] = 1 % m2;
  for (ll i = 1; i < n; ++i) {
    REM[i] = (2 * REM[i - 1]) % m1;
    rem[i] = (2 * rem[i - 1]) % m2;
  }
  reverse(ALL(REM));
  reverse(ALL(rem));
  ll R = 0, r = 0, p, div, ans;
  rep(i, n) if (d[i] == 1) {
    R += REM[i];
    r += rem[i];
  }
  rep(i, n) {
    ans = 1;
    if (d[i] == 1) {
      p = r - rem[i];
      p %= m2;
      if (ones == 1)
        ans = 0;
    } else {
      p = R + REM[i];
      p %= m1;
    }
    div = __builtin_popcount(p);
    while (p > 0) {
      p %= div;
      div = __builtin_popcount(p);
      ans++;
    }
    print(ans);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll, lvector, greater<ll>>
#define P pair<ll, ll>
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, ones = 0, V = 1, v = 1;
  cin >> n;
  string s;
  cin >> s;
  lvector d, Rem(n, 0), rem(n, 0);
  rep(i, n) {
    d.emplace_back(s[i] - '0');
    if (d.back() == 1)
      ones++;
  }
  rep(i, n) {
    Rem[i] = V % (ones + 1);
    V *= 2;
    V %= (ones + 1);
    rem[i] = v % (ones - 1);
    v *= 2;
    v %= (ones - 1);
  }
  reverse(ALL(Rem));
  reverse(ALL(rem));
  ll R = 0, r = 0;
  rep(i, n) if (d[i] == 1) {
    R += Rem[i];
    r += rem[i];
  }
  rep(i, n) {
    ll p, div, ans = 1;
    if (d[i] == 1)
      p = r - rem[i];
    else
      p = R + Rem[i];
    div = __builtin_popcount(p);
    while (p > 0) {
      p %= div;
      div = __builtin_popcount(p);
      ans++;
    }
    print(ans);
  }
  return 0;
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

ll modPow(ll a, ll n, ll p) {
  if (n == 0)
    return 1; // 0乗にも対応する場合
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main() {
  ll N, x = 0, s = 0, t = 0;
  string X;
  cin >> N >> X;
  vector<ll> f(N);
  rep(i, N) {
    if (i == 0)
      f.at(i) = 0;
    else {
      bitset<20> s(i);
      f.at(i) = f.at(i % s.count()) + 1;
    }
  }
  rep(i, N) {
    if (X.at(i) == '1')
      x++;
  }
  rep(i, N) {
    if (X.at(i) == '1') {
      t += modPow(2, N - 1 - i, x + 1);
      t %= x + 1;
      if (x > 1) {
        s += modPow(2, N - 1 - i, x - 1);
        s %= x - 1;
      }
    }
  }
  rep(i, N) {
    if (x == 1 && X.at(i) == '1') {
      cout << 0 << endl;
    } else if (X.at(i) == '1') {
      ll S = s;
      S += x - 1;
      S -= modPow(2, N - 1 - i, x - 1);
      S %= x - 1;
      cout << f.at(S) + 1 << endl;
    } else {
      ll T = t;
      T += modPow(2, N - 1 - i, x + 1);
      T %= x + 1;
      cout << f.at(T) + 1 << endl;
    }
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

ll modPow(ll a, ll n, ll p) {
  if (n == 0)
    return 1; // 0乗にも対応する場合
  if (n == 1)
    return a % p;
  if (n % 2 == 1)
    return (a * modPow(a, n - 1, p)) % p;
  ll t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main() {
  ll N, x = 0, s = 0, t = 0;
  string X;
  cin >> N >> X;
  vector<ll> f(N);
  rep(i, N) {
    if (i == 0)
      f.at(i) = 0;
    else {
      bitset<20> s(i);
      f.at(i) = f.at(i % s.count()) + 1;
    }
  }
  rep(i, N) {
    if (X.at(i) == '1')
      x++;
  }
  rep(i, N) {
    if (X.at(i) == '1') {
      t += modPow(2, N - 1 - i, x + 1);
      t %= x + 1;
      s += modPow(2, N - 1 - i, x - 1);
      s %= x - 1;
    }
  }
  rep(i, N) {
    if (x == 1 && X.at(i) == '1') {
      cout << 0 << endl;
    } else if (X.at(i) == '1') {
      ll S = s;
      S += x - 1;
      S -= modPow(2, N - 1 - i, x - 1);
      S %= x - 1;
      cout << f.at(S) + 1 << endl;
    } else {
      ll T = t;
      T += modPow(2, N - 1 - i, x + 1);
      T %= x + 1;
      cout << f.at(T) + 1 << endl;
    }
  }
}
Problem p02609 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long
int mod;
vector<int> ar;
int expo(int a, int n) {
  if (n <= 0)
    return 1;
  if (n == 1)
    return a;
  int tmp = expo(a, n / 2);
  tmp = (tmp * tmp) % mod;
  if (n & 1)
    tmp = (tmp * a) % mod;
  return tmp;
}
signed main() {
  int n;
  cin >> n;
  ar.resize(n);
  int c = 0;
  string str;
  cin >> str;

  for (int i = 0; i < n; ++i)
    ar[i] = str[i] == '1' ? 1 : 0, c += ar[i] ? 1 : 0;
  mod = c;
  int br[3] = {0};
  int dp[300000] = {0};
  for (int i = 1; i <= 200000; ++i) {
    int x = __builtin_popcount(i);
    dp[i] = 1 + dp[i % x];
  }
  for (int i = ar.size() - 1; ~i; --i) {
    if (mod > 0)
      br[1] = (br[1] + ar[i] * expo(2, ar.size() - i - 1)) % mod;
    --mod;
    if (mod > 0)
      br[0] = (br[0] + ar[i] * expo(2, ar.size() - i - 1)) % mod;
    mod += 2;
    if (mod > 0)
      br[2] = (br[2] + ar[i] * expo(2, ar.size() - i - 1)) % mod;
    --mod;
  }

  for (int i = 0; i < ar.size(); ++i) {
    if (ar[i] == 0) {
      ++mod;
      if (mod == 0) {
        cout << 0 << endl;
        continue;
      }
      int x = expo(2, ar.size() - i - 1);
      cout << dp[(x + br[2]) % mod] + 1 << endl;
      --mod;
    } else {
      --mod;
      if (mod <= 0) {
        cout << 0 << endl;
        ++mod;
        continue;
      }
      int x = expo(2, ar.size() - i - 1);
      int ne = (((br[0] - x) % mod) + mod) % mod;
      cout << 1 + dp[ne] << endl;
      ++mod;
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long
int mod;
vector<int> ar;
int expo(int a, int n) {
  if (n <= 0)
    return 1;
  if (n == 1)
    return a;
  int tmp = expo(a, n / 2);
  tmp = (tmp * tmp) % mod;
  if (n & 1)
    tmp = (tmp * a) % mod;
  return tmp;
}
signed main() {
  int n;
  cin >> n;
  ar.resize(n);
  int c = 0;
  string str;
  cin >> str;

  for (int i = 0; i < n; ++i)
    ar[i] = str[i] == '1' ? 1 : 0, c += ar[i] ? 1 : 0;
  mod = c;
  int br[3] = {0};
  int dp[300000] = {0};
  for (int i = 1; i <= 200000; ++i) {
    int x = __builtin_popcount(i);
    dp[i] = 1 + dp[i % x];
  }
  for (int i = ar.size() - 1; ~i; --i) {
    br[1] = (br[1] + ar[i] * expo(2, ar.size() - i - 1)) % mod;
    --mod;
    br[0] = (br[0] + ar[i] * expo(2, ar.size() - i - 1)) % mod;
    mod += 2;
    br[2] = (br[2] + ar[i] * expo(2, ar.size() - i - 1)) % mod;
    --mod;
  }

  for (int i = 0; i < ar.size(); ++i) {
    if (ar[i] == 0) {
      ++mod;
      int x = expo(2, ar.size() - i - 1);
      cout << dp[(x + br[2]) % mod] + 1 << endl;
      --mod;
    } else {
      --mod;
      int x = expo(2, ar.size() - i - 1);
      int ne = (((br[0] - x) % mod) + mod) % mod;
      cout << 1 + dp[ne] << endl;
      ++mod;
    }
  }

  return 0;
}