prithivMLmods/Coder-Stat huggingface dataset:
Problem p02840 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> ii;
unordered_map<ll, vector<ii>> m;
ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b % a, a); }
int main() {
  ll n, x, d;
  scanf("%lld%lld%lld", &n, &x, &d);
  ll l = 0, r = 0;
  for (int i = 0; i <= n; i++) {
    ll k = (i * x) / d;
    ll st = min(i * x + l * d, i * x + r * d);
    ll en = max(i * x + l * d, i * x + r * d);
    // printf("group %lld ",k);
    // printf("with %d elements, can go from %lld to %lld with remainder
    // %lld\n",i,st,en,(i*x)%d);
    m[(i * x) % d].push_back(ii(st, -1));
    m[(i * x) % d].push_back(ii(en, 1));
    l += i;
    r += (n - i - 1);
  }
  int sum = 0;
  ll last;
  ll ans = 0;
  for (auto p : m) {
    vector<ii> v = p.second;
    sort(v.begin(), v.end());
    for (auto x : v) {
      // printf("%lld %d\n",x.first,x.second);
      if (sum == 0 && x.second == -1) {
        last = x.first;
      } else if (sum == -1 && x.second == 1) {
        // printf("with remainder %lld, range (%lld ->
        // %lld)\n",p.first,last,x.first);
        ans += (x.first - last) / max(d, -d) + 1;
      }
      sum += x.second;
    }
  }
  printf("%lld", ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> ii;
unordered_map<ll, vector<ii>> m;
ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b % a, a); }
int main() {
  ll n, x, d;
  scanf("%lld%lld%lld", &n, &x, &d);
  ll l = 0, r = 0;
  if (d == 0) {
    if (x == 0) {
      printf("1");
      return 0;
    }
    printf("%lld", n + 1);
    return 0;
  }
  for (int i = 0; i <= n; i++) {
    ll k = (i * x) / d;
    ll st = min(i * x + l * d, i * x + r * d);
    ll en = max(i * x + l * d, i * x + r * d);
    // printf("group %lld ",k);
    // printf("with %d elements, can go from %lld to %lld with remainder
    // %lld\n",i,st,en,(i*x)%d);
    m[(i * x) % d].push_back(ii(st, -1));
    m[(i * x) % d].push_back(ii(en, 1));
    l += i;
    r += (n - i - 1);
  }
  int sum = 0;
  ll last;
  ll ans = 0;
  for (auto p : m) {
    vector<ii> v = p.second;
    sort(v.begin(), v.end());
    for (auto x : v) {
      // printf("%lld %d\n",x.first,x.second);
      if (sum == 0 && x.second == -1) {
        last = x.first;
      } else if (sum == -1 && x.second == 1) {
        // printf("with remainder %lld, range (%lld ->
        // %lld)\n",p.first,last,x.first);
        ans += (x.first - last) / max(d, -d) + 1;
      }
      sum += x.second;
    }
  }
  printf("%lld", ans);
}
Problem p02840 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

long prog(long x) { return x * (x - 1) / 2; }

