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

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

using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)

typedef pair<int, int> P;
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

int main() {

  int n, k;
  cin >> n >> k;

  if (k > (n - 1) * (n - 2) / 2) {
    cout << -1 << endl;
    return 0;
  }

  assert(n == 0);
}


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

using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)

typedef pair<int, int> P;
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

int main() {

  int n, k;
  cin >> n >> k;

  if (k > (n - 1) * (n - 2) / 2) {
    cout << -1 << endl;
    return 0;
  }

  int l = (n - 1) * (n - 2) / 2;

  l -= k;
  vector<pair<int, int>> v;
  REP(i, n - 1) { v.push_back({1, i + 2}); }

  while (l) {

    FOR(i, 2, n) {
      FOR(j, i + 1, n + 1) {
        l--;
        v.push_back({i, j});
        if (l == 0)
          break;
      }
      if (l == 0)
        break;
    }
    break;
  }

  cout << v.size() << endl;

  REP(i, v.size()) { cout << v[i].first << ' ' << v[i].second << endl; }
}
Problem p02997 (C++)

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

int main() {
  int N, K;
  cin >> N >> K;
  int count = 0;
  vector<vector<int>> G(N);
  int m = (N - 2) * (N - 1) / 2;
  if (K > m) {
    cout << -1 << endl;
    return 0;
  }

  for (int i = 1; i < N; i++)
    G[0].push_back(i);

  int n = m - K;
  for (int i = 0; i < n; i++)
    G[i + 1].push_back(i + 2);

  cout << N - 1 + n << endl;
  for (int i = 0; i < G.size(); i++) {
    for (int j = 0; j < G[i].size(); j++) {
      cout << i + 1 << " " << G[i][j] + 1 << endl;
    }
  }
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int count = 0;
  vector<vector<int>> G(N);
  int m = (N - 2) * (N - 1) / 2;
  if (K > m) {
    cout << -1 << endl;
    return 0;
  }

  for (int i = 1; i < N; i++)
    G[0].push_back(i);

  int n = m - K;
  int cnt = 0;
  for (int i = 1; i < N - 1; i++) {
    if (cnt >= n)
      break;
    for (int j = i + 1; j < N; j++) {
      if (cnt >= n)
        break;
      G[i].push_back(j);
      cnt++;
    }
  }
  cout << N - 1 + n << endl;
  for (int i = 0; i < G.size(); i++) {
    for (int j = 0; j < G[i].size(); j++) {
      cout << i + 1 << " " << G[i][j] + 1 << endl;
    }
  }
}
Problem p02997 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pi pair<ll, ll>
using namespace std;
const ll N = 250001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, k;
  cin >> n >> k;

  if (n == 2) {
    exit(1);
    if (k != 1) {
      cout << "-1";
    } else {
      cout << "1" << endl;
      cout << "1 2";
    }
    return (0);
  }

  ll lol = ((n - 1) * (n - 2)) / 2;
  if (k > lol) {
    cout << "-1";
    return (0);
  }

  set<pi> ans;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      ans.insert(mp(i, j));
    }
  }

  while (k--) {
    set<pi>::iterator it = ans.begin();
    while (it->second == n) {
      advance(it, 1);
    }
    ans.erase(it);
  }

  cout << ans.size() << endl;
  for (auto x : ans) {
    cout << x.first << " " << x.second << endl;
  }

  return (0);
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pi pair<ll, ll>
using namespace std;
const ll N = 250001;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int n, k;
  cin >> n >> k;

  ll lol = ((n - 1) * (n - 2)) / 2;
  if (k > lol) {
    cout << "-1";
    return (0);
  }

  set<pi> ans;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      ans.insert(mp(i, j));
    }
  }

  while (k--) {
    set<pi>::iterator it = ans.begin();
    while (it->second == n) {
      advance(it, 1);
    }
    ans.erase(it);
  }

  cout << ans.size() << endl;
  for (auto x : ans) {
    cout << x.first << " " << x.second << endl;
  }

  return (0);
}
Problem p02998 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; ++i) {
    cin >> X[i] >> Y[i];
  }
  vector<int> gx = X, gy = Y;
  sort(gx.begin(), gx.end());
  gx.erase(unique(gx.begin(), gx.end()), gx.end());
  sort(gy.begin(), gy.end());
  gy.erase(unique(gy.begin(), gy.end()), gy.end());
  int sx = gx.size(), sy = gy.size();
  vector<vector<int>> G(sx + sy);
  for (int i = 0; i < N; ++i) {
    int px = lower_bound(gx.begin(), gx.end(), X[i]) - gx.begin();
    int py = lower_bound(gy.begin(), gy.end(), Y[i]) - gy.begin();
    G[px].push_back(py + sy);
    G[py + sy].push_back(px);
  }
  vector<bool> vis(sx + sy, false);
  int cx = 0, cy = 0;
  function<void(int)> dfs = [&](int pos) {
    vis[pos] = true;
    if (pos < sx)
      ++cx;
    else
      ++cy;
    for (int i : G[pos]) {
      if (vis[i])
        continue;
      dfs(i);
    }
  };
  long long ans = 0;
  for (int i = 0; i < sx + sy; ++i) {
    if (!vis[i]) {
      cx = 0, cy = 0;
      dfs(i);
      ans += 1LL * cx * cy;
    }
  }
  cout << ans - N << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; ++i) {
    cin >> X[i] >> Y[i];
  }
  vector<int> gx = X, gy = Y;
  sort(gx.begin(), gx.end());
  gx.erase(unique(gx.begin(), gx.end()), gx.end());
  sort(gy.begin(), gy.end());
  gy.erase(unique(gy.begin(), gy.end()), gy.end());
  int sx = gx.size(), sy = gy.size();
  vector<vector<int>> G(sx + sy);
  for (int i = 0; i < N; ++i) {
    int px = lower_bound(gx.begin(), gx.end(), X[i]) - gx.begin();
    int py = lower_bound(gy.begin(), gy.end(), Y[i]) - gy.begin();
    G[px].push_back(py + sx);
    G[py + sx].push_back(px);
  }
  vector<bool> vis(sx + sy, false);
  int cx = 0, cy = 0;
  function<void(int)> dfs = [&](int pos) {
    vis[pos] = true;
    if (pos < sx)
      ++cx;
    else
      ++cy;
    for (int i : G[pos]) {
      if (vis[i])
        continue;
      dfs(i);
    }
  };
  long long ans = 0;
  for (int i = 0; i < sx + sy; ++i) {
    if (!vis[i]) {
      cx = 0, cy = 0;
      dfs(i);
      ans += 1LL * cx * cy;
    }
  }
  cout << ans - N << endl;
  return 0;
}
Problem p02998 (C++)

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

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
using ll = long long;
using vi = vector<int>;

