prithivMLmods/Coder-Stat huggingface dataset:
Problem p03112 (Python)

Buggy submission (status: Runtime Error):
from bisect import bisect_right

A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
    x = int(input())
    b, d = bisect_right(s, x), bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)


Fixed submission:
from bisect import bisect_right

A, B, Q = map(int, input().split())
INF = 10**18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
xs = [int(input()) for i in range(Q)]
for x in xs:
    b, d = bisect_right(s, x), bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)
Problem p03112 (Python)

Buggy submission (status: Runtime Error):
def p_d():
    from bisect import bisect_right

    A, B, Q = map(int, input().split())
    INF = 10**9
    s = [-INF] + [int(input()) for _ in range(A)] + [INF]
    t = [-INF] + [int(input()) for _ in range(B)] + [INF]
    ans = []
    for _ in range(Q):
        x = int(input())
        b, d = bisect_right(s, x), bisect_right(t, x)
        res = INF
        for S in [s[b - 1], s[b]]:
            for T in [t[d - 1], t[d]]:
                d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
                res = min((d1, d2, res))
        ans.append(str(res))
    print("\n".join(ans))


if __name__ == "__main__":
    p_d()


Fixed submission:
def p_d():
    from bisect import bisect_right

    A, B, Q = map(int, input().split())
    INF = 10**18
    s = [-INF] + [int(input()) for _ in range(A)] + [INF]
    t = [-INF] + [int(input()) for _ in range(B)] + [INF]
    ans = []
    for _ in range(Q):
        x = int(input())
        b, d = bisect_right(s, x), bisect_right(t, x)
        res = INF
        for S in [s[b - 1], s[b]]:
            for T in [t[d - 1], t[d]]:
                d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
                res = min((d1, d2, res))
        ans.append(str(res))
    print("\n".join(ans))


if __name__ == "__main__":
    p_d()
Problem p03112 (Python)

Buggy submission (status: Runtime Error):
import bisect


def solve(a_list, b_list, position):
    # time O(log(A))
    a_right_key = bisect.bisect_left(a_list, position)
    a_left_key = a_right_key - 1
    # time O(log(B))
    b_right_key = bisect.bisect_left(b_list, position)
    b_left_key = b_right_key - 1

    a_left, a_right = a_list[a_left_key], a_list[a_right_key]
    b_left, b_right = b_list[b_left_key], b_list[b_right_key]

    ans = 10**20
    for a_position in [a_left, a_right]:
        for b_position in [b_left, b_right]:
            distance1 = abs(position - a_position) + abs(a_position - b_position)
            distance2 = abs(position - b_position) + abs(a_position - b_position)
            ans = min(ans, distance1, distance2)
    return ans


def main():
    inf = 10**20
    A, B, Q = map(int, input().split())

    # time O(A)
    a_list = [int(input()) for _ in range(A)]
    a_list = [-inf] + a_list + [inf]
    # time O(B)
    b_list = [int(input()) for _ in range(A)]
    b_list = [-inf] + b_list + [inf]

    # time O(Q (log(A) + log(B))
    for _ in range(Q):
        position = int(input())
        ans = solve(a_list, b_list, position)
        print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import bisect


def solve(a_list, b_list, position):
    # time O(log(A))
    a_right_key = bisect.bisect_left(a_list, position)
    a_left_key = a_right_key - 1
    # time O(log(B))
    b_right_key = bisect.bisect_left(b_list, position)
    b_left_key = b_right_key - 1

    a_left, a_right = a_list[a_left_key], a_list[a_right_key]
    b_left, b_right = b_list[b_left_key], b_list[b_right_key]

    ans = 10**20
    for a_position in [a_left, a_right]:
        for b_position in [b_left, b_right]:
            distance1 = abs(position - a_position) + abs(a_position - b_position)
            distance2 = abs(position - b_position) + abs(a_position - b_position)
            ans = min(ans, distance1, distance2)
    return ans


def main():
    inf = 10**20
    A, B, Q = map(int, input().split())

    # time O(A)
    a_list = [int(input()) for _ in range(A)]
    a_list = [-inf] + a_list + [inf]
    # time O(B)
    b_list = [int(input()) for _ in range(B)]
    b_list = [-inf] + b_list + [inf]

    # time O(Q (log(A) + log(B))
    for _ in range(Q):
        position = int(input())
        ans = solve(a_list, b_list, position)
        print(ans)


if __name__ == "__main__":
    main()
Problem p03112 (C++)

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

long long INF = 1LL << 60;

long long calc(vector<long long> s, vector<long long> t, long long x) {

  long long answer = INF;

  auto a_ = lower_bound(s.begin(), s.end(), x);

  for (int i = 0; i < 2; i++) {

    long long ax_ = *prev(a_);

    if (i == 1) {
      ax_ = *a_;
    }

    auto b_ = lower_bound(t.begin(), t.end(), ax_);

    long long bxl_ = *prev(b_);
    long long bxr_ = *b_;

    if (0 < ax_ && 0 < bxl_) {
      answer = min(answer, abs(ax_ - x) + abs(bxl_ - ax_));
    }

    if (0 < ax_ && 0 < bxr_) {
      answer = min(answer, abs(ax_ - x) + abs(bxr_ - ax_));
    }
  }

  return answer;
}

