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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int pc(int i) { return __builtin_popcount(i); }
int arr[1 << 17];
int rmbit(unsigned n, int i) {
  return ((n << (32 - i)) >> (32 - i)) | (((n >> (i + 1))) << i);
}
int addbit(unsigned n, int i, bool p) {
  unsigned t = (n >> i) << (i + 1), s = (n << (32 - i)) >> (32 - i);
  t |= s;
  if (p)
    t |= (1 << i);
  return t;
}
void f(int n, int a, int b, int l) {
  if (n == 1) {
    arr[l] = a;
    arr[l + 1] = b;
    return;
  }
  for (int i = 0; i < n; i++) {
    if ((a & (1 << i)) == (b & (1 << i)))
      continue;
    int ap = rmbit(a, i), bp = rmbit(b, i), c = ap ^ 1;
    f(n - 1, ap, c, l);
    f(n - 1, c, bp, l + (1 << (n - 1)));
    for (int j = l; j < l + (1 << n); j++)
      arr[j] = addbit(arr[j], i,
                      j < (l + (1 << (n - 1))) ? a & (1 << i) : b & (1 << i));
    return;
  }
  assert(0);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if ((pc(a) & 1) == (pc(b) & 1)) {
    return !(cout << "NO");
  }
  cout << "YES\n";
  f(n, a, b, 0);
  for (int i = 0; i < (1 << n); i++) {
    cout << arr[i] << ' ';
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int pc(int i) { return __builtin_popcount(i); }
int arr[1 << 17];
int getl(int n, int i) { return (n >> (i + 1)) << (i + 1); }
int getr(int n, int i) { return n ^ ((n >> i) << i); }
int rmbit(int n, int i) { return (getl(n, i) >> 1) | getr(n, i); }
int addbit(int n, int i, bool p) {
  return ((n >> i) << (i + 1)) | getr(n, i) | (p ? (1 << i) : 0);
}
void f(int n, int a, int b, int l) {
  if (n == 1) {
    arr[l] = a;
    arr[l + 1] = b;
    return;
  }
  for (int i = 0; i < n; i++) {
    if ((a & (1 << i)) == (b & (1 << i)))
      continue;
    int ap = rmbit(a, i), bp = rmbit(b, i), c = ap ^ 1;
    f(n - 1, ap, c, l);
    f(n - 1, c, bp, l + (1 << (n - 1)));
    for (int j = l; j < l + (1 << n); j++)
      arr[j] = addbit(arr[j], i,
                      j < (l + (1 << (n - 1))) ? a & (1 << i) : b & (1 << i));
    return;
  }
  assert(0);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if ((pc(a) & 1) == (pc(b) & 1)) {
    return !(cout << "NO");
  }
  cout << "YES\n";
  f(n, a, b, 0);
  for (int i = 0; i < (1 << n); i++) {
    cout << arr[i] << ' ';
  }
}
Problem p03097 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define lowbit(_A) ((_A) & (-(_A)))

int n;
int cnt;
int fr[166666];
int ne[333333];
int to[333333];

void add(int a, int b) {
  ne[++cnt] = fr[a], fr[a] = cnt, to[cnt] = b;
  ne[++cnt] = fr[b], fr[b] = cnt, to[cnt] = a;
}

void dfs(int S, int T, int s, int cnt) {
  if (cnt == n - 1) {
    add(S, T);
    return;
  }
  for (int i = 0; i < n; i++) {
    if (s & (1 << i))
      continue;
    if ((S & (1 << i)) != (T & (1 << i))) {
      for (int j = 0, tmp, tmp2; j < n; j++) {
        if ((s & (1 << j)) || j == i)
          continue;
        else {
          if (S & (1 << j))
            tmp = S & ((1 << n) - 1 - (1 << j));
          else
            tmp = S | (1 << j);
          dfs(S, tmp, s | (1 << i), cnt + 1);
          if (S & (1 << i))
            tmp2 = tmp & (((1 << n) - 1 - (1 << i)));
          else
            tmp2 = tmp | (1 << i);
          dfs(tmp2, T, s | (1 << i), cnt + 1);
          add(tmp, tmp2);
        }
      }
      break;
    }
  }
}

int A, B;
int na, nb;

void out(int a, int f) {
  printf("%d ", a);
  for (int i = fr[a]; i; i = ne[i])
    if (to[i] != f)
      out(to[i], a);
}

int main() {
  scanf("%d", &n);
  scanf("%d %d", &A, &B);
  int tmp = A;
  while (tmp)
    tmp -= lowbit(tmp), na++;
  tmp = B;
  while (tmp)
    tmp -= lowbit(tmp), nb++;
  if (na % 2 == nb % 2)
    return !printf("NO\n");
  dfs(A, B, 0, 0);
  puts("YES");
  out(A, -2);
  printf("\n");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define lowbit(_A) ((_A) & (-(_A)))

int n;
int cnt;
int fr[166666];
int ne[333333];
int to[333333];

void add(int a, int b) {
  ne[++cnt] = fr[a], fr[a] = cnt, to[cnt] = b;
  ne[++cnt] = fr[b], fr[b] = cnt, to[cnt] = a;
}

void dfs(int S, int T, int s, int cnt) {
  if (cnt == n - 1) {
    add(S, T);
    return;
  }
  for (int i = 0; i < n; i++) {
    if (s & (1 << i))
      continue;
    if ((S & (1 << i)) != (T & (1 << i))) {
      for (int j = 0, tmp, tmp2; j < n; j++) {
        if ((s & (1 << j)) || j == i)
          continue;
        else {
          if (S & (1 << j))
            tmp = S & ((1 << n) - 1 - (1 << j));
          else
            tmp = S | (1 << j);
          dfs(S, tmp, s | (1 << i), cnt + 1);
          if (S & (1 << i))
            tmp2 = tmp & (((1 << n) - 1 - (1 << i)));
          else
            tmp2 = tmp | (1 << i);
          dfs(tmp2, T, s | (1 << i), cnt + 1);
          add(tmp, tmp2);
          break;
        }
      }
      break;
    }
  }
}

int A, B;
int na, nb;

void out(int a, int f) {
  printf("%d ", a);
  for (int i = fr[a]; i; i = ne[i])
    if (to[i] != f)
      out(to[i], a);
}

int main() {
  scanf("%d", &n);
  scanf("%d %d", &A, &B);
  int tmp = A;
  while (tmp)
    tmp -= lowbit(tmp), na++;
  tmp = B;
  while (tmp)
    tmp -= lowbit(tmp), nb++;
  if (na % 2 == nb % 2)
    return !printf("NO\n");
  dfs(A, B, 0, 0);
  puts("YES");
  out(A, -2);
  printf("\n");
  return 0;
}
Problem p03097 (C++)

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

void print(int x) {
  for (int i = 7; i >= 0; i--)
    cout << (x >> i & 1);
  cout << endl;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  auto count = [&](int x) {
    int r = 0;
    for (int i = 0; i < N; i++)
      r += x >> i & 1;
    return r;
  };

  int C = A ^ B;
  if (count(C) % 2 != 1) {
    cout << "NO" << endl;
    return 0;
  }

  vector<int> T;
  for (int i = 0; i < 1 << N; i++)
    T.push_back(i ^ i >> 1);

  for (int i = 0; i < count(C) / 2; i++) {
    bool ok = false;
    int c = ((1 << N) >> (i * 2 + 1));
    for (int j = (1 << N) - c - 3; j <= (1 << N) - 2; j++) {
      if (count(T[j] ^ T[(1 << N) - 1]) == 1 && count(T[j + 1]) == i * 2 + 3) {
        reverse(T.begin() + j + 1, T.end());
        ok = true;
        break;
      }
    }
    if (!ok) {
      *(int *)0 = 0;
      cout << "NO" << endl;
      return 0;
    }
  }

  vector<int> B0, B1;
  for (int i = 0; i < N; i++)
    if (C >> i & 1)
      B1.push_back(i);
    else
      B0.push_back(i);
  vector<int> M;
  int b0 = 0;
  int b1 = 0;
  for (int i = 0; i < N; i++)
    if (T[(1 << N) - 1] >> i & 1)
      M.push_back(B1[b1++]);
    else
      M.push_back(B0[b0++]);

  cout << "YES" << endl;
  bool f = true;
  for (int t : T) {
    int t2 = 0;
    for (int i = 0; i < N; i++)
      t2 |= (t >> i & 1) << M[i];
    t2 ^= A;
    cout << (f ? "" : " ") << t2;
    f = false;
  }
  cout << endl;
}


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

void print(int x) {
  for (int i = 7; i >= 0; i--)
    cout << (x >> i & 1);
  cout << endl;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  auto count = [&](int x) {
    int r = 0;
    for (int i = 0; i < N; i++)
      r += x >> i & 1;
    return r;
  };

  int C = A ^ B;
  if (count(C) % 2 != 1) {
    cout << "NO" << endl;
    return 0;
  }

  vector<int> T;
  for (int i = 0; i < 1 << N; i++)
    T.push_back(i ^ i >> 1);

  for (int i = 0; i < count(C) / 2; i++) {
    int t = 1 << (N - i * 2 - 1);
    reverse(T.end() - t + 1, T.end());
    reverse(T.end() - t + 2, T.end() - t / 2 + 1);
    reverse(T.end() - t / 2 + 1, T.end());
  }

  vector<int> B0, B1;
  for (int i = 0; i < N; i++)
    if (C >> i & 1)
      B1.push_back(i);
    else
      B0.push_back(i);
  vector<int> M;
  int b0 = 0;
  int b1 = 0;
  for (int i = 0; i < N; i++)
    if (T[(1 << N) - 1] >> i & 1)
      M.push_back(B1[b1++]);
    else
      M.push_back(B0[b0++]);

  cout << "YES" << endl;
  bool f = true;
  for (int t : T) {
    int t2 = 0;
    for (int i = 0; i < N; i++)
      t2 |= (t >> i & 1) << M[i];
    t2 ^= A;
    cout << (f ? "" : " ") << t2;
    f = false;
  }
  cout << endl;
}
Problem p03097 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
inline int read() {
  int x = 0, c;
  while (!isdigit(c = getchar()))
    ;
  while (x = x * 10 + c - '0', isdigit(c = getchar()))
    ;
  return x;
}
int cnt[1 << 18], ans[18][1 << 17], n, A, B;
void solve(int k, int A, int B, int *a, int l, int r) {
  if (k == 1) {
    a[l] = A;
    a[r] = B;
    return;
  }
  int C = A ^ B, x = C & (-C), mid = (l + r) >> 1;
  int nA = A % x + A / (x << 1) * x, nB = B % x + B / (x << 1) * x;
  solve(k - 1, nA, nA ^ nB, ans[k - 1], l, mid);
  solve(k - 1, nA ^ nB, nB, ans[k - 1], mid + 1, r);
  for (int i = l; i <= mid; i++)
    a[i] = ans[k - 1][i] % x + ans[k - 1][i] / x * (x << 1) + ((A & x) ? x : 0);
  for (int i = mid + 1; i <= r; i++)
    a[i] = ans[k - 1][i] % x + ans[k - 1][i] / x * (x << 1) + ((B & x) ? x : 0);
}
int main() {
  n = read();
  A = read();
  B = read();
  int N = 1 << n;
  N--;
  for (int i = 1; i <= N; i++)
    cnt[i] = cnt[i >> 1] + (i & 1);
  if (cnt[A ^ B] & 1) {
    printf("YES\n");
    solve(n, A, B, ans[n], 0, N);
    for (int i = 0; i <= N; i++)
      printf("%d ", ans[n][i]);
    return 0;
  }
  printf("NO\n");
}

Fixed submission:
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
inline int read() {
  int x = 0, c;
  while (!isdigit(c = getchar()))
    ;
  while (x = x * 10 + c - '0', isdigit(c = getchar()))
    ;
  return x;
}
int cnt[1 << 18], ans[18][1 << 17], n, A, B;
void solve(int k, int A, int B, int *a, int l, int r) {
  if (k == 1) {
    a[l] = A;
    a[r] = B;
    return;
  }
  int C = A ^ B, x = C & (-C), mid = (l + r) >> 1;
  int nA = A % x + A / (x << 1) * x, nB = B % x + B / (x << 1) * x;
  solve(k - 1, nA, nA ^ 1, ans[k - 1], l, mid);
  solve(k - 1, nA ^ 1, nB, ans[k - 1], mid + 1, r);
  for (int i = l; i <= mid; i++)
    a[i] = ans[k - 1][i] % x + ans[k - 1][i] / x * (x << 1) + ((A & x) ? x : 0);
  for (int i = mid + 1; i <= r; i++)
    a[i] = ans[k - 1][i] % x + ans[k - 1][i] / x * (x << 1) + ((B & x) ? x : 0);
}
int main() {
  n = read();
  A = read();
  B = read();
  int N = 1 << n;
  N--;
  for (int i = 1; i <= N; i++)
    cnt[i] = cnt[i >> 1] + (i & 1);
  if (cnt[A ^ B] & 1) {
    printf("YES\n");
    solve(n, A, B, ans[n], 0, N);
    for (int i = 0; i <= N; i++)
      printf("%d ", ans[n][i]);
    return 0;
  }
  printf("NO\n");
}
Problem p03097 (C++)

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1 << 17;

int N, A, B;

void go(int s, int t, int mask) {
  if (__builtin_popcount(mask) == N - 1) {
    cout << s << ' ' << t << ' ';
    return;
  }
  int c = -1, e = -1;
  for (int i = 0; i < N; ++i)
    if (!(mask >> i & 1)) {
      if (c == -1 && (s >> i & 1) != (t >> i & 1))
        c = i;
      else
        e = i;
    }
  go(s, s ^ (1 << c), mask ^ (1 << c));
  go(s ^ (1 << c) ^ (1 << e), t, mask ^ (1 << c));
}

signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef LOCAL
  freopen("A.INP", "r", stdin);
  freopen("A.OUT", "w", stdout);
#endif // LOCAL
  cin >> N >> A >> B;
  if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
    cout << "NO";
  } else {
    cout << "YES\n";
    go(A, B, 0);
  }
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1 << 17;

int N, A, B;

void go(int s, int t, int mask) {
  if (__builtin_popcount(mask) == N - 1) {
    cout << s << ' ' << t << ' ';
    return;
  }
  int c = -1, e = -1;
  for (int i = 0; i < N; ++i)
    if (!(mask >> i & 1)) {
      if (c == -1 && (s >> i & 1) != (t >> i & 1))
        c = i;
      else
        e = i;
    }
  go(s, s ^ (1 << e), mask ^ (1 << c));
  go(s ^ (1 << e) ^ (1 << c), t, mask ^ (1 << c));
}

signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef LOCAL
  freopen("A.INP", "r", stdin);
  freopen("A.OUT", "w", stdout);
#endif // LOCAL
  cin >> N >> A >> B;
  if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
    cout << "NO";
  } else {
    cout << "YES\n";
    go(A, B, 0);
  }
}
Problem p03097 (C++)

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