// rank無しなのでlog n
class UnionFind {
public:
  vi data;

  UnionFind(int size) {
    data.resize(size, -1);
    // rep(i, size) data[i] = -1;
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x])
        swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }

  bool find(int x, int y) { return root(x) == root(y); }

  int root(int x) { // どの集合か
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  int size(int x) { return -data[root(x)]; }
};

signed main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];

#define MAX 10005
  UnionFind ufx(MAX), ufy(MAX);
  vector<vector<int>> sx(MAX), sy(MAX);
  rep(i, n) {
    sx[x[i]].push_back(y[i]);
    sy[y[i]].push_back(x[i]);
  }
  rep(i, MAX) {
    FOR(j, 1, sx[i].size())
    ufy.unite(sx[i][0], sx[i][j]);
    FOR(j, 1, sy[i].size())
    ufx.unite(sy[i][0], sy[i][j]);
  }
  vector<int> usedx(MAX);
  int maxv = 0;
  rep(i, n) if (usedx[ufx.root(x[i])] == 0) {
    maxv += ufx.size(x[i]) * ufy.size(y[i]);
    usedx[ufx.root(x[i])] = 1;
  }
  cout << maxv - n << endl;
}


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

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
using ll = long long;
using vi = vector<int>;

// rank無しなのでlog n
class UnionFind {
public:
  vi data;

  UnionFind(int size) {
    data.resize(size, -1);
    // rep(i, size) data[i] = -1;
  }

  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x])
        swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }

  bool find(int x, int y) { return root(x) == root(y); }

  int root(int x) { // どの集合か
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }

  int size(int x) { return -data[root(x)]; }
};

signed main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];

#define MAX 100005
  UnionFind ufx(MAX), ufy(MAX);
  vector<vector<int>> sx(MAX), sy(MAX);
  rep(i, n) {
    sx[x[i]].push_back(y[i]);
    sy[y[i]].push_back(x[i]);
  }
  rep(i, MAX) {
    FOR(j, 1, sx[i].size())
    ufy.unite(sx[i][0], sx[i][j]);
    FOR(j, 1, sy[i].size())
    ufx.unite(sy[i][0], sy[i][j]);
  }
  vector<int> usedx(MAX);
  int maxv = 0;
  rep(i, n) if (usedx[ufx.root(x[i])] == 0) {
    maxv += ufx.size(x[i]) * ufy.size(y[i]);
    usedx[ufx.root(x[i])] = 1;
  }
  cout << maxv - n << endl;
}
Problem p02998 (C++)

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

class UnionFind {
public:
  // parent node index if not root index
  // minus size of the tree if root index
  std::vector<int> data;

  UnionFind(int n) { data.resize(n, -1); }

  int find(int x) {
    if (data[x] < 0) {
      return x;
    } else {
      int r = find(data[x]);
      data[x] = r;
      return r;
    }
  }

  void unite(int x, int y) {
    int r = find(x);
    int s = find(y);
    if (r != s) {
      data[r] += data[s];
      data[s] = r;
    }
  }

  int count(int x) { return -data[find(x)]; }
};

template <typename T> int compress(vector<T> &x) {
  int n = x.size();
  vector<T> xs(n);
  for (int i = 0; i < n; i++)
    xs[i] = x[i];
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < n; i++) {
    x[i] = find(xs.begin(), xs.end(), x[i]) - xs.begin();
  }
  return xs.size();
}

int main() {
  int N;
  cin >> N;
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
    X[i]--, Y[i]--;
  }
  compress(X);
  compress(Y);
  UnionFind uf(2 * N);
  for (int i = 0; i < N; i++) {
    uf.unite(X[i], Y[i] + N);
  }

  map<int, int> nx, ny;
  for (int i = 0; i < 2 * N; i++) {
    int r = uf.find(i);
    int c = uf.count(r);
    if (c <= 1)
      continue;
    if (i < N) {
      nx[r]++;
    } else {
      ny[r]++;
    }
  }

  ll dots = 0;
  for (auto q : nx) {
    dots += (ll)q.second * ny[q.first];
  }
  ll ans = dots - N;
  cout << ans << '\n';
  return 0;
}

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