int main() {

  int A, B, Q;
  cin >> A >> B >> Q;

  vector<long long> s;
  s.push_back(0);
  for (int i = 1; i <= A; i++) {
    long long s_;
    cin >> s_;
    s.push_back(s_);
  }
  s.push_back(INF);

  vector<long long> t(B + 2);
  t.push_back(0);
  for (int i = 1; i <= B; i++) {
    long long t_;
    cin >> t_;
    t.push_back(t_);
  }
  t.push_back(INF);

  vector<long long> x(Q);
  for (int i = 0; i < Q; i++) {
    cin >> x[i];
  }

  for (int i = 0; i < Q; i++) {

    long long answer = INF;

    answer = min(calc(s, t, x[i]), calc(t, s, x[i]));

    cout << answer << endl;
  }
}

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

long long INF = 1LL << 60;

long long calc(vector<long long> &s, vector<long long> &t, long long x) {

  long long answer = INF;

  auto a_ = lower_bound(s.begin(), s.end(), x);

  for (int i = 0; i < 2; i++) {

    long long ax_ = *prev(a_);

    if (i == 1) {
      ax_ = *a_;
    }

    auto b_ = lower_bound(t.begin(), t.end(), ax_);

    long long bxl_ = *prev(b_);
    long long bxr_ = *b_;

    if (0 < ax_ && 0 < bxl_) {
      answer = min(answer, abs(ax_ - x) + abs(bxl_ - ax_));
    }

    if (0 < ax_ && 0 < bxr_) {
      answer = min(answer, abs(ax_ - x) + abs(bxr_ - ax_));
    }
  }

  return answer;
}

int main() {

  int A, B, Q;
  cin >> A >> B >> Q;

  vector<long long> s;
  s.push_back(0);
  for (int i = 1; i <= A; i++) {
    long long s_;
    cin >> s_;
    s.push_back(s_);
  }
  s.push_back(INF);

  vector<long long> t(B + 2);
  t.push_back(0);
  for (int i = 1; i <= B; i++) {
    long long t_;
    cin >> t_;
    t.push_back(t_);
  }
  t.push_back(INF);

  vector<long long> x(Q);
  for (int i = 0; i < Q; i++) {
    cin >> x[i];
  }

  for (int i = 0; i < Q; i++) {

    long long answer = INF;

    answer = min(calc(s, t, x[i]), calc(t, s, x[i]));

    cout << answer << endl;
  }
}
Problem p03112 (C++)

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

int main() {
  int A, B, Q;
  ll x;
  cin >> A >> B >> Q;
  ll s[A], t[B], ans[Q];
  rep(i, A) cin >> s[i];
  rep(i, B) cin >> t[i];
  rep(i, Q) {
    cin >> x;
    int su = lower_bound(s, s + A, x) - s;
    int tu = lower_bound(t, s + B, x) - t;
    ll d[4];
    rep(i, 4) d[i] = INF;
    if (su < A && tu < B)
      d[0] = max(s[su] - x, t[tu] - x);
    if (su < A && tu > 0)
      d[1] =
          min(s[su] - x + 2 * (x - t[tu - 1]), 2 * (s[su] - x) + x - t[tu - 1]);
    if (su > 0 && tu < B)
      d[2] =
          min(x - s[su - 1] + 2 * (t[tu] - x), 2 * (x - s[su - 1]) + t[tu] - x);
    if (su > 0 && tu > 0)
      d[3] = max(x - s[su - 1], x - t[tu - 1]);
    sort(d, d + 4);
    ans[i] = d[0];
  }
  rep(i, Q) cout << ans[i] << endl;
  return 0;
}


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

int main() {
  int A, B, Q;
  ll x;
  cin >> A >> B >> Q;
  ll s[A], t[B], ans[Q];
  rep(i, A) cin >> s[i];
  rep(i, B) cin >> t[i];
  rep(i, Q) {
    cin >> x;
    int su = lower_bound(s, s + A, x) - s;
    int tu = lower_bound(t, t + B, x) - t;
    ll d[4];
    rep(i, 4) d[i] = INF;
    if (su < A && tu < B)
      d[0] = max(s[su] - x, t[tu] - x);
    if (su < A && tu > 0)
      d[1] =
          min(s[su] - x + 2 * (x - t[tu - 1]), 2 * (s[su] - x) + x - t[tu - 1]);
    if (su > 0 && tu < B)
      d[2] =
          min(x - s[su - 1] + 2 * (t[tu] - x), 2 * (x - s[su - 1]) + t[tu] - x);
    if (su > 0 && tu > 0)
      d[3] = max(x - s[su - 1], x - t[tu - 1]);
    sort(d, d + 4);
    ans[i] = d[0];
  }
  rep(i, Q) cout << ans[i] << endl;
  return 0;
}
Problem p03113 (Python)

Buggy submission (status: Runtime Error):
def solve(n, k, aaa):
    buf = []
    prev_last = -1

    for t in range(k + 1):
        ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
        others = set(range(1, n + 1)) - {prev_last, mi}
        buf.extend(others)
        if t == k:
            aaa[mi] += 1
        else:
            buf.append(mi)

        for i in range(n):
            if i + 1 != prev_last:
                aaa[i] -= 1
                if aaa[i] < 0:
                    print(-1)
                    return

        prev_last = mi

    print(len(buf))
    print(*buf)


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)