int n, a, b;
vector<int> ret;
void dfs(int l, int r, int mask) {
  if (mask & (mask - 1) == 0) {
    ret.pb(l);
    ret.pb(r);
    return;
  }
  int x = l ^ r;
  int tb = x & -x, tc = mask ^ tb;
  int td = tc & -tc;
  dfs(l, l ^ td, tc);
  dfs(l ^ tb ^ td, r, tc);
}
int main() {
  cin >> n >> a >> b;
  if (__builtin_popcount(a) % 2 == __builtin_popcount(b) % 2) {
    cout << "NO" << endl;
    return 0;
  }
  dfs(a, b, (1 << n) - 1);
  cout << "YES" << endl;
  rep(i, ret.size()) { cout << ret[i] << " "; }
  cout << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;

int n, a, b;
vector<int> ret;
void dfs(int l, int r, int mask) {
  if ((mask & (mask - 1)) == 0) {
    ret.pb(l);
    ret.pb(r);
    return;
  }
  int x = l ^ r;
  int tb = x & -x, tc = mask ^ tb;
  int td = tc & -tc;
  dfs(l, l ^ td, tc);
  dfs(l ^ tb ^ td, r, tc);
}
int main() {
  cin >> n >> a >> b;
  if (__builtin_popcount(a) % 2 == __builtin_popcount(b) % 2) {
    cout << "NO" << endl;
    return 0;
  }
  dfs(a, b, (1 << n) - 1);
  cout << "YES" << endl;
  rep(i, ret.size()) { cout << ret[i] << " "; }
  cout << endl;
  return 0;
}
Problem p03097 (C++)

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

using namespace std;

int n;
int a, b;

void dfs(vector<int> &ans, int a, int b, int cn, int mask) {
  if (cn == 1) {
    ans.push_back(a);
    ans.push_back(b);
    return;
  }

  int c, d;

  for (int i = 0; i < n; i++) {
    if (!(mask & (1 << i)) && ((a ^ b) & (1 << i))) {
      c = i;
      break;
    }
  }

  for (int i = 0; i < n; i++) {
    if (!(mask & (1 << i)) && i != c) {
      d = i;
      break;
    }
  }

  dfs(ans, a, a ^ (1 << d), n - 1, mask + (1 << c));
  dfs(ans, a ^ (1 << c) ^ (1 << d), b, n - 1, mask + (1 << c));
}

int main() {

  cin >> n >> a >> b;

  int tmp = a;
  int cnt_a, cnt_b;

  while (tmp) {
    if (tmp & 1)
      cnt_a++;
    tmp >>= 1;
  }

  tmp = b;
  while (tmp) {
    if (tmp & 1)
      cnt_b++;
    tmp >>= 1;
  }

  if ((cnt_a % 2) == (cnt_b % 2)) {
    cout << "NO";
    return 0;
  }

  cout << "YES" << endl;
  vector<int> ans;
  dfs(ans, a, b, n, 0);

  for (int i : ans)
    cout << i << ' ';
}

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

using namespace std;

int n;
int a, b;

void dfs(vector<int> &ans, int a, int b, int cn, int mask) {
  if (cn == 1) {
    ans.push_back(a);
    ans.push_back(b);
    return;
  }

  int c, d;

  for (int i = 0; i < n; i++) {
    if (!(mask & (1 << i)) && ((a ^ b) & (1 << i))) {
      c = i;
      break;
    }
  }

  for (int i = 0; i < n; i++) {
    if (!(mask & (1 << i)) && i != c) {
      d = i;
      break;
    }
  }

  dfs(ans, a, a ^ (1 << d), cn - 1, mask + (1 << c));
  dfs(ans, a ^ (1 << c) ^ (1 << d), b, cn - 1, mask + (1 << c));
}

int main() {

  cin >> n >> a >> b;

  int tmp = a;
  int cnt_a, cnt_b;

  while (tmp) {
    if (tmp & 1)
      cnt_a++;
    tmp >>= 1;
  }

  tmp = b;
  while (tmp) {
    if (tmp & 1)
      cnt_b++;
    tmp >>= 1;
  }

  if ((cnt_a % 2) == (cnt_b % 2)) {
    cout << "NO";
    return 0;
  }

  cout << "YES" << endl;
  vector<int> ans;
  dfs(ans, a, b, n, 0);

  for (int i : ans)
    cout << i << ' ';
}
Problem p03097 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
// const int mod = ;

vi solve(int n, int a, int b) {
  if (n == 1) {
    assert(a != b);
    return {a, b};
  }
  assert(a >= 0 && b >= 0 && max(a, b) < (1 << n));
  if (a % 2 == b % 2) {
    vi v1 = solve(n - 1, a / 2, b / 2);
    vi v2 = solve(n - 1, a / 2, v1[1]);
    for (int &x : v2)
      x = 2 * x + (1 - a % 2);
    v2.insert(v2.begin(), a);
    for (int i = 1; i < v1.size(); ++i) {
      v2.push_back(v1[i] * 2 + a % 2);
    }
    return v2;
  } else {
    int neig = (a / 2) ^ 1;
    vi v1 = solve(n - 1, a / 2, neig);
    vi v2 = solve(n - 1, neig, b);
    for (int &x : v1)
      x = 2 * x + a % 2;
    for (int x : v2)
      v1.push_back(x * 2 + b % 2);
    return v1;
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if (__builtin_popcount(a ^ b) % 2 == 0) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  vi v = solve(n, a, b);
  for (int i = 0; i + 1 < v.size(); ++i) {
    assert(__builtin_popcount(v[i] ^ v[i + 1]) == 1);
  }
  for (int x : v) {
    cout << x << ' ';
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
// const int mod = ;

vi solve(int n, int a, int b) {
  if (n == 1) {
    assert(a != b);
    return {a, b};
  }
  assert(a >= 0 && b >= 0 && max(a, b) < (1 << n));
  if (a % 2 == b % 2) {
    vi v1 = solve(n - 1, a / 2, b / 2);
    vi v2 = solve(n - 1, a / 2, v1[1]);
    for (int &x : v2)
      x = 2 * x + (1 - a % 2);
    v2.insert(v2.begin(), a);
    for (int i = 1; i < v1.size(); ++i) {
      v2.push_back(v1[i] * 2 + a % 2);
    }
    return v2;
  } else {
    int neig = (a / 2) ^ 1;
    vi v1 = solve(n - 1, a / 2, neig);
    vi v2 = solve(n - 1, neig, b / 2);
    for (int &x : v1)
      x = 2 * x + a % 2;
    for (int x : v2)
      v1.push_back(x * 2 + b % 2);
    return v1;
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if (__builtin_popcount(a ^ b) % 2 == 0) {
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
  vi v = solve(n, a, b);
  for (int i = 0; i + 1 < v.size(); ++i) {
    assert(__builtin_popcount(v[i] ^ v[i + 1]) == 1);
  }
  for (int x : v) {
    cout << x << ' ';
  }
  cout << endl;
  return 0;
}
Problem p03097 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = (0); i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;

int n;
vi solve(int nn, int l, int r, int bak) {
  // printf("%d  %d %d %d\n",nn,l,r,bak);
  if (nn == 1)
    return {l & bak, r & bak};
  vi L, R, res;
  REP(i, n) if ((bak >> i & 1) && ((l >> i & 1) ^ (r >> i & 1))) {
    int vl = (l >> i & 1), vr = (r >> i & 1), fr = 0;
    REP(j, n) if ((bak >> j & 1) && (j != i)) fr = 1 << j;
    L = solve(nn - 1, l, l ^ fr, bak ^ (1 << i));
    R = solve(nn - 1, l ^ fr, r, bak ^ (1 << i));
    res.resize(1 << nn);
    int semi = 1 << (nn - 1);
    REP(j, semi)
    res[j] = L[j] ^ (vl << i);
    REP(j, semi)
    res[j + semi] = R[j] ^ (vr << i);
  }
  return res;
}

int main() {
  int l, r;
  cin >> n >> l >> r;
  if (__builtin_popcount(l ^ r) % 2 == 0)
    return puts("NO"), 0;
  vi ans = solve(n, l, r, (1 << n) - 1);
  puts("YES");
  for (auto x : ans)
    printf("%d ", x);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) for (int i = (0); i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;

int n;
vi solve(int nn, int l, int r, int bak) {
  // printf("%d  %d %d %d\n",nn,l,r,bak);
  if (nn == 1)
    return {l & bak, r & bak};
  vi L, R, res;
  REP(i, n) if ((bak >> i & 1) && ((l >> i & 1) ^ (r >> i & 1))) {
    int vl = (l >> i & 1), vr = (r >> i & 1), fr = 0;
    REP(j, n) if ((bak >> j & 1) && (j != i)) fr = 1 << j;
    L = solve(nn - 1, l, l ^ fr, bak ^ (1 << i));
    R = solve(nn - 1, l ^ fr, r, bak ^ (1 << i));
    res.resize(1 << nn);
    int semi = 1 << (nn - 1);
    REP(j, semi)
    res[j] = L[j] ^ (vl << i);
    REP(j, semi)
    res[j + semi] = R[j] ^ (vr << i);
    break;
  }
  return res;
}

int main() {
  int l, r;
  cin >> n >> l >> r;
  if (__builtin_popcount(l ^ r) % 2 == 0)
    return puts("NO"), 0;
  vi ans = solve(n, l, r, (1 << n) - 1);
  puts("YES");
  for (auto x : ans)
    printf("%d ", x);
  return 0;
}
Problem p03098 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

const int N = 1e5 + 5;

typedef vector<int> vec;

int n, k, c[N];
bool vis[N];
vec a[7], A, p, q;

vec inv(vec a) {
  vec b;
  b.resize(n);
  fo(i, 0, n - 1) b[a[i]] = i;
  return b;
}

vec mult(vec a, vec b) {
  vec c;
  c.resize(n);
  fo(i, 0, n - 1) c[i] = a[b[i]];
  return c;
}

vec pwr(vec a, int t) {
  vec b;
  b.resize(n);
  fo(i, 0, n - 1) vis[i] = 0;
  fo(i, 0, n - 1) if (!vis[i]) {
    if (a[i] == i) {
      b[i] = i;
      continue;
    }
    int x = i, m = 0;
    do {
      vis[c[m++] = x] = 1;
      x = a[x];
    } while (x != i);
    fo(j, 0, m - 1) b[c[j]] = c[(j + t) % m];
  }
  return b;
}

int main() {
  scanf("%d%d", &n, &k);
  p.resize(n);
  q.resize(n);
  fo(i, 0, n - 1) scanf("%d", &p[i]), p[i]--;
  fo(i, 0, n - 1) scanf("%d", &q[i]), q[i]--;
  a[1] = p;
  a[2] = q;
  if (n <= 6) {
    fo(i, 3, n) a[i] = mult(a[i - 1], inv(a[i - 2]));
    fo(i, 0, n - 1) printf("%d ", a[n][i] + 1);
    return 0;
  }
  fo(i, 3, 6) a[i] = mult(a[i - 1], inv(a[i - 2]));
  A.resize(n);
  fo(i, 0, n - 1) A[i] = i;
  A = mult(A, q);
  A = mult(A, inv(p));
  A = mult(A, inv(q));
  A = mult(A, p);
  A = pwr(A, (k - 1) / 6);
  vec an = a[k % 6];
  an = mult(A, an);
  an = mult(an, inv(A));
  fo(i, 0, n - 1) printf("%d ", an[i] + 1);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

const int N = 1e5 + 5;

typedef vector<int> vec;

int n, k, c[N];
bool vis[N];
vec a[7], A, p, q;

vec inv(vec a) {
  vec b;
  b.resize(n);
  fo(i, 0, n - 1) b[a[i]] = i;
  return b;
}

vec mult(vec a, vec b) {
  vec c;
  c.resize(n);
  fo(i, 0, n - 1) c[i] = a[b[i]];
  return c;
}

vec pwr(vec a, int t) {
  vec b;
  b.resize(n);
  fo(i, 0, n - 1) vis[i] = 0;
  fo(i, 0, n - 1) if (!vis[i]) {
    if (a[i] == i) {
      b[i] = i;
      continue;
    }
    int x = i, m = 0;
    do {
      vis[c[m++] = x] = 1;
      x = a[x];
    } while (x != i);
    fo(j, 0, m - 1) b[c[j]] = c[(j + t) % m];
  }
  return b;
}

int main() {
  scanf("%d%d", &n, &k);
  p.resize(n);
  q.resize(n);
  fo(i, 0, n - 1) scanf("%d", &p[i]), p[i]--;
  fo(i, 0, n - 1) scanf("%d", &q[i]), q[i]--;
  a[1] = p;
  a[2] = q;
  if (n <= 6) {
    fo(i, 3, n) a[i] = mult(a[i - 1], inv(a[i - 2]));
    fo(i, 0, n - 1) printf("%d ", a[n][i] + 1);
    return 0;
  }
  fo(i, 3, 6) a[i] = mult(a[i - 1], inv(a[i - 2]));
  A.resize(n);
  fo(i, 0, n - 1) A[i] = i;
  A = mult(A, q);
  A = mult(A, inv(p));
  A = mult(A, inv(q));
  A = mult(A, p);
  A = pwr(A, (k - 1) / 6);
  vec an = a[(k - 1) % 6 + 1];
  an = mult(A, an);
  an = mult(an, inv(A));
  fo(i, 0, n - 1) printf("%d ", an[i] + 1);
  return 0;
}
Problem p03100 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, m, q, mod, fa[600010], id[50010][3][2], x = 0, g = 0, z;
bool can_a[2][50010];
struct edge {
  int u, v, w;
} e[50010];
int find(int a) { return fa[a] == a ? a : fa[a] = find(fa[a]); }
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
void merge(int u, int v) {
  int fau = find(u), fav = find(v);
  if (fau == fav)
    return;
  fa[fav] = fau;
}
int main() {
  scanf("%d %d %d %d", &n, &m, &q, &mod);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 2; k++)
        id[i][j][k] = ++x, fa[x] = x;
  for (int i = 1; i <= m; i++)
    scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].w),
        g = gcd(abs(e[i].w - e[1].w), g);
  if (!g)
    g = mod;
  mod = gcd(mod, 3 * g), z = e[1].w % g;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 2; k++) {
        merge(id[e[i].u][j][k], id[e[i].v][(2 * j + e[i].w / g) % 3][k ^ 1]);
        merge(id[e[i].v][j][k], id[e[i].u][(2 * j + e[i].w / g) % 3][k ^ 1]);
      }
  }
  for (int i = 0, j = z, ed = mod * 2; i < ed; i++, j = 2 * j % mod)
    can_a[i & 1][j] = 1;
  for (int i = 1, s, t, r; i <= q; i++) {
    scanf("%d %d %d", &s, &t, &r);
    bool flag = false;
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 2; k++)
        if (find(id[t][0][0]) == find(id[s][j][k]))
          flag |= can_a[k][(r + z + (3 - j) * g) % mod];
    puts(flag ? "YES" : "NO");
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, m, q, mod, fa[600010], id[50010][3][2], x = 0, g = 0, z;
bool can_a[2][1000010];
struct edge {
  int u, v, w;
} e[50010];
int find(int a) { return fa[a] == a ? a : fa[a] = find(fa[a]); }
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
void merge(int u, int v) {
  int fau = find(u), fav = find(v);
  if (fau == fav)
    return;
  fa[fav] = fau;
}
int main() {
  scanf("%d %d %d %d", &n, &m, &q, &mod);
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 2; k++)
        id[i][j][k] = ++x, fa[x] = x;
  for (int i = 1; i <= m; i++)
    scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].w),
        g = gcd(abs(e[i].w - e[1].w), g);
  if (!g)
    g = mod;
  mod = gcd(mod, 3 * g), z = e[1].w % g;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 2; k++) {
        merge(id[e[i].u][j][k], id[e[i].v][(2 * j + e[i].w / g) % 3][k ^ 1]);
        merge(id[e[i].v][j][k], id[e[i].u][(2 * j + e[i].w / g) % 3][k ^ 1]);
      }
  }
  for (int i = 0, j = z, ed = mod * 2; i < ed; i++, j = 2 * j % mod)
    can_a[i & 1][j] = 1;
  for (int i = 1, s, t, r; i <= q; i++) {
    scanf("%d %d %d", &s, &t, &r);
    bool flag = false;
    for (int j = 0; j < 3; j++)
      for (int k = 0; k < 2; k++)
        if (find(id[t][0][0]) == find(id[s][j][k]))
          flag |= can_a[k][(r + z + (3 - j) * g) % mod];
    puts(flag ? "YES" : "NO");
  }
  return 0;
}
Problem p03100 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
const int Q = 1 << 19;
int fa[Q];
int gf(int x) { return fa[x] == x ? x : (fa[x] = gf(fa[x])); }
int X[Q], Y[Q], Z[Q];
int MOD;
int id(int x, int y, int z) { return (x - 1) * 6 + y * 2 + z; }
void Merge(int x, int y) {
  x = gf(x), y = gf(y);
  fa[x] = y;
}
int had[2][1 << 21];
void Deal(int x, int y, int z) {
  for (int q = 0; q < 3; q++)
    for (int p = 0; p < 2; p++)
      Merge(id(x, q, p), id(y, ((q << 1) + z) % 3, p ^ 1));
}
int main() {
  int n, m, q, gg = -1;
  scanf("%d%d%d%d", &n, &m, &q, &MOD);
  for (int i = 1; i <= (n + 1) * 6; i++)
    fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &X[i], &Y[i], &Z[i]);
    if (i > 1) {
      int v = abs(Z[i] - Z[1]);
      gg = gg < 0 ? v : __gcd(gg, v);
    }
  }
  // gg=max(gg,1);
  MOD = __gcd(MOD, 3 * gg);
  int zz = Z[1] % gg;
  for (int i = 1; i <= m; i++) {
    int x = X[i], y = Y[i], z = (Z[i] - zz) / gg % 3;
    Deal(x, y, z), Deal(y, x, z);
  }
  for (int i = 0, j = zz % MOD; i < (MOD << 1); i++, j = (j << 1) % MOD)
    had[i & 1][j] = 1;
  while (q--) {
    int s, t, r, als = 0;
    scanf("%d%d%d", &s, &t, &r);
    for (int q = 0; q < 3; q++)
      for (int p = 0; p < 2; p++)
        if (gf(id(t, 0, 0)) == gf(id(s, q, p)) &&
            had[p][(r + zz + (3 - q) * gg) % MOD]) {
          als = 1;
          break;
        }
    puts(als ? "YES" : "NO");
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
const int Q = 1 << 19;
int fa[Q];
int gf(int x) { return fa[x] == x ? x : (fa[x] = gf(fa[x])); }
int X[Q], Y[Q], Z[Q];
int MOD;
int id(int x, int y, int z) { return (x - 1) * 6 + y * 2 + z; }
void Merge(int x, int y) {
  x = gf(x), y = gf(y);
  fa[x] = y;
}
int had[2][1 << 21];
void Deal(int x, int y, int z) {
  for (int q = 0; q < 3; q++)
    for (int p = 0; p < 2; p++)
      Merge(id(x, q, p), id(y, ((q << 1) + z) % 3, p ^ 1));
}
int main() {
  int n, m, q, gg = -1;
  scanf("%d%d%d%d", &n, &m, &q, &MOD);
  for (int i = 1; i <= (n + 1) * 6; i++)
    fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &X[i], &Y[i], &Z[i]);
    if (i > 1) {
      int v = abs(Z[i] - Z[1]);
      gg = gg < 0 ? v : __gcd(gg, v);
    }
  }
  if (!gg)
    gg = MOD;
  MOD = __gcd(MOD, 3 * gg);
  int zz = Z[1] % gg;
  for (int i = 1; i <= m; i++) {
    int x = X[i], y = Y[i], z = (Z[i] - zz) / gg % 3;
    Deal(x, y, z), Deal(y, x, z);
  }
  for (int i = 0, j = zz % MOD; i < (MOD << 1); i++, j = (j << 1) % MOD)
    had[i & 1][j] = 1;
  while (q--) {
    int s, t, r, als = 0;
    scanf("%d%d%d", &s, &t, &r);
    for (int q = 0; q < 3; q++)
      for (int p = 0; p < 2; p++)
        if (gf(id(t, 0, 0)) == gf(id(s, q, p)) &&
            had[p][(r + zz + (3 - q) * gg) % MOD]) {
          als = 1;
          break;
        }
    puts(als ? "YES" : "NO");
  }
  return 0;
}
Problem p03100 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