class UnionFind {
public:
  // parent node index if not root index
  // minus size of the tree if root index
  std::vector<int> data;

  UnionFind(int n) { data.resize(n, -1); }

  int find(int x) {
    if (data[x] < 0) {
      return x;
    } else {
      int r = find(data[x]);
      data[x] = r;
      return r;
    }
  }

  void unite(int x, int y) {
    int r = find(x);
    int s = find(y);
    if (r != s) {
      data[r] += data[s];
      data[s] = r;
    }
  }

  int count(int x) { return -data[find(x)]; }
};

template <typename T> int compress(vector<T> &x) {
  int n = x.size();
  vector<T> xs(n);
  for (int i = 0; i < n; i++)
    xs[i] = x[i];
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < n; i++) {
    x[i] = lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin();
  }
  return xs.size();
}

int main() {
  int N;
  cin >> N;
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
    X[i]--, Y[i]--;
  }
  compress(X);
  compress(Y);
  UnionFind uf(2 * N);
  for (int i = 0; i < N; i++) {
    uf.unite(X[i], Y[i] + N);
  }

  map<int, int> nx, ny;
  for (int i = 0; i < 2 * N; i++) {
    int r = uf.find(i);
    int c = uf.count(r);
    if (c <= 1)
      continue;
    if (i < N) {
      nx[r]++;
    } else {
      ny[r]++;
    }
  }

  ll dots = 0;
  for (auto q : nx) {
    dots += (ll)q.second * ny[q.first];
  }
  ll ans = dots - N;
  cout << ans << '\n';
  return 0;
}
Problem p02998 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;
int x[100010], y[100010];
vector<int> X[100010], Y[100010];
bool visited[100010];
map<P, int> mp;
int ans = 0;

set<int> stX, stY;
set<P> st;
int cnt = 0;
void search(int x, int y) {
  if (cnt >= 2000000)
    return;
  if (visited[mp[{x, y}]])
    return;
  stX.insert(x);
  stY.insert(y);
  st.insert({x, y});
  visited[mp[{x, y}]] = true;
  for (auto to : X[y]) {
    search(to, y);
  }
  for (auto to : Y[x]) {
    search(x, to);
  }
}

signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  rep(i, N) {
    cin >> x[i] >> y[i];
    X[y[i]].push_back(x[i]);
    Y[x[i]].push_back(y[i]);
    mp[{x[i], y[i]}] = i;
  }
  int ans = 0;
  rep(i, N) {
    if (cnt >= 2000000) {
      cout << 0 << endl;
      return 0;
    }
    if (visited[i])
      continue;
    search(x[i], y[i]);
    ans += stX.size() * stY.size() - st.size();
    st.clear();
    stX.clear();
    stY.clear();
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
typedef pair<int, int> P;
int x[100010], y[100010];
vector<int> X[100010], Y[100010];
bool visited[100010];
map<P, int> mp;
int ans = 0;

set<int> stX, stY;
set<P> st;
int cnt = 0;
void search(int x, int y) {
  if (cnt >= 2000000)
    return;
  cnt++;
  if (visited[mp[{x, y}]])
    return;
  stX.insert(x);
  stY.insert(y);
  st.insert({x, y});
  visited[mp[{x, y}]] = true;
  for (auto to : X[y]) {
    search(to, y);
  }
  for (auto to : Y[x]) {
    search(x, to);
  }
}

signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  rep(i, N) {
    cin >> x[i] >> y[i];
    X[y[i]].push_back(x[i]);
    Y[x[i]].push_back(y[i]);
    mp[{x[i], y[i]}] = i;
  }
  int ans = 0;
  rep(i, N) {
    if (cnt >= 2000000) {
      cout << 0 << endl;
      return 0;
    }
    if (visited[i])
      continue;
    search(x[i], y[i]);
    ans += stX.size() * stY.size() - st.size();
    st.clear();
    stX.clear();
    stY.clear();
  }
  cout << ans << endl;

  return 0;
}
Problem p02998 (C++)

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