Fixed submission:
def solve(n, k, aaa):
    buf = []
    prev_last = -1

    for t in range(k + 1):
        ma, mi = min((a, i + 1) for i, a in enumerate(aaa) if i + 1 != prev_last)
        others = set(range(1, n + 1)) - {prev_last, mi}
        buf.extend(others)
        buf.append(mi)
        # print(buf)

        for i in range(n):
            if i + 1 != prev_last:
                aaa[i] -= 1
                if aaa[i] < 0:
                    print(-1)
                    return

        prev_last = mi

    print(len(buf))
    print(*buf)


n, k = map(int, input().split())
aaa = list(map(int, input().split()))
solve(n, k, aaa)
Problem p03115 (C++)

Buggy submission (status: Time Limit Exceeded):
%:pragma GCC optimize("Ofast", "inline")
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i++)
#define re0(i, n) for (rint i = 0; i < (int)n; i++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template <typename tp> inline void read(tp &x) {
  x = 0;
  char c = getchar();
  int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f)
    x = -x;
}
#define int long long
const int N = 1e5 + 233;
const int inf = -5e17;
int n, x[N], y[N], qy;

signed main(void) {
  srand(20021214);
  read(n);
  rep(i, n) read(x[i]), read(y[i]);
  auto isBlack = [&](int o) {
    bool pa = 0;
    rep(i, n) if (y[i] <= o && o <= x[i] + y[i] - inf) {
      int nc = x[i] - inf;
      int mc = o - y[i];
      pa ^= nc == (nc | mc);
    }
    return pa;
  };
  while (!isBlack(qy = (y[rand() % n + 1] + rand() % 10)))
    ;
  for (int k = 61; k >= 0; k--) {
    if (isBlack(qy + (1ll << k))) {
      qy |= 1ll << k;
    }
  }
  cout << qy + inf << "\n";
}


Fixed submission:
%:pragma GCC optimize("Ofast", "inline")
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= (n); i++)
#define re0(i, n) for (rint i = 0; i < (int)n; i++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template <typename tp> inline void read(tp &x) {
  x = 0;
  char c = getchar();
  int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar())
    ;
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar())
    ;
  if (f)
    x = -x;
}
#define int long long
const int N = 1e5 + 233;
const int inf = -5e17;
int n, x[N], y[N], qy;