const int N = 1e6 + 5;

int n, m, q, mod, s, t, r, u[N], v[N], c[N], g, fa[N];
bool can[2][N];

int Id(int x, int y, int z) { return (x - 1) * 6 + y * 3 + z; }
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }

void link(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y)
    return;
  fa[x] = y;
}

int main() {
  scanf("%d%d%d%d", &n, &m, &q, &mod);
  fo(i, 1, m) {
    scanf("%d%d%d", &u[i], &v[i], &c[i]);
    g = __gcd(g, c[i] - c[1]);
  }
  if (!g)
    g = mod;
  mod = __gcd(mod, 3 * g);
  int z = c[1] % g;
  fo(i, 0, 6 * n) fa[i] = i;
  fo(i, 1, m) {
    int w = (c[i] - z) / g;
    fo(p, 0, 1) fo(q, 0, 2) {
      link(Id(u[i], p, q), Id(v[i], 1 - p, (2 * q + w) % 3));
      link(Id(v[i], p, q), Id(u[i], 1 - p, (2 * q + w) % 3));
    }
  }
  for (int i = 0, j = z; i < mod << 1; i++, (j <<= 1) %= mod)
    can[i & 1][j] = 1;
  for (; q; q--) {
    scanf("%d%d%d", &s, &t, &r);
    int ret = 0;
    fo(p, 0, 1) fo(q, 0, 2) if (get(Id(t, 0, 0)) == get(Id(s, p, q))) ret |=
        can[p][(r + z + (3 - q) * g) % mod];
    puts(ret ? "YES" : "NO");
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

const int N = 1e6 + 5;

int n, m, q, mod, s, t, r, u[N], v[N], c[N], g, fa[N];
bool can[2][N];

int Id(int x, int y, int z) { return (x - 1) * 6 + y * 3 + z; }
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }

void link(int x, int y) {
  x = get(x);
  y = get(y);
  if (x == y)
    return;
  fa[x] = y;
}

int main() {
  scanf("%d%d%d%d", &n, &m, &q, &mod);
  fo(i, 1, m) {
    scanf("%d%d%d", &u[i], &v[i], &c[i]);
    g = __gcd(g, abs(c[i] - c[1]));
  }
  if (!g)
    g = mod;
  mod = __gcd(mod, 3 * g);
  int z = c[1] % g;
  fo(i, 0, 6 * n) fa[i] = i;
  fo(i, 1, m) {
    int w = (c[i] - z) / g;
    fo(p, 0, 1) fo(q, 0, 2) {
      link(Id(u[i], p, q), Id(v[i], 1 - p, (2 * q + w) % 3));
      link(Id(v[i], p, q), Id(u[i], 1 - p, (2 * q + w) % 3));
    }
  }
  for (int i = 0, j = z; i < mod << 1; i++, (j <<= 1) %= mod)
    can[i & 1][j] = 1;
  for (; q; q--) {
    scanf("%d%d%d", &s, &t, &r);
    int ret = 0;
    fo(p, 0, 1) fo(q, 0, 2) if (get(Id(t, 0, 0)) == get(Id(s, p, q))) ret |=
        can[p][(r + z + (3 - q) * g) % mod];
    puts(ret ? "YES" : "NO");
  }
  return 0;
}
Problem p03101 (Python)

Buggy submission (status: Runtime Error):
H, W = int(input().split())
h, w = int(input().split())

print((H - h) * (W - w))
H, W = map(int, input().split())
h, w = map(int, input().split())

print((H - h) * (W - w))


Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())