int main() {
  int n;
  scanf("%d", &n);
  int N = 101;
  vector<vector<int>> g(2 * N);
  rep(i, n) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    g[x].push_back(y + N);
    g[y + N].push_back(x);
  }
  vector<bool> used(2 * N);
  int x = 0, y = 0;
  function<void(int)> dfs = [&](int u) {
    if (u < N)
      x++;
    else
      y++;
    used[u] = true;
    for (auto v : g[u])
      if (!used[v]) {
        dfs(v);
      }
  };
  long long ans = -n;
  rep(i, 2 * N) {
    if (!used[i]) {
      x = 0, y = 0;
      dfs(i);
      ans += (long long)x * y;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
  int n;
  scanf("%d", &n);
  int N = 101010;
  vector<vector<int>> g(2 * N);
  rep(i, n) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    g[x].push_back(y + N);
    g[y + N].push_back(x);
  }
  vector<bool> used(2 * N);
  int x = 0, y = 0;
  function<void(int)> dfs = [&](int u) {
    if (u < N)
      x++;
    else
      y++;
    used[u] = true;
    for (auto v : g[u])
      if (!used[v]) {
        dfs(v);
      }
  };
  long long ans = -n;
  rep(i, 2 * N) {
    if (!used[i]) {
      x = 0, y = 0;
      dfs(i);
      ans += (long long)x * y;
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p02998 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

const int V = 10005;

vector<int> to[V * 2];

vector<int> cnt;

vector<int> visited(V * 2);

void dfs(int v) {
  if (visited[v])
    return;
  visited[v] = true;
  cnt[v / V]++;
  for (auto u : to[v])
    dfs(u);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    y += V;
    to[x].push_back(y);
    to[y].push_back(x);
  }

  long long ans = 0;
  for (int i = 0; i < V * 2; i++) {
    if (visited[i])
      continue;
    cnt = vector<int>(2, 0);
    dfs(i);
    ans += (long long)cnt[0] * cnt[1];
  }

  ans -= n;

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

const int V = 100005;

vector<int> to[V * 2];

vector<int> cnt;

vector<int> visited(V * 2);

void dfs(int v) {
  if (visited[v])
    return;
  visited[v] = true;
  cnt[v / V]++;
  for (auto u : to[v])
    dfs(u);
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    y += V;
    to[x].push_back(y);
    to[y].push_back(x);
  }

  long long ans = 0;
  for (int i = 0; i < V * 2; i++) {
    if (visited[i])
      continue;
    cnt = vector<int>(2, 0);
    dfs(i);
    ans += (long long)cnt[0] * cnt[1];
  }

  ans -= n;

  cout << ans << endl;
}
Problem p02998 (C++)

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

static const int64_t MAX = 10;
static vector<bool> seen(MAX * 2, false);

pair<int64_t, int64_t> dfs(const Graph &g, int64_t v, bool isX = true) {
  if (seen[v])
    return {0, 0};
  seen[v] = true;

  pair<int64_t, int64_t> num = {0, 0};
  if (isX)
    num.first++;
  else
    num.second++;

  for (int64_t next_v : g[v]) {
    pair<int64_t, int64_t> child = dfs(g, next_v, !isX);
    num.first += child.first;
    num.second += child.second;
  }

  return num;
}

int main() {
  int64_t n;
  cin >> n;

  Graph g(MAX * 2);
  for (int64_t i = 0; i < n; i++) {
    int64_t x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y + MAX);
    g[y + MAX].push_back(x);
  }

  int64_t ans = 0;
  for (int64_t i = 0; i < MAX; i++) {
    pair<int64_t, int64_t> num = dfs(g, i);
    ans += num.first * num.second;
  }
  ans -= n;
  cout << ans << endl;

  return 0;
}

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

static const int64_t MAX = 1e5;
static vector<bool> seen(MAX * 2, false);

pair<int64_t, int64_t> dfs(const Graph &g, int64_t v, bool isX = true) {
  if (seen[v])
    return {0, 0};
  seen[v] = true;

  pair<int64_t, int64_t> num = {0, 0};
  if (isX)
    num.first++;
  else
    num.second++;

  for (int64_t next_v : g[v]) {
    pair<int64_t, int64_t> child = dfs(g, next_v, !isX);
    num.first += child.first;
    num.second += child.second;
  }

  return num;
}

int main() {
  int64_t n;
  cin >> n;

  Graph g(MAX * 2);
  for (int64_t i = 0; i < n; i++) {
    int64_t x, y;
    cin >> x >> y;
    x--;
    y--;
    g[x].push_back(y + MAX);
    g[y + MAX].push_back(x);
  }

  int64_t ans = 0;
  for (int64_t i = 0; i < MAX; i++) {
    pair<int64_t, int64_t> num = dfs(g, i);
    ans += num.first * num.second;
  }
  ans -= n;
  cout << ans << endl;

  return 0;
}
Problem p02998 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MAXNUM 111
#define rep(i, s, t) for (int i = s; i < t; i++)
#define pii pair<int, int>
typedef long long ll;
pii num[MAXNUM];
int dset[MAXNUM * 2], allx[MAXNUM], ally[MAXNUM], xsize, ysize;
int ssizex[MAXNUM * 2], ssizey[MAXNUM * 2];
int fa(int a) {
  if (dset[a] != a)
    return dset[a] = fa(dset[a]);
  return a;
}
int main() {
  int n, a, b;
  scanf("%d", &n);
  rep(i, 1, n + 1) scanf("%d%d", &a, &b), num[i] = {a, b}, allx[++xsize] = a,
                                          ally[++ysize] = b;
  sort(allx + 1, allx + xsize + 1), sort(ally + 1, ally + ysize + 1);
  xsize = unique(allx + 1, allx + xsize + 1) - allx - 1,
  ysize = unique(ally + 1, ally + ysize + 1) - ally - 1;
  rep(i, 1, xsize + ysize + 1) dset[i] = i;
  rep(i, 1, n + 1) {
    int k1 = lower_bound(allx + 1, allx + xsize + 1, num[i].first) - allx,
        k2 = lower_bound(ally + 1, ally + ysize + 1, num[i].second) - ally;
    dset[fa(k1)] = fa(k2 + xsize);
  }
  rep(i, 1, xsize + 1) ssizex[fa(i)]++;
  rep(i, 1, ysize + 1) ssizey[fa(i + xsize)]++;
  ll res = 0;
  rep(i, 1, xsize + ysize + 1) if (fa(i) == i) res +=
      ssizex[i] * 1ll * ssizey[i];
  printf("%lld\n", res - n);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MAXNUM 111111
#define rep(i, s, t) for (int i = s; i < t; i++)
#define pii pair<int, int>
typedef long long ll;
pii num[MAXNUM];
int dset[MAXNUM * 2], allx[MAXNUM], ally[MAXNUM], xsize, ysize;
int ssizex[MAXNUM * 2], ssizey[MAXNUM * 2];
int fa(int a) {
  if (dset[a] != a)
    return dset[a] = fa(dset[a]);
  return a;
}
int main() {
  int n, a, b;
  scanf("%d", &n);
  rep(i, 1, n + 1) scanf("%d%d", &a, &b), num[i] = {a, b}, allx[++xsize] = a,
                                          ally[++ysize] = b;
  sort(allx + 1, allx + xsize + 1), sort(ally + 1, ally + ysize + 1);
  xsize = unique(allx + 1, allx + xsize + 1) - allx - 1,
  ysize = unique(ally + 1, ally + ysize + 1) - ally - 1;
  rep(i, 1, xsize + ysize + 1) dset[i] = i;
  rep(i, 1, n + 1) {
    int k1 = lower_bound(allx + 1, allx + xsize + 1, num[i].first) - allx,
        k2 = lower_bound(ally + 1, ally + ysize + 1, num[i].second) - ally;
    dset[fa(k1)] = fa(k2 + xsize);
  }
  rep(i, 1, xsize + 1) ssizex[fa(i)]++;
  rep(i, 1, ysize + 1) ssizey[fa(i + xsize)]++;
  ll res = 0;
  rep(i, 1, xsize + ysize + 1) if (fa(i) == i) res +=
      ssizex[i] * 1ll * ssizey[i];
  printf("%lld\n", res - n);
}
Problem p02998 (C++)

Buggy submission (status: Runtime Error):
// Author: πα

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

const int N = 1e5 + 5;
vector<int> g[N];
bool vis[N];
int cl, cr, ce;

void dfs(int u) {
  if (vis[u])
    return;
  vis[u] = 1;
  if (u < N)
    cl++, ce += g[u].size();
  else
    cr++;
  for (auto v : g[u])
    dfs(v);
}

int main() {
  int n, u, v, i;
  long ans = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> u >> v;
    v += N;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (i = 1; i < N; ++i)
    if (not vis[i]) {
      cl = cr = ce = 0;
      dfs(i);
      ans += 1LL * cl * cr - ce;
    }
  cout << ans;
  return 0;
}


Fixed submission:
// Author: πα

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

const int N = 1e5 + 5;
vector<int> g[N + N];
bool vis[N + N];
int cl, cr, ce;

void dfs(int u) {
  if (vis[u])
    return;
  vis[u] = 1;
  if (u < N)
    cl++, ce += g[u].size();
  else
    cr++;
  for (auto v : g[u])
    dfs(v);
}

int main() {
  int n, u, v, i;
  long ans = 0;
  cin >> n;
  for (i = 0; i < n; ++i) {
    cin >> u >> v;
    v += N;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (i = 1; i < N; ++i)
    if (not vis[i]) {
      cl = cr = ce = 0;
      dfs(i);
      ans += 1LL * cl * cr - ce;
    }
  cout << ans;
  return 0;
}
Problem p02998 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

struct UnionFind {
  int size;
  vector<int> parent;

  UnionFind() {}
  UnionFind(int size) {
    this->size = size;
    parent.resize(size + 1);
    init();
  }
  void init() {
    for (int i = 0; i <= size; i++)
      parent[i] = i;
  }
  int root(int i) {
    if (parent[i] == i)
      return i;
    return parent[i] = root(parent[i]);
  }
  bool same(int i, int j) { return root(i) == root(j); }
  void unite(int i, int j) {
    int root_i = root(i), root_j = root(j);
    if (root_i == root_j)
      return;
    parent[root_i] = root_j;
  }
};

llint n;
llint x[100005], y[100005];
UnionFind uf(100005);
vector<llint> vec[100005], vecx[100005];
set<llint> S[100005];
llint cnt[100005];

int main(void) {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> x[i] >> y[i];

  for (int i = 1; i <= n; i++)
    vec[x[i]].push_back(y[i]);
  for (int i = 1; i <= n; i++)
    vecx[y[i]].push_back(x[i]);

  for (int i = 1; i < 100005; i++) {
    for (int j = 1; j < vec[i].size(); j++)
      uf.unite(vec[i][j - 1], vec[i][j]);
  }
  for (int i = 1; i < 100005; i++) {
    for (int j = 0; j < vec[i].size(); j++) {
      S[uf.root(i)].insert(vecx[i][j]);
    }
    cnt[uf.root(i)]++;
  }

  llint ans = 0;
  for (int i = 1; i < 100005; i++) {
    ans += S[i].size() * cnt[i];
  }
  ans -= n;
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

struct UnionFind {
  int size;
  vector<int> parent;

  UnionFind() {}
  UnionFind(int size) {
    this->size = size;
    parent.resize(size + 1);
    init();
  }
  void init() {
    for (int i = 0; i <= size; i++)
      parent[i] = i;
  }
  int root(int i) {
    if (parent[i] == i)
      return i;
    return parent[i] = root(parent[i]);
  }
  bool same(int i, int j) { return root(i) == root(j); }
  void unite(int i, int j) {
    int root_i = root(i), root_j = root(j);
    if (root_i == root_j)
      return;
    parent[root_i] = root_j;
  }
};

llint n;
llint x[100005], y[100005];
UnionFind uf(100005);
vector<llint> vec[100005], vecx[100005];
set<llint> S[100005];
llint cnt[100005];

int main(void) {
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> x[i] >> y[i];

  for (int i = 1; i <= n; i++)
    vec[x[i]].push_back(y[i]);
  for (int i = 1; i <= n; i++)
    vecx[y[i]].push_back(x[i]);

  for (int i = 1; i < 100005; i++) {
    for (int j = 1; j < vec[i].size(); j++)
      uf.unite(vec[i][j - 1], vec[i][j]);
  }
  for (int i = 1; i < 100005; i++) {
    for (int j = 0; j < vecx[i].size(); j++) {
      S[uf.root(i)].insert(vecx[i][j]);
    }
    cnt[uf.root(i)]++;
  }

  llint ans = 0;
  for (int i = 1; i < 100005; i++) {
    ans += S[i].size() * cnt[i];
  }
  ans -= n;
  cout << ans << endl;

  return 0;
}
Problem p02998 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
constexpr int MAX = 10005;

int n;
vector<vector<int>> to(MAX * 2);
vector<bool> visited(MAX * 2, false);
vector<ll> cnt(2, 0);
ll ret = 0;

void dfs(int v) {
  if (visited[v])
    return;
  visited[v] = true;
  cnt[v / MAX]++;
  for (int i = 0; i < to[v].size(); i++)
    dfs(to[v][i]);
  return;
}

int main(void) {
  cin >> n;
  for (size_t i = 0; i < n; i++) {
    int ai, bi;
    cin >> ai >> bi;
    bi += MAX;
    to[ai].push_back(bi);
    to[bi].push_back(ai);
  }
  ll ret = 0;
  for (int i = 0; i < MAX * 2; i++) {
    if (visited[i])
      continue;
    cnt = vector<ll>(2, 0);
    dfs(i);
    ret += ll(cnt[0] * cnt[1]);
  }
  ret -= n;
  cout << ret << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
constexpr int MAX = 100005;

int n;
vector<vector<int>> to(MAX * 2);
vector<bool> visited(MAX * 2, false);
vector<ll> cnt(2, 0);
ll ret = 0;

void dfs(int v) {
  if (visited[v])
    return;
  visited[v] = true;
  cnt[v / MAX]++;
  for (int i = 0; i < to[v].size(); i++)
    dfs(to[v][i]);
  return;
}

int main(void) {
  cin >> n;
  for (size_t i = 0; i < n; i++) {
    int ai, bi;
    cin >> ai >> bi;
    bi += MAX;
    to[ai].push_back(bi);
    to[bi].push_back(ai);
  }
  ll ret = 0;
  for (int i = 0; i < MAX * 2; i++) {
    if (visited[i])
      continue;
    cnt = vector<ll>(2, 0);
    dfs(i);
    ret += ll(cnt[0] * cnt[1]);
  }
  ret -= n;
  cout << ret << endl;
  return 0;
}
Problem p02998 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstdlib>

#include <iostream>

#include <algorithm>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint {
public:
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  mint &operator+=(const mint rhs) {
    x += rhs.x;
    while (x >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint rhs) {
    x -= rhs.x;
    while (x < 0)
      x += mod;
    return *this;
  }
  mint &operator*=(const mint rhs) {
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  friend ostream &operator<<(ostream &os, const mint rhs) {
    os << rhs.x;
    return os;
  }
};

#define rep(index, num) for (int index = 0; index < num; ++index)

const int V = 100000;
vector<int> to[V * 2];
bool visited[V * 2];
vector<int> cnt;

void dfs(int v) {
  if (visited[v])
    return;
  visited[v] = true;
  cnt[v / V]++;
  for (int u : to[v])
    dfs(u);
}

int main() {
  int n;
  std::cin >> n;
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    y += V;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  ll ans = 0;
  rep(i, V * 2) {
    if (visited[i])
      continue;
    cnt = vector<int>(2);
    dfs(i);
    ans += (ll)cnt[0] * cnt[1];
  }
  ans -= n;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstdlib>

#include <iostream>

#include <algorithm>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint {
public:
  ll x;
  mint(ll x = 0) : x(x % mod) {}
  mint &operator+=(const mint rhs) {
    x += rhs.x;
    while (x >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint rhs) {
    x -= rhs.x;
    while (x < 0)
      x += mod;
    return *this;
  }
  mint &operator*=(const mint rhs) {
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  friend ostream &operator<<(ostream &os, const mint rhs) {
    os << rhs.x;
    return os;
  }
};

#define rep(index, num) for (int index = 0; index < num; ++index)

const int V = 100005;
vector<int> to[V * 2];
bool visited[V * 2];
vector<int> cnt;

void dfs(int v) {
  if (visited[v])
    return;
  visited[v] = true;
  cnt[v / V]++;
  for (int u : to[v])
    dfs(u);
}

int main() {
  int n;
  std::cin >> n;
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    y += V;
    to[x].push_back(y);
    to[y].push_back(x);
  }
  ll ans = 0;
  rep(i, V * 2) {
    if (visited[i])
      continue;
    cnt = vector<int>(2);
    dfs(i);
    ans += (ll)cnt[0] * cnt[1];
  }
  ans -= n;
  cout << ans << endl;
  return 0;
}
Problem p02998 (C++)

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

typedef long long ll;

ll N;

map<ll, vector<ll>> XY;
// y, x
map<ll, ll> YX;

map<ll, ll> Par, Rank;

// root x, (#x's, ys)
map<ll, pair<ll, set<ll>>> Rect;
ll R;

ll find(ll x) {
  if (!Par.count(x))
    return x;
  return Par[x] = find(Par[x]);
}
void merge(ll x, ll x2) {
  x = find(x);
  x2 = find(x2);
  if (Rank[x] > Rank[x2]) {
    Par[x2] = x;
  } else {
    Par[x] = x2;
    if (Rank[x] == Rank[x2])
      ++Rank[x2];
  }
}
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll x, y;
    cin >> x >> y;
    XY[x].push_back(y);
  }
  for (const auto &x_ys : XY) {
    ll x = x_ys.first;
    for (ll y : x_ys.second) {
      if (YX.count(y))
        merge(x, YX[y]);
      YX[y] = x;
    }
  }
  for (const auto &x_ys : XY) {
    ll x = find(x_ys.first);
    ++Rect[x].first;
    for (ll y : x_ys.second)
      Rect[x].second.insert(y);
  }
  for (const auto &x_rect : Rect) {
    const auto &rect = x_rect.second;
    R += rect.first * rect.second.size();
  }
  R -= N;
  cout << R << endl;
  return 0;
}


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

typedef long long ll;

ll N;

map<ll, vector<ll>> XY;
// y, x
map<ll, ll> YX;

map<ll, ll> Par, Rank;

// root x, (#x's, ys)
map<ll, pair<ll, set<ll>>> Rect;
ll R;

ll find(ll x) {
  if (!Par.count(x))
    return x;
  return Par[x] = find(Par[x]);
}
void merge(ll x, ll x2) {
  x = find(x);
  x2 = find(x2);
  if (x == x2)
    return;
  if (Rank[x] > Rank[x2]) {
    Par[x2] = x;
  } else {
    Par[x] = x2;
    if (Rank[x] == Rank[x2])
      ++Rank[x2];
  }
}
int main() {
  cin >> N;
  for (ll i = 0; i < N; ++i) {
    ll x, y;
    cin >> x >> y;
    XY[x].push_back(y);
  }
  for (const auto &x_ys : XY) {
    ll x = x_ys.first;
    for (ll y : x_ys.second) {
      if (YX.count(y))
        merge(x, YX[y]);
      YX[y] = x;
    }
  }
  for (const auto &x_ys : XY) {
    ll x = find(x_ys.first);
    ++Rect[x].first;
    for (ll y : x_ys.second)
      Rect[x].second.insert(y);
  }
  for (const auto &x_rect : Rect) {
    const auto &rect = x_rect.second;
    R += rect.first * rect.second.size();
  }
  R -= N;
  cout << R << endl;
  return 0;
}
Problem p02998 (C++)

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

const int N = 1e5 + 5;

int fa[N];
int n1[N], n2[N];

vector<int> edge[N];

int Find(int v) { return v == fa[v] ? v : fa[v] == Find(fa[v]); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    m = max(m, max(u, v));
    edge[u].push_back(v);
  }
  for (int i = 1; i <= m; ++i) {
    fa[i] = i;
    n1[i] = 0;
    n2[i] = 1;
  }
  for (int i = 1; i <= m; ++i) {
    int len = edge[i].size();
    if (len == 0)
      continue;
    int pa = Find(edge[i][0]);
    n1[pa]++;
    for (int j = 1; j < len; ++j) {
      int v = edge[i][j];
      int pa2 = Find(v);
      if (pa != pa2) {
        fa[pa2] = pa;
        n1[pa] += n1[pa2];
        n2[pa] += n2[pa2];
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= m; ++i) {
    if (fa[i] == i) {
      ans += 1ll * n1[i] * n2[i];
    }
  }
  cout << ans - 1ll * n << endl;
  return 0;
}


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

const int N = 1e5 + 5;

int fa[N];
int n1[N], n2[N];

vector<int> edge[N];

int Find(int v) { return v == fa[v] ? v : fa[v] = Find(fa[v]); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int u, v;
    cin >> u >> v;
    m = max(m, max(u, v));
    edge[u].push_back(v);
  }
  for (int i = 1; i <= m; ++i) {
    fa[i] = i;
    n1[i] = 0;
    n2[i] = 1;
  }
  for (int i = 1; i <= m; ++i) {
    int len = edge[i].size();
    if (len == 0)
      continue;
    int pa = Find(edge[i][0]);
    n1[pa]++;
    for (int j = 1; j < len; ++j) {
      int v = edge[i][j];
      int pa2 = Find(v);
      if (pa != pa2) {
        fa[pa2] = pa;
        n1[pa] += n1[pa2];
        n2[pa] += n2[pa2];
      }
    }
  }
  ll ans = 0;
  for (int i = 1; i <= m; ++i) {
    if (fa[i] == i) {
      ans += 1ll * n1[i] * n2[i];
    }
  }
  cout << ans - 1ll * n << endl;
  return 0;
}
Problem p02999 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main(void) {
  int x, a, result;
  scanf("%d %d", x, a);
  if (x < a)
    result = 0;
  else
    result = 10;
  printf("%d", result);
  return 0;
}


Fixed submission:
#include <stdio.h>

int main(void) {
  int x, a, result;
  scanf("%d %d", &x, &a);
  if (x < a)
    result = 0;
  else
    result = 10;
  printf("%d", result);
  return 0;
}
Problem p02999 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok ? "Yes" : "No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int main() {
  int x, a;
  cin >> x >> a;
  cout << x / a * 10 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok ? "Yes" : "No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
// clang++ -std=c++11 -stdlib=libc++

int main() {
  int x, a;
  cin >> x >> a;
  int ans = 10;
  if (x < a)
    ans = 0;
  cout << ans << endl;
  return 0;
}
Problem p02999 (C++)

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

int main() {
  int X, A;
  cin >> X >> A;
  cout << X / A * 10 << endl;
}

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

int main() {
  int X, A;
  cin >> X >> A;
  if (X < A) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }
}
Problem p02999 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  cout << ((int)(a / b) * 10) << endl;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;

  cout << (a >= b ? 10 : 0) << endl;
}
Problem p02999 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int a, x;
  scanf("%d %d", a, x);
  if (x < a) {
    printf("0");
  } else {
    printf("10");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int a, x;
  scanf("%d %d", &a, &x);
  if (x > a) {
    printf("0");
  } else {
    printf("10");
  }
  return 0;
}
Problem p02999 (C++)

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

int main(void) {
  int X, A;

  cin >> X >> A;
  cout << ((X / A) ? 1 : 0) * 10 << endl;
  return 0;
}


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

int main(void) {
  int X, A;

  cin >> X >> A;

  if (X < A)
    cout << "0\n";
  else
    cout << "10\n";
  return 0;
}
Problem p02999 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int x, a;
  cin >> x >> a;
  if (x / a == 0) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main() {
  int x, a;
  cin >> x >> a;
  if (a == 0) {
    cout << 10 << endl;
  } else if (x / a == 0) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }
}
Problem p02999 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int a, b;

int main() {
  cin >> a >> b;
  cout << min(1, a / b) * 10 << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};

int a, b;

int main() {
  cin >> a >> b;
  if (a >= b)
    cout << 10 << endl;
  else
    cout << 0 << endl;
}
Problem p02999 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
  if (atoi(argv[1]) < atoi(argv[2])) {
    cout << 0;
  } else {
    cout << 10;
  }

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
  int x, a;
  cin >> x >> a;
  if (x < a) {
    cout << 0;
  } else {
    cout << 10;
  }

  return 0;
}
Problem p02999 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define sz(c) int(c.size())
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);

  int x, a;
  cin >> x >> a;
  cout << (x / a) * 10 << "\n";
}