signed main(void) {
  srand(20021214);
  read(n);
  rep(i, n) read(x[i]), read(y[i]);
  auto isBlack = [&](int o) {
    bool pa = 0;
    rep(i, n) if (y[i] <= o && o <= x[i] + y[i] - inf) {
      int nc = x[i] - inf;
      int mc = o - y[i];
      pa ^= nc == (nc | mc);
    }
    return pa;
  };
  while (!isBlack(qy = rand() % 10))
    ;
  for (int k = 61; k >= 0; k--) {
    if (isBlack(qy + (1ll << k))) {
      qy |= 1ll << k;
    }
  }
  cout << qy + inf << "\n";
}
Problem p03115 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
using namespace std;
typedef long long ll;
int n;
ll x[100001], y[100001];
ll px[200001], py[200001];
bool pz[200001];
ll tae(ll x, ll y, int id) { // y<2^59
  if (x == px[id] && y == py[id])
    return pz[id];
  bool eq = 1, sm = 0;
  for (int i = 58; i >= 0; i--) {
    if ((x & (1LL << i))) {
      if ((y & (1LL << i)))
        sm = eq;
      else {
        sm ^= eq;
        eq = 0;
      }
    } else {
      if ((y & (1LL << i)))
        sm = 0;
    }
  }
  px[id] = x, py[id] = y, pz[id] = (eq ^ sm);
  return eq ^ sm;
}
int qry(ll l, ll r) {
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    ll ty = y[i] + (1LL << 58);
    ll xl = max(0LL, l - x[i]);
    ll xr = min(ty, r - x[i]);
    if (xl > xr)
      continue;
    sum ^= tae(xr, ty, i * 2 - 1) % 2;
    if (xl != x[i])
      sum ^= tae(xl - 1, ty, i * 2);
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
  }
  ll l = -1.232323e17, r = 1.0669e17;
  while (l != r) {
    ll mid = l + (r - l) / 2;
    int sum = qry(l, mid);
    if (sum % 2 == 0)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << endl;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
using namespace std;
typedef long long ll;
int n;
ll x[100001], y[100001];
ll px[200001], py[200001];
bool pz[200001];
ll tae(ll x, ll y, int id) { // y<2^59
  if (x == px[id] && y == py[id])
    return pz[id];
  bool eq = 1, sm = 0;
  for (int i = 58; i >= 0; i--) {
    if (eq == 0 && sm == 0)
      break;
    if ((x & (1LL << i))) {
      if ((y & (1LL << i)))
        sm = eq;
      else {
        sm ^= eq;
        eq = 0;
      }
    } else {
      if ((y & (1LL << i)))
        sm = 0;
    }
  }
  px[id] = x, py[id] = y, pz[id] = (eq ^ sm);
  return eq ^ sm;
}
int qry(ll l, ll r) {
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    ll ty = y[i] + (1LL << 58);
    ll xl = max(0LL, l - x[i]);
    ll xr = min(ty, r - x[i]);
    if (xl > xr)
      continue;
    sum ^= tae(xr, ty, i * 2 - 1) % 2;
    if (xl != x[i])
      sum ^= tae(xl - 1, ty, i * 2);
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
  }
  ll l = -1.232323e17, r = 1.0669e17;
  while (l != r) {
    ll mid = l + (r - l) / 2;
    int sum = qry(l, mid);
    if (sum % 2 == 0)
      l = mid + 1;
    else
      r = mid;
  }
  cout << l << endl;
}
Problem p03116 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mkp make_pair
#define pin pair<int, int>
pin solve(V<pin> &ab, int ex) {
  if (!ex) {
    return mkp(1, 0);
  }
  V<V<pin>> qab(2);
  int sz = ab.size();
  qab[0].reserve(sz);
  qab[1].reserve(sz);
  for (pin x : ab) {
    qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
    if (x.first & 1) {
      qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2));
    }
  }
  V<vel> c(2, vel(2));
  rep(i, 2) {
    for (pin x : qab[i]) {
      int qc = (2 * x.first + x.second) % 3;
      c[i][0] ^= ((qc + 1) & 1);
      c[i][1] ^= (qc & 1);
    }
  }
  rep(i, 2) {
    if (!c[1 - i][0] && !c[1 - i][1]) {
      pin ans = solve(qab[i], ex - 1);
      ans.first *= 2;
      ans.second *= 2;
      ans.second += i;
      return ans;
    }
  }
  for (pin &v : ab) {
    v.first++;
  }
  pin ans = solve(ab, ex);
  ans.first--;
  return ans;
}
signed main() {
  long long inf = 2e17;
  int n;
  scanf("%lld", &n);
  V<pin> ab(n);
  rep(i, n) {
    long long a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    ab[i] = {a + inf, b + inf};
  }
  pin ret = solve(ab, 70);
  cout << ret.first - inf << " " << ret.second - inf << "\n";
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mkp make_pair
#define pin pair<int, int>
pin solve(V<pin> &ab, int ex) {
  if (!ex) {
    return mkp(1, 0);
  }
  V<V<pin>> qab(2);
  int sz = ab.size();
  qab[0].reserve(sz);
  qab[1].reserve(sz);
  for (pin x : ab) {
    qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
    if (x.first & 1) {
      qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2));
    }
  }
  V<vel> c(2, vel(2));
  rep(i, 2) {
    for (pin x : qab[i]) {
      int qc = (2 * x.first + x.second) % 3;
      c[i][0] ^= ((qc + 1) & 1);
      if (qc) {
        c[i][1] ^= 1;
      }
    }
  }
  rep(i, 2) {
    if (!c[1 - i][0] && !c[1 - i][1]) {
      pin ans = solve(qab[i], ex - 1);
      ans.first *= 2;
      ans.second *= 2;
      ans.second += i;
      return ans;
    }
  }
  for (pin &v : ab) {
    v.first++;
  }
  pin ans = solve(ab, ex);
  ans.first--;
  return ans;
}
signed main() {
  long long inf = 2e17;
  int n;
  scanf("%lld", &n);
  V<pin> ab(n);
  rep(i, n) {
    long long a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    ab[i] = {a + inf, b + inf};
  }
  pin ret = solve(ab, 70);
  cout << ret.first - inf << " " << ret.second - inf << "\n";
}
Problem p03116 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
L E = 70;
W S(V<W> p) {
  if (!E) {
    return {1, 0};
  }
  V<V<W>> T(2);
  for (W x : p) {
    T[x[1] & 1].push_back({x[0] / 2, x[1] / 2});
    if (x[0] & 1) {
      T[(x[1] + 1) & 1].push_back({x[0] / 2, (x[1] + 1) / 2});
    }
  }
  for (L i; i < 2; i++) {
    L c = 0;
    for (W x : T[!i]) {
      L Q = (2 * x[0] + x[1]) % 3;
      c ^= Q + 1;
    }
    if (!c) {
      E--;
      W A = S(T[i]);
      A[0] *= 2;
      A[1] *= 2;
      A[1] += i;
      return A;
    }
  }
  for (W &v : p) {
    v[0]++;
  }
  W A = S(p);
  A[0]--;
  return A;
}
int main() {
  L M = 2e17, n, a, b;
  cin >> n;
  V<W> p;
  while (n--) {
    cin >> a >> b;
    p[n] = {a + M, b + M};
  }
  W x = S(p);
  cout << x[0] - M << " " << x[1] - M;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define V vector
#define L long
#define W V<L>
L E = 70;
W S(V<W> p) {
  if (!E) {
    return {1, 0};
  }
  V<V<W>> T(2);
  for (W x : p) {
    T[x[1] & 1].push_back({x[0] / 2, x[1] / 2});
    if (x[0] & 1) {
      T[(x[1] + 1) & 1].push_back({x[0] / 2, (x[1] + 1) / 2});
    }
  }
  for (L i; i < 2; i++) {
    L c = 0;
    for (W x : T[!i]) {
      L Q = (2 * x[0] + x[1]) % 3;
      c ^= Q + 1;
    }
    if (!c) {
      E--;
      W A = S(T[i]);
      A[0] *= 2;
      A[1] *= 2;
      A[1] += i;
      return A;
    }
  }
  for (W &v : p) {
    v[0]++;
  }
  W A = S(p);
  A[0]--;
  return A;
}
int main() {
  L M = 2e17, n, a, b;
  cin >> n;
  V<W> p(n);
  while (n--) {
    cin >> a >> b;
    p[n] = {a + M, b + M};
  }
  W x = S(p);
  cout << x[0] - M << " " << x[1] - M;
}
Problem p03116 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mkp make_pair
#define pin pair<int, int>
pin solve(V<pin> &ab, int ex) {
  if (!ex) {
    return mkp(1, 0);
  }
  V<V<pin>> qab(2);
  int sz = ab.size();
  qab[0].reserve(sz);
  qab[1].reserve(sz);
  for (pin &x : ab) {
    qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
    if (x.first & 1) {
      qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2));
    }
  }
  rep(i, 2) {
    int c;
    for (pin &x : qab[1 - i]) {
      int qc = (2 * x.first + x.second) % 3;
      c ^= (qc + 1);
    }
    if (!c) {
      pin ans = solve(qab[i], ex - 1);
      ans.first *= 2;
      ans.second *= 2;
      ans.second += i;
      return ans;
    }
  }
  for (pin &v : ab) {
    v.first++;
  }
  pin ans = solve(ab, ex);
  ans.first--;
  return ans;
}
signed main() {
  long long inf = 2e17;
  int n;
  scanf("%lld", &n);
  V<pin> ab(n);
  rep(i, n) {
    long long a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    ab[i] = {a + inf, b + inf};
  }
  pin ret = solve(ab, 70);
  cout << ret.first - inf << " " << ret.second - inf << "\n";
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
#define int long long
#define V vector
#define vel V<int>
#define rep(i, n) for (int i = 0; i < n; i++)
#define mkp make_pair
#define pin pair<int, int>
pin solve(V<pin> &ab, int ex) {
  if (!ex) {
    return mkp(1, 0);
  }
  V<V<pin>> qab(2);
  int sz = ab.size();
  qab[0].reserve(sz);
  qab[1].reserve(sz);
  for (pin &x : ab) {
    qab[x.second & 1].push_back(mkp(x.first / 2, x.second / 2));
    if (x.first & 1) {
      qab[(x.second + 1) & 1].push_back(mkp(x.first / 2, (x.second + 1) / 2));
    }
  }
  rep(i, 2) {
    int c = 0;
    for (pin &x : qab[1 - i]) {
      int qc = (2 * x.first + x.second) % 3;
      c ^= (qc + 1);
    }
    if (!c) {
      pin ans = solve(qab[i], ex - 1);
      ans.first *= 2;
      ans.second *= 2;
      ans.second += i;
      return ans;
    }
  }
  for (pin &v : ab) {
    v.first++;
  }
  pin ans = solve(ab, ex);
  ans.first--;
  return ans;
}
signed main() {
  long long inf = 2e17;
  int n;
  scanf("%lld", &n);
  V<pin> ab(n);
  rep(i, n) {
    long long a, b;
    scanf("%lld", &a);
    scanf("%lld", &b);
    ab[i] = {a + inf, b + inf};
  }
  pin ret = solve(ab, 70);
  cout << ret.first - inf << " " << ret.second - inf << "\n";
}
Problem p03125 (C++)

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


Fixed submission:
#include <stdio.h>
int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);
  if (b % a == 0) {
    printf("%d\n", a + b);
  } else {
    printf("%d\n", b - a);
  }
  return 0;
}
Problem p03125 (C++)

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

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  int a, b;
  cin >> a >> b;
  if (b % a == 0)
    cout << b + a;
  else
    cout << b - a;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if (b % a == 0)
    cout << b + a;
  else
    cout << b - a;
  return 0;
}
Problem p03125 (C++)

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