print((H - h) * (W - w))
Problem p03101 (Python)

Buggy submission (status: Runtime Error):
"""A - White Cells
https://atcoder.jp/contests/abc121/tasks/abc121_a

>>> main([3, 2], [2, 1])
1
>>> main([5, 5], [2, 3])
6
>>> main([2, 4], [2, 4])
0"""


def main(amount, portion):
    print((amount[0] - portion[0]) * (amount[1] - portion[1]))


if __name__ == "__main__":
    amount = map(int, input().split(" "))
    portion = map(int, input().split(" "))

    main(amount, portion)


Fixed submission:
"""A - White Cells
https://atcoder.jp/contests/abc121/tasks/abc121_a

>>> main([3, 2], [2, 1])
1
>>> main([5, 5], [2, 3])
6
>>> main([2, 4], [2, 4])
0"""


def main(amount, portion):
    print((amount[0] - portion[0]) * (amount[1] - portion[1]))


if __name__ == "__main__":
    amount = list(map(int, input().split(" ")))
    portion = list(map(int, input().split(" ")))

    main(amount, portion)
Problem p03101 (C++)

Buggy submission (status: Time Limit Exceeded):
/*

    author : s@if

*/

#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll, ll>
#define PII pair<int, int>
#define triplell pair<pair<ll, ll>, ll>
#define triple pair<pair<int, int>, int>
#define For(i, n) for (int i = 0; i < (int)n; i++)
#define Forn(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define forba(i, a, b) for (int i = (int)b; i >= (int)a; i--)