Fixed submission:
#include <bits/stdc++.h>
#define sz(c) int(c.size())
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = (b)-1; i >= (a); --i)
using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);

  int x, a;
  cin >> x >> a;
  cout << (x >= a) * 10 << "\n";
}
Problem p02999 (Python)

Buggy submission (status: Runtime Error):
x, a = map(int, input())

if x < a:
    print("0")

if x >= a:
    print("10")


Fixed submission:
x, a = map(int, input().split())

if x < a:
    print("0")

if x >= a:
    print("10")
Problem p02999 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-

x, a = int(input()), int(input())

if x < a:
    print("0")
else:
    print("10")


Fixed submission:
# -*- coding: utf-8 -*-

x, a = map(int, input().split())

if x < a:
    print("0")
else:
    print("10")
Problem p02999 (Python)

Buggy submission (status: Runtime Error):
X, A = int(input().split(""))
if X < A:
    print(0)
else:
    print(10)


Fixed submission:
X, A = map(int, input().split(" "))
if X < A:
    print(0)
else:
    print(10)
Problem p02999 (Python)

Buggy submission (status: Runtime Error):
X, A = map(int, input())
if X < A:
    print(0)
else:
    print(10)


Fixed submission:
X, A = map(int, input().split())
if X < A:
    print(0)