using namespace std;

int A, B, C;

int main() {
  if (B % A) {
    C = B - A;
  } else {
    C = B + A;
  }
  printf("%d\n", C);
}

Fixed submission:
#include <cstdio>

using namespace std;

int A, B, C;

int main() {
  scanf("%d %d", &A, &B);

  if (B % A) {
    C = B - A;
  } else {
    C = B + A;
  }
  printf("%d\n", C);
}
Problem p03125 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int a, b;
  cin >> b >> a;
  if (a % b == 0)
    cout << a + b << endl;
  else
    cout << a - b << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {

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

  int a, b;
  cin >> b >> a;
  if (a % b == 0)
    cout << a + b << endl;
  else
    cout << a - b << endl;
  return 0;
}
Problem p03125 (C++)

Buggy submission (status: Runtime Error):
/*************************************************************************
    > File Name: A.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年02月16日 星期六 20时04分07秒
 ************************************************************************/

#include <iostream>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
#endif
  int a, b;
  cin >> a >> b;
  if (b % a == 0) {
    cout << a + b << endl;
  } else {
    cout << b - a << endl;
  }
  return 0;
}


Fixed submission:
/*************************************************************************
    > File Name: A.cc
    > Author: sqwlly
    > Mail: sqw.lucky@gmail.com
    > Created Time: 2019年02月16日 星期六 20时04分07秒
 ************************************************************************/

#include <iostream>

#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

using namespace std;

int main() {

  int a, b;
  cin >> a >> b;
  if (b % a == 0) {
    cout << a + b << endl;
  } else {
    cout << b - a << endl;
  }
  return 0;
}
Problem p03125 (C++)

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

int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;

  if (A % B == 0) {
    if (op == "+") {
      cout << A + B << endl;
    }
  } else {
    cout << B - A << endl;
  }
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if (B % A == 0) {
    cout << A + B << endl;
  } else {
    cout << B - A << endl;
  }
}
Problem p03125 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
b = int(input())
r = a + b if b % a == 0 else b - a
print(r)