int dx[] = {+1, -1, +0, +0};
int dy[] = {+0, +0, +1, -1};
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int hr[] = {-2, -2, -1, +1, +2, +2, -1, +1};
int hc[] = {+1, -1, +2, +2, -1, +1, -2, -2};

const int MAXN = (int)1e5 + 9;

const int N = 100000;

int main() {
  /*	freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      ios_base::sync_with_stdio(false);
      cin.tie(0);
      cout.tie(0);  */

  int i, j, k, l, m, n, p, q, r, tc, t;

  int h, w, h1, w1;

  cin >> h >> w;
  cin >> h1 >> w1;

  h -= h1;
  w -= w1;
  cout << h * w << endl;

  main();
  return 0;
}

Fixed submission:
/*

    author : s@if

*/

#include <bits/stdc++.h>
using namespace std;
#define NIL -1
#define fi first
#define sec second
#define MAX INT_MAX
#define INF 99999999
#define ll long long
#define PI acos(-1.0)
#define MOD 1000000007
#define PLL pair<ll, ll>
#define PII pair<int, int>
#define triplell pair<pair<ll, ll>, ll>
#define triple pair<pair<int, int>, int>
#define For(i, n) for (int i = 0; i < (int)n; i++)
#define Forn(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define forba(i, a, b) for (int i = (int)b; i >= (int)a; i--)