else:
    print(10)
Problem p02999 (Python)

Buggy submission (status: Runtime Error):
x, a = list(input())
print("100"[x >= a :: 2])


Fixed submission:
x, a = map(int, input().split())
print(int("100"[x < a :: 2]))
Problem p02999 (Python)

Buggy submission (status: Runtime Error):
x, a = map(int, input())
if x < a:
    print(0)
else:
    print(10)


Fixed submission:
# A Rounding

x, a = map(int, input().split())
if x < a:
    print(0)
else:
    print(10)
Problem p02999 (Python)

Buggy submission (status: Runtime Error):
x, a = map(int, input())
if x < a:
    print(0)
else:
    print(10)


Fixed submission:
x, a = map(int, input().split())
if x < a:
    print(0)
else:
    print(10)
Problem p03000 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, x;
  cin >> n >> x;

  vector<ll> l(n);
  for (ll i = 0; i < n; i++)
    cin >> l[i];

  vector<ll> d(n + 1);
  d[0] = 0;
  for (ll i = 1; i < n + 1; i++)
    d[i] = d[i - 1] + l[i - 1];

  ll ind = 0;
  for (; d[ind] <= x; ++ind)
    continue;

  cout << ind << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char *argv[]) {

  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, x;
  cin >> n >> x;

  vector<ll> l(n);
  for (ll i = 0; i < n; i++)
    cin >> l[i];

  vector<ll> d(n + 1);
  d[0] = 0;
  for (ll i = 1; i < n + 1; i++)
    d[i] = d[i - 1] + l[i - 1];

  ll ind = 0;
  for (; d[ind] <= x && ind < n + 1; ++ind)
    continue;

  cout << ind << endl;

  return 0;
}