Fixed submission:
a, b = list(map(int, input().split()))
r = a + b if b % a == 0 else b - a
print(r)
Problem p03125 (C++)

Buggy submission (status: Runtime Error):
/***
 *          ___           ___
 *         /\  \         /\  \                                     _____
 *         \:\  \        \:\  \                                   /::\  \       ___
 * ___
 *          \:\  \        \:\  \                                 /:/\:\  \     /\__\
 * /\__\
 *      _____\:\  \   ___  \:\  \   ___     ___   ___     ___   /:/
 * /::\__\   /:/__/        /:/  /
 *     /::::::::\__\ /\  \  \:\__\ /\  \   /\__\ /\  \   /\__\ /:/_/:/\:|__|
 * /::\  \       /:/__/
 *     \:\~~\~~\/__/ \:\  \ /:/  / \:\  \ /:/  / \:\  \ /:/  / \:\/:/ /:/  /
 * \/\:\  \__   /::\  \
 *      \:\  \        \:\  /:/  /   \:\  /:/  /   \:\  /:/  /   \::/_/:/  /
 * ~~\:\/\__\ /:/\:\  \
 *       \:\  \        \:\/:/  /     \:\/:/  /     \:\/:/  /     \:\/:/  / \::/
 * / \/__\:\  \
 *        \:\__\        \::/  /       \::/  /       \::/  /       \::/  / /:/  /
 * \:\__\
 *         \/__/         \/__/         \/__/         \/__/         \/__/ \/__/
 * \/__/
 *
 *      @author      : Dylan Dsouza (dsouzadyn@gmail.com)
 *      @created     : Saturday Feb 16, 2019 22:47:36 IST
 */
#include <bits/stdc++.h>

using namespace std;

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

#ifndef ONLINE_JUDGE
  freopen("in.txt", "rt", stdin);
#endif

  int A, B;
  cin >> A >> B;
  if (B % A == 0) {
    cout << A + B << endl;
  } else {
    cout << B - A << endl;
  }

  return 0;
}


Fixed submission:
/***
 *          ___           ___
 *         /\  \         /\  \                                     _____
 *         \:\  \        \:\  \                                   /::\  \       ___
 * ___
 *          \:\  \        \:\  \                                 /:/\:\  \     /\__\
 * /\__\
 *      _____\:\  \   ___  \:\  \   ___     ___   ___     ___   /:/
 * /::\__\   /:/__/        /:/  /
 *     /::::::::\__\ /\  \  \:\__\ /\  \   /\__\ /\  \   /\__\ /:/_/:/\:|__|
 * /::\  \       /:/__/
 *     \:\~~\~~\/__/ \:\  \ /:/  / \:\  \ /:/  / \:\  \ /:/  / \:\/:/ /:/  /
 * \/\:\  \__   /::\  \
 *      \:\  \        \:\  /:/  /   \:\  /:/  /   \:\  /:/  /   \::/_/:/  /
 * ~~\:\/\__\ /:/\:\  \
 *       \:\  \        \:\/:/  /     \:\/:/  /     \:\/:/  /     \:\/:/  / \::/
 * / \/__\:\  \
 *        \:\__\        \::/  /       \::/  /       \::/  /       \::/  / /:/  /
 * \:\__\
 *         \/__/         \/__/         \/__/         \/__/         \/__/ \/__/
 * \/__/
 *
 *      @author      : Dylan Dsouza (dsouzadyn@gmail.com)
 *      @created     : Saturday Feb 16, 2019 22:47:36 IST
 */
#include <bits/stdc++.h>

using namespace std;

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

  int A, B;
  cin >> A >> B;
  if (B % A == 0) {
    cout << A + B << endl;
  } else {
    cout << B - A << endl;
  }

  return 0;
}
Problem p03125 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int a, b;
int main() {
  if (b % a == 0)
    cout << a + b;
  else
    cout << b - a;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int a, b;
int main() {
  cin >> a >> b;
  if (b % a == 0)
    cout << a + b;
  else
    cout << b - a;
  return 0;
}
Problem p03125 (Python)

Buggy submission (status: Runtime Error):
A, B = list(map(int, input()))

if B % A == 0:
    print(A + B)
else:
    print(B - A)


Fixed submission:
A, B = list(map(int, input().split()))

if B % A == 0:
    print(A + B)
else:
    print(B - A)
Problem p03125 (Python)

Buggy submission (status: Runtime Error):
def main():
    a, b = map(int, input().split())
    if b / a % 0:
        print(a + b)
    else:
        print(b - a)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    a, b = map(int, input().split())
    if b % a == 0:
        print(a + b)
    else:
        print(b - a)


if __name__ == "__main__":
    main()
Problem p03125 (Python)

Buggy submission (status: Runtime Error):
a, b = [int(x) for x in input().split()]
print([a + b, b - a][int(b % a)])


Fixed submission:
a, b = [int(x) for x in input().split()]
print([a + b, b - a][int(bool(b % a))])
Problem p03125 (Python)

Buggy submission (status: Runtime Error):
a, b = map(int, input())
if b % a == 0:
    print(a + b)
else:
    print(b - a)


Fixed submission:
a, b = map(int, input().split())
if b % a == 0:
    print(a + b)
else:
    print(b - a)
Problem p03125 (C++)

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

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b;
  cout << (b % a ? b - a : a + b);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int a, b;

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b;
  cout << (b % a ? b - a : a + b);
  return 0;
}
Problem p03126 (Python)