int dx[] = {+1, -1, +0, +0};
int dy[] = {+0, +0, +1, -1};
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int hr[] = {-2, -2, -1, +1, +2, +2, -1, +1};
int hc[] = {+1, -1, +2, +2, -1, +1, -2, -2};

const int MAXN = (int)1e5 + 9;

const int N = 100000;

int main() {
  /*	freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      ios_base::sync_with_stdio(false);
      cin.tie(0);
      cout.tie(0);  */

  int i, j, k, l, m, n, p, q, r, tc, t;

  int h, w, h1, w1;

  cin >> h >> w;
  cin >> h1 >> w1;

  h -= h1;
  w -= w1;
  cout << h * w << endl;

  //	main();
  return 0;
}
Problem p03101 (Python)

Buggy submission (status: Runtime Error):
H, W, h, w = map(int, input().split())
print((H - h) * (W - w))


Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())
print((H - h) * (W - w))
Problem p03101 (C++)

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

using namespace std;

int main() {
  int H, W, h, w;
  cin >> H;
  cin >> W;
  cin >> h;
  cin >> w;

  return (H - h) * (W - w);
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int H, W, h, w;
  cin >> H;
  cin >> W;
  cin >> h;
  cin >> w;

  cout << (H - h) * (W - w);
  return 0;
}
Problem p03101 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a.begin(), a.end());
  bool s = true;
  int cnt = 0, ans = 0;
  while (s) {
    for (int i = 0; i < 100000; i++) {
      if (cnt < m) {
        ans = ans + a[i] * b[i];
        cnt += b[i];
      }
      if (cnt = m) {
        bool s = false;
        break;
      }
    }
  }
  cout << ans;
}

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