int main() {
  ios::sync_with_stdio(false);

  int n;
  long x, d;
  cin >> n >> x >> d;
  if (d < 0) {
    x = -x;
    d = -d;
  }

  map<int, vector<pair<long, long>>> seg;

  for (int a = -n; a <= n; a++) {
    if ((a & 1) != (n & 1))
      continue;
    // plus + minus = n
    // plus - minus = a
    int plus = (n + a) / 2;

    long bmin = prog(plus) - (prog(n) - prog(plus));
    long bmax = -prog(n - plus) + (prog(n) - prog(n - plus));

    long p = a * x + bmin * d;
    long k = (bmax - bmin) / 2 + 1;

    int q = p % (2 * d);
    if (q < 0)
      q += 2 * d;

    long l = (p - q) / (2 * d);
    long r = l + k;

    //        cout << a << " " << bmin << " " << bmax << " " <<
    //        p << " " << k << " " << q << " " << l << " " << r << "\n";

    seg[q].push_back({l, r});
  }

  long res = 0;
  for (auto &p : seg) {
    auto &ss = p.second;
    sort(ss.begin(), ss.end());
    long r = LONG_MIN;
    for (auto s : ss) {
      if (s.second <= r)
        continue;
      res += s.second - max(r, s.first);
      r = s.second;
    }
  }
  cout << res << "\n";

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

long prog(long x) { return x * (x - 1) / 2; }

int main() {
  ios::sync_with_stdio(false);

  int n;
  long x, d;
  cin >> n >> x >> d;
  if (d < 0) {
    x = -x;
    d = -d;
  }

  if (d == 0) {
    if (x == 0) {
      cout << 1;
    } else {
      cout << n + 1;
    }
    return 0;
  }

  map<int, vector<pair<long, long>>> seg;

  for (int a = -n; a <= n; a++) {
    if ((a & 1) != (n & 1))
      continue;
    // plus + minus = n
    // plus - minus = a
    int plus = (n + a) / 2;

    long bmin = prog(plus) - (prog(n) - prog(plus));
    long bmax = -prog(n - plus) + (prog(n) - prog(n - plus));

    long p = a * x + bmin * d;
    long k = (bmax - bmin) / 2 + 1;

    int q = p % (2 * d);
    if (q < 0)
      q += 2 * d;

    long l = (p - q) / (2 * d);
    long r = l + k;

    //        cout << a << " " << bmin << " " << bmax << " " <<
    //        p << " " << k << " " << q << " " << l << " " << r << "\n";

    seg[q].push_back({l, r});
  }

  long res = 0;
  for (auto &p : seg) {
    auto &ss = p.second;
    sort(ss.begin(), ss.end());
    long r = LONG_MIN;
    for (auto s : ss) {
      if (s.second <= r)
        continue;
      res += s.second - max(r, s.first);
      r = s.second;
    }
  }
  cout << res << "\n";

  return 0;
}
Problem p02840 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define x first
#define y second

#ifdef LOCAL
#include "/Users/swad/Desktop/CP/debug.h"
#endif

const int N = int(2e5) + 10;

ll n, x, d;
ll pref[N], suff[N];
map<ll, ll> series_from;

int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  cin >> n >> x >> d;

  if (d < 0) {
    x += d * (n - 1);
    d *= -1;
  }

  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + (i - 1);
    suff[i] = suff[i - 1] + (n - i);
  }

  vector<pair<ll, ll>> seriesv(n + 1);

  for (int i = 0; i <= n; i++) {
    ll add = x * (i - (n - i));
    ll L = d * (pref[i] - suff[n - i]);
    ll R = d * (suff[i] - pref[n - i]);

    seriesv[i] = make_pair(add + L, add + R);
  }

  sort(seriesv.begin(), seriesv.end());

  ll ans = 0LL;
  d *= 2;

  for (pair<ll, ll> p : seriesv) {
    ll l = p.x, r = p.y;
    ll rem = (l % d + d) % d;

    ll R = LLONG_MIN;
    if (series_from.find(rem) != series_from.end()) {
      R = series_from[rem];
    }

    if (R < r) {
      l = max(l, R + d);
      ans += (r - l + d) / d;
      series_from[rem] = r;
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define x first
#define y second

#ifdef LOCAL
#include "/Users/swad/Desktop/CP/debug.h"
#endif

const int N = int(2e5) + 10;

ll n, x, d;
ll pref[N], suff[N];
map<ll, ll> series_from;

int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  cin >> n >> x >> d;

  if (d == 0) {
    if (x == 0)
      cout << 1 << endl;
    else
      cout << n + 1 << endl;
    return 0;
  }

  if (d < 0) {
    x += d * (n - 1);
    d *= -1;
  }

  for (int i = 1; i <= n; i++) {
    pref[i] = pref[i - 1] + (i - 1);
    suff[i] = suff[i - 1] + (n - i);
  }

  vector<pair<ll, ll>> seriesv(n + 1);

  for (int i = 0; i <= n; i++) {
    ll add = x * (i - (n - i));
    ll L = d * (pref[i] - suff[n - i]);
    ll R = d * (suff[i] - pref[n - i]);

    seriesv[i] = make_pair(add + L, add + R);
  }

  sort(seriesv.begin(), seriesv.end());

  ll ans = 0LL;
  d *= 2;

  for (pair<ll, ll> p : seriesv) {
    ll l = p.x, r = p.y;
    ll rem = (l % d + d) % d;

    ll R = LLONG_MIN;
    if (series_from.find(rem) != series_from.end()) {
      R = series_from[rem];
    }

    if (R < r) {
      l = max(l, R + d);
      ans += (r - l + d) / d;
      series_from[rem] = r;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p02840 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define MAX_N 200000

using namespace std;

typedef long long lint;

int n;

struct elem {
  lint r;
  lint st, dr;
};

int m;
elem v[MAX_N + 1];

lint x, d;

struct cmp {
  bool operator()(const elem &a, const elem &b) const {
    if (a.r != b.r)
      return a.r < b.r;

    return a.st < b.st;
  }
};

lint rez;

int main() {
  cin >> n >> x >> d;
  /*
      if(d < 0)
      {
          x = -x;
          d = -d;
      }*/

  if (d == 0) {
    rez = (x == 0 ? 1 : n + 1);

    cout << rez << "\n";

    return 0;
  }

  v[++m] = {0, 0, 0};
  for (int k = 1; k <= n; k++) {
    v[++m] = {1LL * k * x % d, 1LL * k * x / d + ((1LL * (k - 1) * k) >> 1),
              1LL * k * x / d + 1LL * n * k - (((1LL * k) * (k + 1)) >> 1)};
  }

  sort(v + 1, v + m + 1, cmp());

  int ant = -1;
  lint st = 0, dr = -1;
  for (int i = 1; i <= m; i++) {
    // cout << v[i].r << " " << v[i].st << " " << v[i].dr << "\n";

    if (ant != v[i].r) {
      rez += (dr - st) + 1;
      ant = v[i].r;
      st = v[i].st;
      dr = v[i].dr;
    }

    else {
      if (v[i].st <= dr)
        dr = max(dr, v[i].dr);

      else {
        rez += (dr - st) + 1;
        st = v[i].st;
        dr = v[i].dr;
      }
    }
  }

  rez += (dr - st) + 1;

  cout << rez << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define MAX_N 200000

using namespace std;

typedef long long lint;

int n;

struct elem {
  lint r;
  lint st, dr;
};

int m;
elem v[MAX_N + 1 + 1];

lint x, d;

struct cmp {
  bool operator()(const elem &a, const elem &b) const {
    if (a.r != b.r)
      return a.r < b.r;

    return a.st < b.st;
  }
};

lint rez;

int main() {
  cin >> n >> x >> d;
  /*
      if(d < 0)
      {
          x = -x;
          d = -d;
      }*/

  if (d == 0) {
    rez = (x == 0 ? 1 : n + 1);

    cout << rez << "\n";

    return 0;
  }

  v[++m] = {0, 0, 0};
  for (int k = 1; k <= n; k++) {
    v[++m] = {1LL * k * x % d, 1LL * k * x / d + ((1LL * (k - 1) * k) >> 1),
              1LL * k * x / d + 1LL * n * k - (((1LL * k) * (k + 1)) >> 1)};
  }

  sort(v + 1, v + m + 1, cmp());

  int ant = -1;
  lint st = 0, dr = -1;
  for (int i = 1; i <= m; i++) {
    // cout << v[i].r << " " << v[i].st << " " << v[i].dr << "\n";

    if (ant != v[i].r) {
      rez += (dr - st) + 1;
      ant = v[i].r;
      st = v[i].st;
      dr = v[i].dr;
    }

    else {
      if (v[i].st <= dr)
        dr = max(dr, v[i].dr);

      else {
        rez += (dr - st) + 1;
        st = v[i].st;
        dr = v[i].dr;
      }
    }
  }

  rez += (dr - st) + 1;

  cout << rez << "\n";

  return 0;
}
Problem p02840 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  const long long L = 100000000LL * 200000 + 199999LL * 100000LL * 100000000LL;
  int N;
  long long X, sD;
  while (cin >> N >> X >> sD) {
    map<int, vector<pair<long long, long long>>> mp;
    long long D = abs(sD);
    mp[L % D] = vector<pair<long long, long long>>();
    mp[L % D].emplace_back(L / D, L / D);
    for (long long i = 1; i <= N; i++) {
      long long l = (i * X + (i - 1) * i / 2 * sD + L);
      long long r = (i * X + (2 * N - 1 - i) * i / 2 * sD + L);
      if (l > r)
        swap(l, r);
      int key = l % D;
      if (!mp.count(key)) {
        mp[key] = vector<pair<long long, long long>>();
      }
      mp[key].emplace_back(l / D, r / D);
    }
    long long res = 0;
    for (auto &val : mp) {
      auto &v = val.second;
      sort(v.begin(), v.end());
      auto end = v[0].first - 1;
      for (auto &p : v) {
        res += max(0LL, p.second - max(end, p.first) + 1);
        end = max(end, p.second + 1);
      }
    }
    cout << res << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  const long long L = 100000000LL * 200000 + 199999LL * 100000LL * 100000000LL;
  int N;
  long long X, sD;
  while (cin >> N >> X >> sD) {
    map<int, vector<pair<long long, long long>>> mp;
    long long D = abs(sD);
    if (D == 0) {
      cout << (X == 0 ? 1 : N + 1) << endl;
      continue;
    }
    mp[L % D] = vector<pair<long long, long long>>();
    mp[L % D].emplace_back(L / D, L / D);
    for (long long i = 1; i <= N; i++) {
      long long l = (i * X + (i - 1) * i / 2 * sD + L);
      long long r = (i * X + (2 * N - 1 - i) * i / 2 * sD + L);
      if (l > r)
        swap(l, r);
      int key = l % D;
      if (!mp.count(key)) {
        mp[key] = vector<pair<long long, long long>>();
      }
      mp[key].emplace_back(l / D, r / D);
    }
    long long res = 0;
    for (auto &val : mp) {
      auto &v = val.second;
      sort(v.begin(), v.end());
      auto end = v[0].first - 1;
      for (auto &p : v) {
        res += max(0LL, p.second - max(end, p.first) + 1);
        end = max(end, p.second + 1);
      }
    }
    cout << res << endl;
  }
}
Problem p02840 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pll;

#define pb push_back
#define mp make_pair

const int N = 2e5 + 10;

int n;
LL X, D;
stack<pll> V[N];
unordered_map<LL, int> MP;

int getidx(LL v) {
  if (MP.count(v)) {
    return MP[v];
  }
  int m = MP.size();
  return MP[v] = m;
}

bool cross(LL L1, LL R1, LL L2, LL R2) { return min(R1, R2) >= max(L1, L2); }

int main() {
  scanf("%d %lld %lld", &n, &X, &D);
  LL d = abs(D);

  MP[0] = 0;

  V[0].push(mp(0, 0));

  LL low = 0, top = 0, lft = 0, rgt = n - 1;
  LL L, R, r;
  int idx;

  for (int i = 1; i <= n; i++) {
    low += lft;
    top += rgt;
    lft++;
    rgt--;

    r = (X * i % d + d) % d;
    L = (X * i - r) / D + low;
    R = (X * i - r) / D + top;

    idx = getidx(r);

    while (!V[idx].empty() &&
           cross(L, R, V[idx].top().first, V[idx].top().second)) {
      L = min(L, V[idx].top().first);
      R = max(R, V[idx].top().second);
      V[idx].pop();
    }

    V[idx].push(mp(L, R));
  }

  LL ans = 0;
  int m = MP.size();
  for (int i = 0; i < m; i++) {
    while (!V[i].empty()) {
      ans = ans + V[i].top().second - V[i].top().first + 1;
      V[i].pop();
    }
  }

  printf("%lld\n", ans);

  return 0;
}


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

typedef long long LL;
typedef pair<LL, LL> pll;

#define pb push_back
#define mp make_pair

const int N = 2e5 + 10;

int n;
LL X, D;
stack<pll> V[N];
unordered_map<LL, int> MP;

int getidx(LL v) {
  if (MP.count(v)) {
    return MP[v];
  }
  int m = MP.size();
  return MP[v] = m;
}

bool cross(LL L1, LL R1, LL L2, LL R2) { return min(R1, R2) >= max(L1, L2); }

int main() {
  scanf("%d %lld %lld", &n, &X, &D);

  if (D == 0) {
    if (X == 0) {
      puts("1");
    } else {
      printf("%d\n", n + 1);
    }
    return 0;
  }

  LL d = abs(D);

  MP[0] = 0;

  V[0].push(mp(0, 0));

  LL low = 0, top = 0, lft = 0, rgt = n - 1;
  LL L, R, r;
  int idx;

  for (int i = 1; i <= n; i++) {
    low += lft;
    top += rgt;
    lft++;
    rgt--;

    r = (X * i % d + d) % d;
    L = (X * i - r) / D + low;
    R = (X * i - r) / D + top;

    idx = getidx(r);

    while (!V[idx].empty() &&
           cross(L, R, V[idx].top().first, V[idx].top().second)) {
      L = min(L, V[idx].top().first);
      R = max(R, V[idx].top().second);
      V[idx].pop();
    }

    V[idx].push(mp(L, R));
  }

  LL ans = 0;
  int m = MP.size();
  for (int i = 0; i < m; i++) {
    while (!V[i].empty()) {
      ans = ans + V[i].top().second - V[i].top().first + 1;
      V[i].pop();
    }
  }

  printf("%lld\n", ans);

  return 0;
}
Problem p02840 (C++)

Buggy submission (status: 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 ll INF = 1ll << 60;

typedef pair<ll, ll> P;

int main() {
  ll n, x, d;
  cin >> n >> x >> d;
  map<int, vector<P>> mp;
  rep(i, n + 1) {
    ll s = x * i;
    ll l = (ll)i * (i - 1) / 2;
    ll r = l + (ll)i * (n - i);
    s += l * d;
    r -= l;
    mp[(s + (d << 30)) % d].emplace_back(s, r);
  }

  ll ans = 0;
  for (auto p : mp) {
    auto a = p.second;
    int m = a.size();
    rep(i, m) a[i].first = (a[i].first - p.first) / d;
    vector<P> ev;
    rep(i, m) {
      ev.emplace_back(a[i].first, 1);
      ev.emplace_back(a[i].first + a[i].second + 1, -1);
    }
    sort(ev.begin(), ev.end());
    ll cnt = 0, pre = -INF;
    for (auto e : ev) {
      ll len = e.first - pre;
      if (cnt)
        ans += len;
      cnt += e.second;
      pre = e.first;
    }
  }
  cout << ans << endl;
  return 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 ll INF = 1ll << 60;

typedef pair<ll, ll> P;

int main() {
  ll n, x, d;
  cin >> n >> x >> d;

  if (d == 0) {
    if (x == 0) {
      cout << 1 << endl;
    } else {
      cout << n + 1 << endl;
    }
    return 0;
  }

  map<int, vector<P>> mp;
  rep(i, n + 1) {
    ll s = x * i;
    ll l = (ll)i * (i - 1) / 2;
    ll r = l + (ll)i * (n - i);
    s += l * d;
    r -= l;
    mp[(s + (d << 30)) % d].emplace_back(s, r);
  }

  ll ans = 0;
  for (auto p : mp) {
    auto a = p.second;
    int m = a.size();
    rep(i, m) a[i].first = (a[i].first - p.first) / d;
    vector<P> ev;
    rep(i, m) {
      ev.emplace_back(a[i].first, 1);
      ev.emplace_back(a[i].first + a[i].second + 1, -1);
    }
    sort(ev.begin(), ev.end());
    ll cnt = 0, pre = -INF;
    for (auto e : ev) {
      ll len = e.first - pre;
      if (cnt)
        ans += len;
      cnt += e.second;
      pre = e.first;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02841 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
void deepu() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}

int main() {
  deepu();

  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == m2)
    cout << "0\n";
  else
    cout << "1\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
void deepu() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}

int main() {
  // deepu();

  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if (m1 == m2)
    cout << "0\n";
  else
    cout << "1\n";

  return 0;
}
Problem p02841 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN                                                                    \
  std::ios_base::sync_with_stdio(false);                                       \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main() {
  FIN;
#ifndef ONLINE_JUDGE
  freopen("../in.txt", "r", stdin);
  freopen("../out.txt", "w", stdout);
#endif
  int d1, m1, d2, m2;
  cin >> d1 >> m1 >> d2 >> m2;
  if (d1 != d2) {
    cout << 1;
  } else {
    cout << 0;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i, a, b) for (int i = a, almo5t = b; i < almo5t; ++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN                                                                    \
  std::ios_base::sync_with_stdio(false);                                       \
  cin.tie(NULL);                                                               \
  cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main() {
  FIN;

  int d1, m1, d2, m2;
  cin >> d1 >> m1 >> d2 >> m2;
  if (d1 != d2) {
    cout << 1;
  } else {
    cout << 0;
  }
  return 0;
}
Problem p02841 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int M1, D1;
  cin >> M1 >> D1;
  int M2, D2;
  cin >> M2 >> D2;

  int j = 0;
  rep(i, 1000000000000) { j++; }

  if (M1 == M2) {
    if (D1 + 1 == D2)
      cout << 0 << endl;
    else
      cout << 1 << endl;
  } else {
    cout << 1 << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((ll)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int M1, D1;
  cin >> M1 >> D1;
  int M2, D2;
  cin >> M2 >> D2;

  cout << (M1 != M2) << endl;
}
Problem p02841 (Python)

Buggy submission (status: Runtime Error):
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())

if m1 != m2:
    print("1")
    exit(1)

print("0")


Fixed submission:
m1, d1 = map(int, input().split())
m2, d2 = map(int, input().split())

if m1 != m2:
    print("1")
else:
    print("0")
Problem p02841 (Python)

Buggy submission (status: Runtime Error):
M1 = int(input())
D1 = int(input())
M2 = int(input())
D2 = int(input())

if D2 == 1:
    print(1)
else:
    print(0)


Fixed submission:
date_entry_1 = input()
M1, D1 = map(int, date_entry_1.split(" "))
date_entry_2 = input()
M2, D2 = map(int, date_entry_2.split(" "))

if D2 == 1:
    print(1)
else:
    print(0)
Problem p02841 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265
using namespace std;
using ll = long long;
void self_max(int &a, int b) { a = max(a, b); }
void self_min(ll &a, ll b) { a = min(a, b); }

int main() {
  int m1, d1;
  cin >> m1 >> d1;
  int m2, d2;
  cin >> m2 >> d2;

  if (m1 + 1 == m2)
    return 1;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265
using namespace std;
using ll = long long;
void self_max(int &a, int b) { a = max(a, b); }
void self_min(ll &a, ll b) { a = min(a, b); }

int main() {
  int m1, d1;
  cin >> m1 >> d1;
  int m2, d2;
  cin >> m2 >> d2;

  if (m1 + 1 == m2)
    cout << 1 << endl;
  else
    cout << 0 << endl;

  return 0;
}
Problem p02842 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int k = N;
  while (k >= N / 2) {
    int kj = k * 108;
    kj /= 100;
    if (kj == N) {
      cout << k << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int k = N;
  while (k >= N / 2) {
    int kj = k * 108;
    kj /= 100;
    if (kj == N) {
      cout << k << endl;
      return 0;
    }
    k--;
  }
  cout << ":(" << endl;
}
Problem p02842 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
int main(void) {
  int n;
  std::cin >> n;
  for (int i = n / 2; i < n; i++) {
    if (static_cast<int>(i * 1.08) == n) {
      std::cout << i << std::endl;
      return 1;
    }
  }
  std::cout << ":(" << std::endl;
}

Fixed submission:
#include <iostream>
int main(void) {
  int n;
  std::cin >> n;
  int a = n / 1.08;
  int b = a * 1.08;
  int c = (a + 1) * 1.08;
  if (b == n)
    std::cout << a << std::endl;
  else if (c == n)
    std::cout << a + 1 << std::endl;
  else
    std::cout << ":(" << std::endl;
}
Problem p02842 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

int main() {
  int N;
  std::cin >> N;
  int X = N * 25 / 27;
  for (;;) {
    int n = 27 * X / 25;
    if (n == N)
      break;
    if (n > N) {
      std::cout << ":(" << std::endl;
      return 0;
    }
  }
  std::cout << X << std::endl;
  return 0;
}


Fixed submission:
#include <iostream>

int main() {
  int N;
  std::cin >> N;
  int X = N * 25 / 27;
  for (;; ++X) {
    int n = 27 * X / 25;
    if (n == N)
      break;
    if (n > N) {
      std::cout << ":(" << std::endl;
      return 0;
    }
  }
  std::cout << X << std::endl;
  return 0;
}
Problem p02842 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef unsigned long long int ll;
#define fastio ios_base::sync_with_stdio(false);
#define rep(i, start, end) for (int i = start; i < end; i++)
using namespace std;

// debugger template
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
  }

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

void show(int *arr, int size) {
  rep(i, 0, size) { cout << arr[i] << " "; }
  cout << endl;
}

int main() {
  fastio int n;
  cin >> n;
  for (int i = 1; n <= 50000; i++) {
    if ((int)(i * 1.08) == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef unsigned long long int ll;
#define fastio ios_base::sync_with_stdio(false);
#define rep(i, start, end) for (int i = start; i < end; i++)
using namespace std;

// debugger template
#define error(args...)                                                         \
  {                                                                            \
    string _s = #args;                                                         \
    replace(_s.begin(), _s.end(), ',', ' ');                                   \
    stringstream _ss(_s);                                                      \
    istream_iterator<string> _it(_ss);                                         \
    err(_it, args);                                                            \
  }

void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}

void show(int *arr, int size) {
  rep(i, 0, size) { cout << arr[i] << " "; }
  cout << endl;
}

int main() {
  fastio int n;
  cin >> n;
  for (int i = 1; n <= 50000; i++) {
    if ((int)(i * 1.08) == n) {
      cout << i << endl;
      return 0;
    }
    if ((int)(i * 1.08) > n) {
      break;
    }
  }
  cout << ":(" << endl;
  return 0;
}
Problem p02842 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
for x in range(1, 50_000):
    if int(x * 1.08) == N:
        print(x)
        exit()
print(":(")


Fixed submission:
N = int(input())
for x in range(1, 50000):
    if int(x * 1.08) == N:
        print(x)
        exit()
print(":(")
Problem p02842 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
//------
#define R2(i, in, j, jn) REP(i, in) REP(j, jn)

using namespace std;

int main(void) {
  int I;
  cin >> I;
  int z;
  z = (I / 1.08); // zeinuki
  //	cout <<(I/1.08)<<" : "<<z;
  int Z = z * 1.08; // zeikomi
  if (Z == I)
    Z = I;
  else if (int((z + 1) * 1.08) == I) {
    z = z + 1;
    Z = int(z * 1.08);
  } else {
    cout << ":(";
    return 1;
  }
  cout << to_string(z);
  return 0;
} // 422


Fixed submission:
#include <iostream>
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
//------
#define R2(i, in, j, jn) REP(i, in) REP(j, jn)

using namespace std;

int main(void) {
  int I;
  cin >> I;
  int z;
  z = (I / 1.08); // zeinuki
  //	cout <<(I/1.08)<<" : "<<z;
  int Z = z * 1.08; // zeikomi
  if (Z == I)
    Z = I;
  else if (int((z + 1) * 1.08) == I) {
    z = z + 1;
    Z = int(z * 1.08);
  } else {
    cout << ":(";
    return 0;
  }
  cout << to_string(z);
  return 0;
} // 422
Problem p02843 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll, ll>
#define all(v) (v).begin(), (v).end()

const ll mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void) {
  ll x;
  cin >> x;
  bool dp[100010];
  dp[0] = true;
  rep(i, x) rep(j, 6) {
    if (dp[i] == true)
      dp[i + 100 + j] = true;
  }
  cout << dp[x] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll, ll>
#define all(v) (v).begin(), (v).end()

const ll mod = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void) {
  ll x;
  cin >> x;
  bool dp[110000];
  dp[0] = true;
  rep(i, x) rep(j, 6) {
    if (dp[i] == true)
      dp[i + 100 + j] = true;
  }
  cout << dp[x] << endl;
  return 0;
}
Problem p02843 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main() {
  std::ios_base::sync_with_stdio(0);

  u32 price101 = 101, price102 = 102, price103 = 103, price104 = 104,
      price105 = 105;

  i32 money;
  std::cin >> money;

  std::stringstream stream;
  stream << money;
  std::string digits = stream.str();

  u32 last2digits = (u32)std::stoi(digits.substr(digits.size() - 2, 2));

  while (money >= 0) {
    if (last2digits >= 5) {
      last2digits -= 5;
      money -= price105;
    } else if (last2digits >= 4) {
      last2digits -= 4;
      money -= price104;
    } else if (last2digits >= 3) {
      last2digits -= 3;
      money -= price103;
    } else if (last2digits >= 2) {
      last2digits -= 2;
      money -= price102;
    } else if (last2digits >= 1) {
      last2digits -= 1;
      money -= price101;
    } else if (last2digits == 0) {
      std::cout << "1";
      return 0;
    }
  }
  std::cout << "0";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main() {
  std::ios_base::sync_with_stdio(0);

  u32 price101 = 101, price102 = 102, price103 = 103, price104 = 104,
      price105 = 105;

  i32 money;
  std::cin >> money;

  if (money < 100) {
    std::cout << "0";
    return 0;
  }

  std::stringstream stream;
  stream << money;
  std::string digits = stream.str();

  u32 last2digits = (u32)std::stoi(digits.substr(digits.size() - 2, 2));

  while (money >= 0) {
    if (last2digits >= 5) {
      last2digits -= 5;
      money -= price105;
    } else if (last2digits >= 4) {
      last2digits -= 4;
      money -= price104;
    } else if (last2digits >= 3) {
      last2digits -= 3;
      money -= price103;
    } else if (last2digits >= 2) {
      last2digits -= 2;
      money -= price102;
    } else if (last2digits >= 1) {
      last2digits -= 1;
      money -= price101;
    } else if (last2digits == 0) {
      std::cout << "1";
      return 0;
    }
  }
  std::cout << "0";

  return 0;
}
Problem p02843 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int x;
  cin >> x;
  int n = x / 100;
  x %= 100;
  for (int a0 = 0; a0 <= n; ++a0) {
    for (int a1 = 0; a0 + a1 <= n; ++a1) {
      for (int a2 = 0; a0 + a1 + a2 <= n; ++a2) {
        for (int a3 = 0; a0 + a1 + a2 + a3 <= n; ++a3) {
          for (int a4 = 0; a0 + a1 + a2 + a3 + a4 <= n; ++a4) {
            if (a1 + 2 * a2 + 3 * a3 + 4 * a4 +
                    5 * (n - (a0 + a1 + a2 + a3 + a4)) ==
                x) {
              cout << 1 << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << 0 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int x;
  cin >> x;
  int n = x / 100;
  x %= 100;
  for (int a0 = 0; a0 <= n; ++a0) {
    for (int a1 = 0; a0 + a1 <= n && a1 <= x; ++a1) {
      for (int a2 = 0; a0 + a1 + a2 <= n && a1 + 2 * a2 <= x; ++a2) {
        for (int a3 = 0; a0 + a1 + a2 + a3 <= n && a1 + 2 * a2 + 3 * a3 <= x;
             ++a3) {
          for (int a4 = 0; a0 + a1 + a2 + a3 + a4 <= n &&
                           a1 + 2 * a2 + 3 * a3 + 4 * a4 +
                                   5 * (n - (a0 + a1 + a2 + a3 + a4)) <=
                               x;
               ++a4) {
            if (a1 + 2 * a2 + 3 * a3 + 4 * a4 +
                    5 * (n - (a0 + a1 + a2 + a3 + a4)) ==
                x) {
              cout << 1 << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << 0 << endl;
}
Problem p02843 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int x;
  cin >> x;
  int n = x / 100;
  if ((x % 100) / n < 5) {
    cout << 1 << endl;
    return;
  } else if ((x % 100) / n == 5) {
    if ((x % 100) % n == 0) {
      cout << 1 << endl;
      return;
    }
  }
  cout << 0 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int x;
  cin >> x;
  int n = x / 100;
  if (n == 0) {
    cout << 0 << endl;
    return;
  }
  if ((x % 100) / n < 5) {
    cout << 1 << endl;
    return;
  } else if ((x % 100) / n == 5) {
    if ((x % 100) % n == 0) {
      cout << 1 << endl;
      return;
    }
  }
  cout << 0 << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}
Problem p02843 (C++)

Buggy submission (status: Runtime Error):
// #pragma GCC target("avx2")
// #pragma GCC optimization("O3")
// #pragma GCC optimization("unroll-loops")
// assert(q==w) если q!=w --> runtime error
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x, 0, sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int>> matrix;

inline void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const ll maxn = 2e5 + 123;
const ll inf = 1e9 + 123;
const ll linf = 1e18 + 123;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
const double pi = acos(-1);
int dx[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int dy[8] = {1, 0, 0, -1, 1, 1, -1, -1};

int main() {
  boost();
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n;
  cin >> n;
  int kol = n / 100;
  int q = n % 100;
  if (ceil(q / kol) <= 6) {
    cout << "1";
    return 0;
  }
  cout << "0";
  exit(0);
}


Fixed submission:
// #pragma GCC target("avx2")
// #pragma GCC optimization("O3")
// #pragma GCC optimization("unroll-loops")
// assert(q==w) если q!=w --> runtime error
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x, 0, sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int>> matrix;

inline void boost() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

const ll maxn = 2e5 + 123;
const ll inf = 1e9 + 123;
const ll linf = 1e18 + 123;
const ll mod = 1e9 + 7;
const double eps = 1e-9;
const double pi = acos(-1);
int dx[8] = {0, 1, -1, 0, 1, -1, 1, -1};
int dy[8] = {1, 0, 0, -1, 1, 1, -1, -1};

int main() {
  boost();
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n;
  cin >> n;
  int kol = n / 100;
  int q = n % 100;
  if (n < 100) {
    cout << "0";
    return 0;
  }
  if (q <= kol * 5) {
    cout << "1";
    return 0;
  }
  cout << "0";
  exit(0);
}
Problem p02843 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool dfs(int k, int r, int cnt) {
  bool res = false;
  if (cnt == 0) {
    if (r == 0 && k >= 0)
      return 1;
    else
      return 0;
  }
  for (int i = 0; i <= k; i++) {
    res |= dfs(k - i, r - cnt * i, cnt - 1);
  }
  return res;
}

int main() {
  int x;
  cin >> x;
  int k = x / 100, r = x % 100;
  cout << (int)dfs(k, r, 5) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool dfs(int k, int r, int cnt) {
  bool res = false;
  if (cnt == 0) {
    if (r == 0 && k >= 0)
      return 1;
    else
      return 0;
  }
  for (int i = k; i >= 0; i--) {
    if (r - cnt * i >= 0)
      res |= dfs(k - i, r - cnt * i, cnt - 1);
    if (res == true)
      break;
  }
  return res;
}

int main() {
  int x;
  cin >> x;
  int k = x / 100, r = x % 100;
  cout << (int)dfs(k, r, 5) << endl;
  return 0;
}
Problem p02843 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
bool b = 0;
void dfs(int X) {
  if (X == 100) {
    b = 1;
    return;
  } else if (X == 101) {
    b = 1;
    return;
  } else if (X == 102) {
    b = 1;
    return;
  } else if (X == 103) {
    b = 1;
    return;
  } else if (X == 104) {
    b = 1;
    return;
  } else if (X == 105) {
    b = 1;
    return;
  }

  if (X < 100)
    return;
  dfs(X - 100);
  dfs(X - 101);
  dfs(X - 102);
  dfs(X - 103);
  dfs(X - 104);
  dfs(X - 105);
}
int main() {
  int X;
  cin >> X;
  dfs(X);
  cout << b;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool b = 0;
void dfs(int X) {
  if (X == 100) {
    b = 1;
    return;
  } else if (X == 101) {
    b = 1;
    return;
  } else if (X == 102) {
    b = 1;
    return;
  } else if (X == 103) {
    b = 1;
    return;
  } else if (X == 104) {
    b = 1;
    return;
  } else if (X == 105) {
    b = 1;
    return;
  }

  if (X < 100)
    return;
  dfs(X - 100);
  dfs(X - 101);
  dfs(X - 102);
  dfs(X - 103);
  dfs(X - 104);
  dfs(X - 105);
}
int main() {
  int X;
  cin >> X;
  int a[X + 1];
  memset(a, 0, sizeof a);
  for (int i = 100; i <= 105; i++)
    a[i] = 1;
  for (int i = 200; i <= X; i++) {
    if (a[i - 100])
      a[i] = 1;
    else if (a[i - 101])
      a[i] = 1;
    else if (a[i - 102])
      a[i] = 1;
    else if (a[i - 103])
      a[i] = 1;
    else if (a[i - 104])
      a[i] = 1;
    else if (a[i - 105])
      a[i] = 1;
  }
  cout << a[X];
}
Problem p02843 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

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

  vector<vector<bool>> dp(7, vector<bool>(100001));
  dp[0][0] = true;
  for (int i = 0; i < 6; i++) {
    int c = 100 + i;
    for (int j = 0; j <= X; j++) {
      dp[i + 1][j] = dp[i + 1][j] || dp[i][j];
      if (dp[i + 1][j]) {
        dp[i + 1][j + c] = dp[i + 1][j];
      }
    }
  }

  cout << dp[6][X] << endl;
  return 0;
}

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

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

  vector<vector<bool>> dp(7, vector<bool>(100505));
  dp[0][0] = true;
  for (int i = 0; i < 6; i++) {
    int c = 100 + i;
    for (int j = 0; j <= X; j++) {
      dp[i + 1][j] = dp[i + 1][j] || dp[i][j];
      if (dp[i + 1][j]) {
        dp[i + 1][j + c] = dp[i + 1][j];
      }
    }
  }

  cout << dp[6][X] << endl;
  return 0;
}
Problem p02843 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int X;
  cin >> X;
  int num, frac;
  num = X / 100;
  frac = X % 100;
  if ((frac + 1) / num <= 5)
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 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;

int main() {
  int X;
  cin >> X;
  int num, frac;
  num = X / 100;
  frac = X % 100;
  if (num != 0 && (frac / num < 5 || (frac / num == 5 && frac % num == 0)))
    cout << 1 << endl;
  else
    cout << 0 << endl;
  return 0;
}
Problem p02843 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
  int x;
  cin >> x;
  rep(i, 1000) {
    rep(j, 1000) {
      rep(k, 1000) {
        rep(l, 1000) {
          rep(m, 1000) {
            rep(n, 1000) {
              if (100 * i + 101 * j + 102 * k + 103 * l + 104 * m + 105 * n ==
                  x) {
                cout << '1' << endl;
                return 0;
              }
            }
          }
        }
      }
    }
  }
  cout << '0' << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
  int x;
  cin >> x;
  rep(i, x) {
    if (100 * i <= x && x <= 105 * i) {
      cout << '1' << endl;
      return 0;
    }
  }
  cout << '0' << endl;
  return 0;
}
Problem p02843 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)

using namespace std;
typedef long long ll;
ll x;
ll a[6] = {100, 101, 102, 103, 104, 105};
set<ll> s;
void dfs(ll now) {
  if (now > 100000)
    return;
  s.insert(now);
  rep(i, 6) dfs(now + a[i]);
}
int main() {
  dfs(0);
  while (cin >> x) {
    if (s.count(x))
      cout << "1\n";
    else
      cout << "0\n";
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)

using namespace std;
typedef long long ll;
ll x;
ll a[6] = {100, 101, 102, 103, 104, 105};
set<ll> s;
void dfs(ll now) {
  if (now > 100000)
    return;
  s.insert(now);
  rep(i, 6) {
    if (!s.count(now + a[i]))
      dfs(now + a[i]);
  }
}
int main() {
  dfs(0);
  while (cin >> x) {
    if (s.count(x))
      cout << "1\n";
    else
      cout << "0\n";
  }
}
Problem p02843 (Python)

Buggy submission (status: Runtime Error):
n = input()
num = int(n[0:-2])
yen = int(n[-2::])
if num * 5 >= yen:
    print(1)
else:
    print(0)


Fixed submission:
n = input()
if len(n) >= 3:
    num = int(n[0:-2])
    yen = int(n[-2::])
    if num * 5 >= yen:
        print(1)
    else:
        print(0)
else:
    print(0)
Problem p02843 (Python)

Buggy submission (status: Runtime Error):
x = input()
k = int(x[0:-2])
x = int(x[-2:])

k -= x / 5
if x % 5 == 0 and k >= 0:
    print(1)
elif k > 0:
    print(1)
else:
    print(0)


Fixed submission:
x = input()
if len(x) < 3:
    print(0)
    exit()
k = int(x[0:-2])
x = int(x[-2:])

k -= x / 5
if x % 5 == 0 and k >= 0:
    print(1)
elif k > 0:
    print(1)
else:
    print(0)
Problem p02843 (Python)

Buggy submission (status: Runtime Error):
X = int(input())

dp = [0] * (100000)
dp[0] = 1

for i in range(X + 1):
    if dp[i] == 1:
        for j in range(6):
            dp[i + 100 + j] = 1
            if i + 100 + j == X:
                print(1)
                exit()
print(0)


Fixed submission:
X = int(input())

dp = [0] * (100200)
dp[0] = 1

for i in range(X + 1):
    if dp[i] == 1:
        for j in range(6):
            dp[i + 100 + j] = 1
            if i + 100 + j == X:
                print(1)
                exit()
print(0)
Problem p02843 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main(void) {
  int X;
  cin >> X;
  int cnt = X / 100;
  int amari = X % 100; // 調整が必要な金額
  if (cnt == 0) {
    cout << "0" << endl;
    return 0;
  }
  // 0
  for (int i = 0; i <= cnt; i++) {
    // 1
    for (int j = 0; j <= cnt - i; j++) {
      // 2
      for (int k = 0; k <= cnt - i - j; k++) {
        // 3
        for (int l = 0; l <= cnt - i - j - k; l++) {
          // 4
          for (int m = 0; m <= cnt - i - j - k - l; m++) {
            // 5
            if (0 * i + 1 * j + 2 * k + 3 * l + 4 * m +
                    5 * (cnt - i - j - k - l - m) ==
                amari) {
              cout << "1" << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << "0" << endl;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main(void) {
  int X;
  cin >> X;
  int cnt = X / 100;
  int amari = X % 100; // 調整が必要な金額
  if (cnt == 0) {
    cout << "0" << endl;
    return 0;
  } else if (cnt >= 100) {
    cout << "1" << endl;
    return 0;
  }
  // 0
  for (int i = 0; i <= cnt; i++) {
    // 1
    for (int j = 0; j <= cnt - i; j++) {
      // 2
      for (int k = 0; k <= cnt - i - j; k++) {
        // 3
        for (int l = 0; l <= cnt - i - j - k; l++) {
          // 4
          for (int m = 0; m <= cnt - i - j - k - l; m++) {
            // 5
            if (0 * i + 1 * j + 2 * k + 3 * l + 4 * m +
                    5 * (cnt - i - j - k - l - m) ==
                amari) {
              cout << "1" << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << "0" << endl;
  return 0;
}