Buggy submission (status: Runtime Error):
n, m = map(int, input().split())

r = [0 for x in range(0, m)]

for _ in range(0, n):
    a = [x for x in map(int, input().split())]
    for i in a[1:]:
        r[i - 1] += 1

print(f"{len([x for x in r if x == n])}")


Fixed submission:
n, m = map(int, input().split())

r = [0 for x in range(0, m)]

for _ in range(0, n):
    a = [x for x in map(int, input().split())]
    for i in a[1:]:
        r[i - 1] += 1

print("{}".format(len([x for x in r if x == n])))
Problem p03126 (Python)

Buggy submission (status: Runtime Error):
from collections import defaultdict


n, m = map(int, input().split())
d = defaultdict(int)
for i in range(n):
    tmp = list(map(int, input().split()))
    for a in tmp[1:]:
        d[a] += 1
cnt = 0
for value in range(d.values()):
    if value == n:
        cnt += 1
print(cnt)


Fixed submission:
from collections import defaultdict


n, m = map(int, input().split())
d = defaultdict(int)
for i in range(n):
    tmp = list(map(int, input().split()))
    for a in tmp[1:]:
        d[a] += 1
cnt = 0
for value in d.values():
    if value == n:
        cnt += 1
print(cnt)
Problem p03126 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> cnt(M, 0);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A;
      cin >> A;
      A--;
      cnt[A]++;
    }
  }
  for (int i = 0; i < N; i++) {
    if (cnt[M] = N) {
      ans++;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> cnt(M, 0);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A;
      cin >> A;
      A--;
      cnt[A]++;
    }
  }
  for (int i = 0; i < M; i++) {
    if (cnt[i] == N) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03126 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int n, m;
  int k[m], a[30][30];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> a[i][j];
    }
  }
  int cnt = 0;
  bool like;
  for (int i = 1; i < m + 1; i++) { // ｍ種類の食べ物
    like = true;
    for (int j = 0; j < n; j++) { // 各人の好物に入っているか
      bool in = false;
      for (int l = 0; l < k[j]; l++) {
        if (a[j][l] == i)
          in = true;
      }
      if (!in) {
        like = false;
        break;
      }
    }
    if (like)
      cnt++;
  }

  cout << cnt << endl;
  return 0;
}


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

int main() {
  int n, m;
  int k[30], a[30][30];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) {
      cin >> a[i][j];
    }
  }
  int cnt = 0;
  bool like;
  for (int i = 1; i < m + 1; i++) { // ｍ種類の食べ物
    like = true;
    for (int j = 0; j < n; j++) { // 各人の好物に入っているか
      bool in = false;
      for (int l = 0; l < k[j]; l++) {
        if (a[j][l] == i)
          in = true;
      }
      if (!in) {
        like = false;
        break;
      }
    }
    if (like)
      cnt++;
  }

  cout << cnt << endl;
  return 0;
}
Problem p03126 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(n, 0);
  int k, a;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> a;
      c[a - 1]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (c[i] == n)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m, 0);
  int k, a;
  for (int i = 0; i < n; i++) {
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> a;
      c[a - 1]++;
    }
  }
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (c[i] == n)
      ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03126 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void) {
  int N, M;
  cin >> N >> M;
  int *K;
  K = new int[N];
  int **A = new int *[N];
  for (int j = 0; j < M; j++) {
    A[j] = new int[M];
  }
  for (int i = 0; i < N; i++) {
    cin >> K[i];
    for (int j = 0; j < K[i]; j++) {
      cin >> A[i][j];
    }
  }
  int *count;
  count = new int[M];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < K[i]; j++) {
      count[A[i][j] - 1]++;
    }
  }
  int kindnum = 0;
  for (int i = 0; i < M; i++) {
    if (count[i] == N) {
      kindnum++;
    }
  }
  cout << kindnum << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void) {
  int N, M;
  cin >> N >> M;
  int *K;
  K = new int[N];
  int **A = new int *[N];
  for (int j = 0; j < N; j++) {
    A[j] = new int[M];
  }
  for (int i = 0; i < N; i++) {
    cin >> K[i];
    for (int j = 0; j < K[i]; j++) {
      cin >> A[i][j];
    }
  }
  int *count;
  count = new int[M];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < K[i]; j++) {
      count[A[i][j] - 1]++;
    }
  }
  int kindnum = 0;
  for (int i = 0; i < M; i++) {
    if (count[i] == N) {
      kindnum++;
    }
  }
  cout << kindnum << endl;
  return 0;
}
Problem p03126 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(m + 10);
  vector<int> B(m + 10);
  vector<int> k(n);
  rep(i, n) {
    cin >> k[i];
    rep(j, k[i]) {
      cin >> A[j];
      B[A[j]] += 1;
    }
  }
  int count = 0;
  rep(i, m) {
    if (B[i] == n)
      ++count;
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)                                                              \
  ;                                                                            \
  for (int i = 1; i <= n; ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(m + 10);
  vector<int> B(m + 10);
  vector<int> k(n + 10);
  rep(i, n) {
    cin >> k[i];
    rep(j, k[i]) {
      cin >> A[j];
      B[A[j]] += 1;
    }
  }
  int count = 0;
  rep(i, m) {
    if (B[i] == n)
      ++count;
  }
  cout << count << endl;
  return 0;
}
Problem p03126 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int b[105];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", x);
      b[x]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++)
    if (b[i] == n)
      ans++;
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int b[105];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", &x);
      b[x]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++)
    if (b[i] == n)
      ans++;
  printf("%d\n", ans);
  return 0;
}
Problem p03126 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, m;
  cin >> n >> m;
  int cnt[m + 1];
  fill(cnt, cnt + n + 1, 0);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      cnt[a]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    if (cnt[i] == n)
      ans++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n, m;
  cin >> n >> m;
  int cnt[m + 1];
  fill(cnt, cnt + m + 1, 0);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      cnt[a]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= m; i++) {
    if (cnt[i] == n)
      ans++;
  }
  cout << ans << endl;
}
Problem p03126 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      a[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int num;
      cin >> num;
      a[i][num - 1] = 1;
    }
  }

  int count = 0;
  for (int i = 0; i < m; i++) {
    int flag = 0;
    for (int j = 0; j < n; j++) {
      if (a[j][i] != 1) {
        flag = 1;
      }
    }
    if (flag == 0) {
      count++;
    }
  }

  cout << count << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int a[n][m];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      a[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int num;
      cin >> num;
      a[i][num - 1] = 1;
    }
  }

  int count = 0;
  for (int i = 0; i < m; i++) {
    int flag = 0;
    for (int j = 0; j < n; j++) {
      if (a[j][i] != 1) {
        flag = 1;
      }
    }
    if (flag == 0) {
      count++;
    }
  }

  cout << count << endl;
}
Problem p03126 (C++)

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