int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;

  cout << (H - h) * (W - w) << endl;
}
Problem p03101 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int H, W, h, w;

  cin >> H >> W;
  cin >> h >> w;

  int all = H * W;

  all = all - W * h - H * w + h * w;
  cout << all << endl;
  return all;
}

Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int H, W, h, w;

  cin >> H >> W;
  cin >> h >> w;

  int all = H * W;

  all = all - W * h - H * w + h * w;
  cout << all << endl;
  return 0;
}
Problem p03101 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define X first
#define Y second
#define PB push_back
#define eps 1e-9
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int maxn = 1e6 + 7;

inline int read() {
  int ret = 0, c, f = 1;
  for (c = getchar(); !(isdigit(c) || c == '-'); c = getchar())
    ;
  if (c == '-')
    f = -1, c = getchar();
  for (; isdigit(c); c = getchar())
    ret = ret * 10 + c - '0';
  if (f < 0)
    ret = -ret;
  return ret;
}

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("i.txt", "r", stdin);
  freopen("o.txt", "w", stdout);
#endif

  int a, b;
  cin >> a >> b;
  int ans = a * b;

  int x, y;
  cin >> x >> y;
  cout << (a - x) * (b - y);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
#define X first
#define Y second
#define PB push_back
#define eps 1e-9
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