int main(void) {
  int N, M;
  cin >> N >> M;
  int cnt[M];
  int ans = 0;

  for (int i = 0; i < M; i++)
    cnt[i] = 0;

  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A[K];
      cin >> A[i];
      cnt[A[i] - 1]++;
    }
  }

  for (int i = 0; i < M; i++) {
    if (cnt[i] == N)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


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

int main(void) {
  int N, M;
  cin >> N >> M;
  int cnt[M];
  int ans = 0;

  for (int i = 0; i < M; i++)
    cnt[i] = 0;

  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A;
      cin >> A;
      cnt[A - 1]++;
    }
  }

  for (int i = 0; i < M; i++) {
    if (cnt[i] == N)
      ans++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03126 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<bool>> match(N, vector<bool>(M, 0));
  int k, m;
  for (int i = 0; i < N; ++i) {
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> m;
      match.at(i).at(m) = 1;
    }
  }
  bool like;
  int num;
  for (int i = 0; i < M; ++i) {
    like = 1;
    for (int j = 0; j < N; ++j) {
      like *= match.at(j).at(i);
    }
    num += like;
  }
  cout << num << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<bool>> match(N, vector<bool>(M, 0));
  int k, m;
  for (int i = 0; i < N; ++i) {
    cin >> k;
    for (int j = 0; j < k; ++j) {
      cin >> m;
      match.at(i).at(m - 1) = 1;
    }
  }
  bool like;
  int num;
  for (int i = 0; i < M; ++i) {
    like = 1;
    for (int j = 0; j < N; ++j) {
      like *= match.at(j).at(i);
    }
    num += like;
  }
  cout << num << endl;
}
Problem p03126 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<set<int>> A(N);
  for (int i = 0; i < N; i++) {
    set<int> a;
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int c;
      cin >> c;
      a.insert(c);
    }
    A.at(i) = a;
  }
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    bool x = true;
    for (int j = 0; j < N; j++) {
      if (!A.at(i).count(j)) {
        x = false;
        break;
      }
    }
    if (x)
      ans++;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<set<int>> A(N);
  for (int i = 0; i < N; i++) {
    set<int> a;
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int c;
      cin >> c;
      a.insert(c);
    }
    A.at(i) = a;
  }
  int ans = 0;
  for (int i = 1; i <= M; i++) {
    bool x = true;
    for (int j = 0; j < N; j++) {
      if (!A.at(j).count(i)) {
        x = false;
        break;
      }
    }
    if (x)
      ans++;
  }
  cout << ans << endl;

  return 0;
}
Problem p03126 (C++)

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

using namespace std;

int main() {
  int n, m;
  int num = 0;
  int count = 0;
  cin >> n >> m;
  vector<vector<int>> item = vector<vector<int>>(n, vector<int>(m, 0));

  for (int i = 0; i < n; i++) {
    cin >> item[i][0];
    for (int j = 0; j < item[i][0]; j++) {
      cin >> item[i][j + 1];
    }
  }
  vector<int> ans(m, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < item[i][0]; j++) {
      ans[item[i][j + 1] - 1]++;
    }
  }
  for (int i : ans) {
    if (i == n) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  int num = 0;
  int count = 0;
  cin >> n >> m;
  vector<vector<int>> item = vector<vector<int>>(n, vector<int>(m + 1, 0));

  for (int i = 0; i < n; i++) {
    cin >> item[i][0];
    for (int j = 0; j < item[i][0]; j++) {
      cin >> item[i][j + 1];
    }
  }
  vector<int> ans(m, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < item[i][0]; j++) {
      ans[item[i][j + 1] - 1]++;
    }
  }
  for (int i : ans) {
    if (i == n) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}