const int maxn = 1e6 + 7;

inline int read() {
  int ret = 0, c, f = 1;
  for (c = getchar(); !(isdigit(c) || c == '-'); c = getchar())
    ;
  if (c == '-')
    f = -1, c = getchar();
  for (; isdigit(c); c = getchar())
    ret = ret * 10 + c - '0';
  if (f < 0)
    ret = -ret;
  return ret;
}

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("i.txt", "r", stdin);
  // freopen("o.txt", "w", stdout);
  // #endif

  int a, b;
  cin >> a >> b;
  int ans = a * b;

  int x, y;
  cin >> x >> y;
  cout << (a - x) * (b - y);
}
Problem p03101 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FastRead                                                               \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long int
#define FOR(i, a, n) for (int i = (a); i <= (n); ++i)
#define RFOR(i, a, n) for (int i = (n); i >= (a); --i)
#define FI(i, n) for (int i = 0; i < (n); ++i)
#define ZERO(a) memset((a), 0, sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(), g.end()
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including
// tree_order_statistics_node_updat using namespace __gnu_pbds; typedef tree<ll,
// null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// ordered_set;

// I am questioning life and universe and
// everything else after looking at this

void solve() {
  ll H, W, h, w;
  cin >> H >> W >> h >> w;

  ll ans = H * W - h * W - w * H + h * w;
  cout << ans << endl;
}

signed main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  FastRead;

  int t;
  t = 1;
  // cin>>t;

  while (t--)
    solve();
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FastRead                                                               \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long int
#define FOR(i, a, n) for (int i = (a); i <= (n); ++i)
#define RFOR(i, a, n) for (int i = (n); i >= (a); --i)
#define FI(i, n) for (int i = 0; i < (n); ++i)
#define ZERO(a) memset((a), 0, sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(), g.end()
int fastMax(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y; }
int fastMin(int x, int y) { return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including
// tree_order_statistics_node_updat using namespace __gnu_pbds; typedef tree<ll,
// null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
// ordered_set;

// I am questioning life and universe and
// everything else after looking at this

void solve() {
  ll H, W, h, w;
  cin >> H >> W >> h >> w;

  ll ans = H * W - h * W - w * H + h * w;
  cout << ans << endl;
}

signed main() {

  // #ifndef ONLINE_JUDGE
  //     freopen("input.txt", "r", stdin);
  //     freopen("output.txt", "w", stdout);
  // #endif

  FastRead;

  int t;
  t = 1;
  // cin>>t;

  while (t--)
    solve();
}
Problem p03101 (C++)

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

  //*
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  //*/

  /*
  vector<int> vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

  sort(vec.begin(), vec.end());
  //*/

  /*
  if( b / a < c ){
      cout << b / a << endl;
  } else {
      cout << c << endl;
  }
  //*/

  cout << (a - c) / (b - d) << endl;

  return 0;
}


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

  //*
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  //*/

  /*
  vector<int> vec(3);
  cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;

  sort(vec.begin(), vec.end());
  //*/

  /*
  if( b / a < c ){
      cout << b / a << endl;
  } else {
      cout << c << endl;
  }
  //*/

  cout << (a - c) * (b - d) << endl;

  return 0;
}
Problem p03101 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int H, W, h, w;

  cin >> H >> W;
  cin >> h >> w;

  int all = H * W;

  all = all - W * h - H * w + h * w;
  cout << all;
  return all;
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int H, W, h, w;

  cin >> H >> W;
  cin >> h >> w;

  int all = H * W;

  all = all - W * h - H * w + h * w;
  cout << all << endl;
  return 0;
}
Problem p03102 (C++)

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; i < m; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < m; j++) {
      sum += a[i][j] * b[j];
    }
    sum += c;
    if (sum > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < m; j++) {
      sum += a[i][j] * b[j];
    }
    sum += c;
    if (sum > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03102 (C++)

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

using namespace std;

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(1);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  int y = 0;
  for (int i = 0; i < n; i++) {
    long long int x = 0;
    for (int j = 0; j < m; j++) {
      x += a[i][j] * b[j];
    }
    x += c;
    if (x > 0) {
      y++;
    }
  }
  cout << y << endl;
  return 0;
}

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

using namespace std;

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }
  vector<vector<int>> a(n, vector<int>(m));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }

  int y = 0;
  for (int i = 0; i < n; i++) {
    long long int x = 0;
    for (int j = 0; j < m; j++) {
      x += a[i][j] * b[j];
    }
    x += c;
    if (x > 0) {
      y++;
    }
  }
  cout << y << endl;
  return 0;
}
Problem p03102 (C++)

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(n);
  rep(i, m) cin >> b[i];

  int ans = 0;
  rep(i, n) {
    int sum = 0;
    rep(j, m) {
      int a;
      cin >> a;
      sum += a * b[j];
    }
    if (sum > -c)
      ans++;
  }
  cout << ans << endl;
}

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

int main() {
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  rep(i, m) cin >> b[i];

  int ans = 0;
  rep(i, n) {
    int sum = 0;
    rep(j, m) {
      int a;
      cin >> a;
      sum += a * b[j];
    }
    if (sum > -c)
      ans++;
  }
  cout << ans << endl;
}