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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define fi first
#define se second

#define INF 2147483600

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);
  rep(i, m) scanf("%d", &vec[i]);

  vector<bool> used(n + 1, false);
  for (int i = m - 1; i >= 0; i--) {
    if (!used[vec[i]])
      printf("%d\n", vec[i]);
    used[vec[i]] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      printf("%d\n", i);
    }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define fi first
#define se second

#define INF 2147483600

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(m);
  rep(i, m) scanf("%d", &vec[i]);

  vector<bool> used(n + 1, false);
  for (int i = m - 1; i >= 0; i--) {
    if (!used[vec[i]])
      printf("%d\n", vec[i]);
    used[vec[i]] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!used[i]) {
      printf("%d\n", i);
    }

  return 0;
}
Problem p00946 (C++)

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

int n, m;
int e[200000];

int main() {
  int i;

  cin >> n >> m;
  for (i = 0; i < m; i++)
    cin >> e[i];

  bool used[100001] = {false};
  for (i = m - 1; i >= 0; i--) {
    if (!used[e[i]]) {
      used[e[i]] = true;
      cout << e[i] << endl;
    }
  }
  for (i = 1; i <= n; i++) {
    if (!used[i])
      cout << i << endl;
  }
  return 0;
}

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

int n, m;
int e[200000];

int main() {
  int i;

  cin >> n >> m;
  for (i = 0; i < m; i++)
    cin >> e[i];

  static bool used[200001] = {false};
  for (i = m - 1; i >= 0; i--) {
    if (!used[e[i]]) {
      used[e[i]] = true;
      cout << e[i] << endl;
    }
  }
  for (i = 1; i <= n; i++) {
    if (!used[i])
      cout << i << endl;
  }
  return 0;
}
Problem p00946 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n + 1, 0);
  vector<int> ans(m);

  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    ans[i] = a;
    used[a] = 1;
  }

  vector<int> syu(m + 1, 0);

  for (int i = 0; i < m; i++) {
    if (syu[ans[m - i - 1]] != 1) {
      cout << ans[m - i - 1] << endl;
      syu[ans[m - i - 1]] = 1;
    }
  }

  for (int i = 1; i < n + 1; i++) {
    if (used[i] == 0)
      cout << i << endl;
  }

  return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> used(n + 1, 0);
  vector<int> ans(m);

  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    ans[i] = a;
    used[a] = 1;
  }

  vector<int> syu(n + 1, 0);

  for (int i = 0; i < m; i++) {
    if (syu[ans[m - i - 1]] != 1) {
      cout << ans[m - i - 1] << endl;
      syu[ans[m - i - 1]] = 1;
    }
  }

  for (int i = 1; i < n + 1; i++) {
    if (used[i] == 0)
      cout << i << endl;
  }

  return 0;
}
Problem p00946 (C++)

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

int N, M; //?度? n 的序列,有 m 个操作
int F[20500];
bool Jud[20500];

int main() {
  cin >> N >> M;
  memset(Jud, true, sizeof(Jud));
  for (int i = 1; i <= M; i++)
    cin >> F[i];
  for (int i = M; i >= 1; i--)
    if (Jud[F[i]] == true) {
      Jud[F[i]] = false;
      cout << F[i] << endl;
    }
  for (int i = 1; i <= N; i++)
    if (Jud[i] == true)
      cout << i << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int N, M; //?度? n 的序列,有 m 个操作
int F[205000];
bool Jud[205000];

int main() {
  cin >> N >> M;
  memset(Jud, true, sizeof(Jud));
  for (int i = 1; i <= M; i++)
    cin >> F[i];
  for (int i = M; i >= 1; i--)
    if (Jud[F[i]] == true) {
      Jud[F[i]] = false;
      cout << F[i] << endl;
    }
  for (int i = 1; i <= N; i++)
    if (Jud[i] == true)
      cout << i << endl;
  return 0;
}
Problem p00946 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool b[114514];
int n, m;
vector<int> l;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    b[i] = false;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    l.push_back(a);
  }
  for (int i = 1; i <= m; i++) {
    if (!b[l[m - i]])
      cout << l[m - i] << endl;
    b[l[m - i]] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!b[i])
      cout << i << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool b[229028];
int n, m;
vector<int> l;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    b[i] = false;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    l.push_back(a);
  }
  for (int i = 1; i <= m; i++) {
    if (!b[l[m - i]])
      cout << l[m - i] << endl;
    b[l[m - i]] = true;
  }
  for (int i = 1; i <= n; i++)
    if (!b[i])
      cout << i << endl;
}
Problem p00948 (C++)

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

struct Pos {
  int y, x;
  Pos() {}
  Pos(int y, int x) {
    this->y = y;
    this->x = x;
  }
  bool operator<(const Pos &r) const { return (y != r.y) ? y < r.y : x < r.x; }
};

int n, m;
Pos arm[100000];
int dp[2][100000];

//?§??????????(dir=0:???, dir=1:???), (?????£????????£???)??¢???????????????id,
//??????????????????????????´???(0-indexed)?????????
int dfs(int dir, int id) {
  int nextId;

  if (dir == 0) {
    nextId = upper_bound(arm, arm + m, Pos(arm[id].y - 1, arm[id].x)) - 1 - arm;
    if (nextId < 0 || arm[nextId].y != arm[id].y - 1)
      return arm[id].y;
    return dp[dir][id] = dfs(dir, nextId);
  }

  nextId = upper_bound(arm, arm + m, Pos(arm[id].y + 1, arm[id].x)) - 1 - arm;
  if (nextId < 0 || arm[nextId].y != arm[id].y + 1)
    return arm[id].y + 1;
  return dp[dir][id] = dfs(dir, nextId);
}

int main() {
  int i, j;

  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> arm[i].x >> arm[i].y;
    arm[i].y--;
  }
  sort(arm, arm + m);

  for (i = 0; i < 2; i++)
    for (j = 0; j < m; j++)
      dp[i][j] = -1;

  int id;
  for (i = 0; i < n; i++) {
    id = lower_bound(arm, arm + m, Pos(i, -1)) - 1 - arm;
    int low = ((id < 0 || arm[id].y != i - 1) ? i : dfs(0, id));
    id = lower_bound(arm, arm + m, Pos(i + 1, -1)) - 1 - arm;
    int high = ((id < 0 || arm[id].y != i) ? i : dfs(1, id));
    cout << high - low + 1;
    if (i + 1 < n)
      cout << " ";
  }
  cout << endl;
  return 0;
}

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

struct Pos {
  int y, x;
  Pos() {}
  Pos(int y, int x) {
    this->y = y;
    this->x = x;
  }
  bool operator<(const Pos &r) const { return (y != r.y) ? y < r.y : x < r.x; }
};

int n, m;
Pos arm[100000];
int dp[2][100000];

//?§??????????(dir=0:???, dir=1:???), (?????£????????£???)??¢???????????????id,
//??????????????????????????´???(0-indexed)?????????
int dfs(int dir, int id) {
  int nextId;

  if (dp[dir][id] != -1) {
    return dp[dir][id];
  }

  if (dir == 0) {
    nextId = upper_bound(arm, arm + m, Pos(arm[id].y - 1, arm[id].x)) - 1 - arm;
    if (nextId < 0 || arm[nextId].y != arm[id].y - 1)
      return arm[id].y;
    return dp[dir][id] = dfs(dir, nextId);
  }

  nextId = upper_bound(arm, arm + m, Pos(arm[id].y + 1, arm[id].x)) - 1 - arm;
  if (nextId < 0 || arm[nextId].y != arm[id].y + 1)
    return arm[id].y + 1;
  return dp[dir][id] = dfs(dir, nextId);
}

int main() {
  int i, j;

  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> arm[i].x >> arm[i].y;
    arm[i].y--;
  }
  sort(arm, arm + m);

  for (i = 0; i < 2; i++)
    for (j = 0; j < m; j++)
      dp[i][j] = -1;

  int id;
  for (i = 0; i < n; i++) {
    id = lower_bound(arm, arm + m, Pos(i, -1)) - 1 - arm;
    int low = ((id < 0 || arm[id].y != i - 1) ? i : dfs(0, id));
    id = lower_bound(arm, arm + m, Pos(i + 1, -1)) - 1 - arm;
    int high = ((id < 0 || arm[id].y != i) ? i : dfs(1, id));
    cout << high - low + 1;
    if (i + 1 < n)
      cout << " ";
  }
  cout << endl;
  return 0;
}
Problem p00949 (C++)

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  if (S.length() > T.length()) {
    swap(S, T);
  }
  vector<vector<int>> memo(S.length() + 1, vector<int>(26));
  for (int i = 0; i < S.length(); i++) {
    memo[i + 1] = memo[i];
    memo[i + 1][S[i] - 'a']++;
  }
  vector<vector<int>> memo2(T.length() + 1, vector<int>(26));
  for (int i = 0; i < T.length(); i++) {
    memo2[i + 1] = memo2[i];
    memo2[i + 1][T[i] - 'a']++;
  }
  {
    bool f = false;
    for (int i = 0; i < 26; i++) {
      if (memo[S.length()][i] && memo2[T.length()][i]) {
        f = true;
        break;
      }
    }
    if (!f) {
      cout << 0 << endl;
      return 0;
    }
  }

  vector<int> now(26);
  int ans = 0;
  for (int i = 0; i < memo.size(); i++) {
    for (int j = memo.size() - 1; j > i + ans; j--) {
      for (int l = 0; l + j - i < memo2.size(); l++) {
        int m = l + j - i;
        bool f = true;
        for (int k = 0; k < 26; k++) {
          if (memo[j][k] - memo[i][k] - memo2[m][k] + memo2[l][k] != 0) {
            f = false;
            break;
          }
        }
        if (f) {
          ans = max(ans, j - i);
          break;
        }
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  if (S.length() > T.length()) {
    swap(S, T);
  }
  vector<vector<int>> memo(S.length() + 1, vector<int>(26));
  for (int i = 0; i < S.length(); i++) {
    memo[i + 1] = memo[i];
    memo[i + 1][S[i] - 'a']++;
  }
  vector<vector<int>> memo2(T.length() + 1, vector<int>(26));
  for (int i = 0; i < T.length(); i++) {
    memo2[i + 1] = memo2[i];
    memo2[i + 1][T[i] - 'a']++;
  }
  {
    bool f = false;
    for (int i = 0; i < 26; i++) {
      if (memo[S.length()][i] && memo2[T.length()][i]) {
        f = true;
        break;
      }
    }
    if (!f) {
      cout << 0 << endl;
      return 0;
    }
  }

  vector<int> now(26);
  int ans = 0;
  for (int len = S.length(); len >= 1; len--) {
    set<vector<int>> SVI;
    for (int i = 0; i + len < memo.size(); i++) {
      for (int k = 0; k < 26; k++) {
        now[k] = memo[i + len][k] - memo[i][k];
      }
      SVI.insert(now);
    }
    for (int i = 0; i + len < memo2.size(); i++) {
      for (int k = 0; k < 26; k++) {
        now[k] = memo2[i + len][k] - memo2[i][k];
      }
      if (SVI.count(now)) {
        cout << len << endl;
        return 0;
      }
    }
  }

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

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

#define MAXN 500000

bitset<MAXN + 1 + 1> b;
bool full[MAXN + 1 + 1];
int lowest = -1;

bool ok(int depth) {
  if (b[0])
    return false;
  return depth > MAXN || !full[depth] || depth >= lowest;
}

void add(int depth) {
  lowest = max(lowest, depth);
  if (depth >= MAXN)
    return;
  while (1) {
    if (b[depth]) {
      b.reset(depth--);
    } else {
      b.set(depth);
      break;
    }
  }
  if (!b[lowest])
    lowest = depth;
  if (depth == 0)
    return;
  while (full[depth - 1] && !full[depth] && b[depth]) {
    full[depth++] = true;
  }
}

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

  full[0] = true;
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    if (ok(x)) {
      add(x);
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
#define INF (1 << 29)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define uniq(v) v.erase(unique(all(v)), v.end())

#define MAXN 500000

bitset<MAXN + 1 + 1> b;
bool full[MAXN + 1 + 1];
int lowest = -1;

bool ok(int depth) {
  if (b[0])
    return false;
  return depth > MAXN || !full[depth] || depth >= lowest;
}

void add(int depth) {
  lowest = max(lowest, depth);
  if (depth >= MAXN)
    return;
  while (1) {
    if (b[depth]) {
      b.reset(depth--);
    } else {
      b.set(depth);
      break;
    }
  }
  if (lowest <= MAXN && !b[lowest])
    lowest = depth;
  if (depth == 0)
    return;
  while (full[depth - 1] && !full[depth] && b[depth]) {
    full[depth++] = true;
  }
}

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

  full[0] = true;
  int n;
  cin >> n;
  rep(i, n) {
    int x;
    cin >> x;
    if (ok(x)) {
      add(x);
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}
Problem p00952 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
int b[500000], p = 1, cnt = 0;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (b[0] == 1 || x < p - 1) {
      cout << "No" << endl;
      continue;
    }
    if (p - 1 == x && cnt > x) {
      cout << "No" << endl;
      continue;
    }
    cnt++;
    cout << "Yes" << endl;
    if (x >= n)
      continue;
    b[x]++;
    int j = x;
    while (j > 0 && b[j] >= 2)
      b[j] -= 2, b[j - 1]++, j--, cnt--;
    p = 1;
    while (p < n && b[p] == 1)
      p++;
  }
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
int b[500000], p = 1, cnt = 0;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (b[0] == 1 || x < p - 1) {
      cout << "No" << endl;
      continue;
    }
    if (p - 1 == x && cnt > x) {
      cout << "No" << endl;
      continue;
    }
    cnt++;
    cout << "Yes" << endl;
    if (x >= n)
      continue;
    b[x]++;
    while (x > 0 && b[x] >= 2)
      b[x] -= 2, b[x - 1]++, x--, cnt--;
    while (p < n && b[p] == 1)
      p++;
  }
}
Problem p00959 (C++)

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

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

int main() {
  int n;
  ll t, h[SIZE];

  scanf("%d%lld", &n, &t);

  ll start = 0;
  ll maxh = 0;
  ll sum = 0;
  ll l = 0;

  for (int i = 0; i < n; i++) {
    scanf("%lld", h + i);

    if (i > 0 && maxh <= h[i]) {
      debug(i);
      ll pos = (t - start) / h[l];
      printf("%lld\n", max(pos + 1, 1LL));
      ll subsum = 0;

      for (int j = l + 1; j < i; j++) {
        subsum += h[j];

        while (t - start < subsum + pos * h[l])
          pos--;

        printf("%lld\n", max(pos + 1, 1LL));
      }

      l = i;
      start += sum;
      maxh = h[i];
      sum = h[i];
    } else {
      sum += h[i];
      if (i == 0)
        maxh = h[0];
    }
  }

  ll pos = (t - start) / h[l];
  printf("%lld\n", max(pos + 1, 1LL));
  ll subsum = 0;

  for (int j = l + 1; j < n; j++) {
    subsum += h[j];

    while (t - start < subsum + pos * h[l])
      pos--;

    printf("%lld\n", max(pos + 1, 1LL));
  }

  return 0;
}


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

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <complex>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;

#define mod 1000000007              // 1e9+7(prime number)
#define INF 1000000000              // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010

int main() {
  int n;
  ll t, h[SIZE];

  scanf("%d%lld", &n, &t);

  ll start = 0;
  ll maxh = 0;
  ll sum = 0;
  ll l = 0;

  for (int i = 0; i < n; i++) {
    scanf("%lld", h + i);

    if (i > 0 && maxh <= h[i]) {
      ll pos = (t - start) / h[l];
      printf("%lld\n", max(pos + 1, 1LL));
      ll subsum = 0;

      for (int j = l + 1; j < i; j++) {
        subsum += h[j];

        while (t - start < subsum + pos * h[l])
          pos--;

        printf("%lld\n", max(pos + 1, 1LL));
      }

      l = i;
      start += sum;
      maxh = h[i];
      sum = h[i];
    } else {
      sum += h[i];
      if (i == 0)
        maxh = h[0];
    }
  }

  ll pos = (t - start) / h[l];
  printf("%lld\n", max(pos + 1, 1LL));
  ll subsum = 0;

  for (int j = l + 1; j < n; j++) {
    subsum += h[j];

    while (t - start < subsum + pos * h[l])
      pos--;

    printf("%lld\n", max(pos + 1, 1LL));
  }

  return 0;
}
Problem p00965 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

#define FRER() freopen("i.txt", "r", stdin);

using namespace std;

const int maxn = 100000 + 5;

int l[maxn], r[maxn], ml[maxn] = {0}, mr[maxn] = {0}, sum[maxn] = {0};

int main() {
  int n, ans1 = 0, ans2 = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &l[i], &r[i]);
    ++sum[l[i]];
    --sum[r[i]];
    ++ml[l[i]];
    ++mr[r[i]];
  }
  for (int i = 1; i < maxn; ++i) {
    sum[i] += sum[i - 1];
    ml[i] += ml[i - 1];
    mr[i] += mr[i - 1];
    ans2 = max(ans2, sum[i]);
  }
  for (int i = 0; i < n; ++i) {
    ans1 = max(ans1, ml[r[i] - 1] - mr[l[i]]);
  }
  printf("%d %d\n", ans1, ans2);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

#define FRER() freopen("i.txt", "r", stdin);

using namespace std;

const int maxn = 200000 + 5;

int l[maxn], r[maxn], ml[maxn] = {0}, mr[maxn] = {0}, sum[maxn] = {0};

int main() {
  int n, ans1 = 0, ans2 = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &l[i], &r[i]);
    ++sum[l[i]];
    --sum[r[i]];
    ++ml[l[i]];
    ++mr[r[i]];
  }
  for (int i = 1; i < maxn; ++i) {
    sum[i] += sum[i - 1];
    ml[i] += ml[i - 1];
    mr[i] += mr[i - 1];
    ans2 = max(ans2, sum[i]);
  }
  for (int i = 0; i < n; ++i) {
    ans1 = max(ans1, ml[r[i] - 1] - mr[l[i]]);
  }
  printf("%d %d\n", ans1, ans2);
  return 0;
}
Problem p00991 (C++)

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

int d[1000][1000], ans[1000][1000];
int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
int main() {
  int r, c, x1, y1, x2, y2;
  cin >> r >> c >> x1 >> y1 >> x2 >> y2;
  queue<P> que;
  memset(d, -1, sizeof(d));
  ans[x1][y1] = 1;
  d[x1][y1] = 0;
  que.push(P(x1, y1));
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    rep(i, 4) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      int a = 0;
      /*	if(nx<0||nx>=r){
                      nx=(nx+r)%r;a++;
              }
              if(ny<0||ny>=c){
                      ny=(ny+c)%c;a++;
              }
              if(a==2)continue;*/
      if (d[nx][ny] == -1) {
        d[nx][ny] = d[p.first][p.second] + 1;
        que.push(P(nx, ny));
      }
      if (d[nx][ny] == d[p.first][p.second] + 1)
        (ans[nx][ny] += ans[p.first][p.second]) %= MOD;
    }
  }
  printf("%d\n", ans[x2][y2]);
}

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

int d[1000][1000], ans[1000][1000];
int dx[]{1, -1, 0, 0}, dy[]{0, 0, 1, -1};
int main() {
  int r, c, x1, y1, x2, y2;
  cin >> r >> c >> x1 >> y1 >> x2 >> y2;
  queue<P> que;
  memset(d, -1, sizeof(d));
  ans[x1][y1] = 1;
  d[x1][y1] = 0;
  que.push(P(x1, y1));
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    rep(i, 4) {
      int nx = (p.first + dx[i] + r) % r, ny = (p.second + dy[i] + c) % c;
      if (d[nx][ny] == -1) {
        d[nx][ny] = d[p.first][p.second] + 1;
        que.push(P(nx, ny));
      }
      if (d[nx][ny] == d[p.first][p.second] + 1)
        (ans[nx][ny] += ans[p.first][p.second]) %= MOD;
    }
  }
  printf("%d\n", ans[x2][y2]);
}
Problem p00993 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <iostream>
using namespace std;
#define MAX_P 50000
int n;
int dp[5010][MAX_P];
void fact(int n) {
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < MAX_P; j++) {
      dp[i][j] += dp[i - 1][j] * i;
      if (dp[i][j] >= 10) {
        dp[i][j + 1] += dp[i][j] / 10;
        dp[i][j] %= 10;
      }
    }
  }
  dp[n][0] += 2;
  for (int j = 0; j < MAX_P; j++) {
    if (dp[n][j] >= 10) {
      dp[n][j + 1] += dp[n][j] / 10;
      dp[n][j] %= 10;
    }
  }
}
int main() {
  cin >> n;
  fact(n + 1);
  int ok = 0;
  for (int i = MAX_P - 1; i >= 0; i--) {
    if (dp[n + 1][i] >= 1) {
      ok = 1;
    }
    if (ok == 1) {
      cout << dp[n + 1][i];
    }
  }
  cout << endl;
  for (int i = 2; i < n + 2; i++) {
    cout << i << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
#define MAX_P 20000
int n;
int dp[5010][MAX_P];
void fact(int n) {
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < MAX_P; j++) {
      dp[i][j] += dp[i - 1][j] * i;
      if (dp[i][j] >= 10) {
        dp[i][j + 1] += dp[i][j] / 10;
        dp[i][j] %= 10;
      }
    }
  }
  dp[n][0] += 2;
  for (int j = 0; j < MAX_P; j++) {
    if (dp[n][j] >= 10) {
      dp[n][j + 1] += dp[n][j] / 10;
      dp[n][j] %= 10;
    }
  }
}
int main() {
  cin >> n;
  fact(n + 1);
  int ok = 0;
  for (int i = MAX_P - 1; i >= 0; i--) {
    if (dp[n + 1][i] >= 1) {
      ok = 1;
    }
    if (ok == 1) {
      cout << dp[n + 1][i];
    }
  }
  cout << endl;
  for (int i = 2; i < n + 2; i++) {
    cout << i << endl;
  }
  return 0;
}
Problem p00997 (C++)

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

using namespace std;

#define MAX 100000

class Union_Find {
public:
  int par[MAX], rnk[MAX], sz[MAX], gnum;

  Union_Find(int N) {
    gnum = N;
    for (int i = 0; i < N; i++) {
      par[i] = i;
      rnk[i] = 0;
      sz[i] = 1;
    }
  }

  int find(int x) {
    if (par[x] == x) {
      return x;
    }
    return par[x] = find(par[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;

    if (rnk[x] < rnk[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      if (rnk[x] == rnk[y]) {
        rnk[x]++;
      }
    }
    gnum--;
  }

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

  int size(int x) { return sz[find(x)]; }

  int groups() { return gnum; }
};

struct edge {
  int u, v, cost;
};

bool comp(const edge &a, const edge &b) { return a.cost < b.cost; }

using ll = long long;

edge es[MAX];

ll solve(int N) {
  Union_Find uf(N);
  sort(es, es + N - 1, comp);

  ll res = 0;
  for (int i = 0; i < N - 1; i++) {
    edge &e = es[i];
    if (!uf.same(e.u, e.v)) {
      res += (ll)uf.size(e.u) * uf.size(e.v) * e.cost;
      uf.unite(e.u, e.v);
    }
  }
  return res;
}

int main() {
  int N, a, b, c;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b >> c;
    es[i] = {a, b, c};
  }
  cout << solve(N) << endl;
  return 0;
}

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

using namespace std;

#define MAX 252521

class Union_Find {
public:
  int par[MAX], rnk[MAX], sz[MAX], gnum;

  Union_Find(int N) {
    gnum = N;
    for (int i = 0; i < N; i++) {
      par[i] = i;
      rnk[i] = 0;
      sz[i] = 1;
    }
  }

  int find(int x) {
    if (par[x] == x) {
      return x;
    }
    return par[x] = find(par[x]);
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;

    if (rnk[x] < rnk[y]) {
      par[x] = y;
      sz[y] += sz[x];
    } else {
      par[y] = x;
      sz[x] += sz[y];
      if (rnk[x] == rnk[y]) {
        rnk[x]++;
      }
    }
    gnum--;
  }

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

  int size(int x) { return sz[find(x)]; }

  int groups() { return gnum; }
};

struct edge {
  int u, v, cost;
};

bool comp(const edge &a, const edge &b) { return a.cost < b.cost; }

using ll = long long;

edge es[MAX];

ll solve(int N) {
  Union_Find uf(N);
  sort(es, es + N - 1, comp);

  ll res = 0;
  for (int i = 0; i < N - 1; i++) {
    edge &e = es[i];
    if (!uf.same(e.u, e.v)) {
      res += (ll)uf.size(e.u) * uf.size(e.v) * e.cost;
      uf.unite(e.u, e.v);
    }
  }
  return res;
}

int main() {
  int N, a, b, c;
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b >> c;
    es[i] = {a, b, c};
  }
  cout << solve(N) << endl;
  return 0;
}
Problem p01006 (C++)

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

string s[3] = {"ABC", "DEF", "GHI"}, pass;
int vx[4] = {-1, 0, 1, 0}, vy[4] = {0, -1, 0, 1};

bool search(int cnt, int n) {
  if (cnt == pass.size() - 1)
    return true;

  bool ret = false;

  for (int i = 0; i < 4; ++i) {
    int nx = n / 3 + vx[i], ny = n % 3 + vy[i];

    if (0 <= nx && nx <= 3 && 0 <= ny && ny <= 3) {
      if (pass[cnt + 1] == s[nx][ny]) {
        ret = search(cnt + 1, pass[cnt + 1] - 'A');
        if (ret)
          return ret;
      }
    }
  }

  return false;
}

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

  for (int i = 0; i < 1000; ++i) {
    cin >> pass;
    int num = pass[0] - 'A';
    if (search(0, num))
      cout << pass << endl;
  }

  return 0;
}

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

string s[3] = {"ABC", "DEF", "GHI"}, pass;
int vx[4] = {-1, 0, 1, 0}, vy[4] = {0, -1, 0, 1};

bool search(int cnt, int n) {
  if (cnt == pass.size() - 1)
    return true;

  bool ret = false;

  for (int i = 0; i < 4; ++i) {
    int nx = n / 3 + vx[i], ny = n % 3 + vy[i];

    if (0 <= nx && nx <= 2 && 0 <= ny && ny <= 2) {
      if (pass[cnt + 1] == s[nx][ny]) {
        ret = search(cnt + 1, pass[cnt + 1] - 'A');
        if (ret)
          return ret;
      }
    }
  }

  return false;
}

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

  for (int i = 0; i < 1000; ++i) {
    cin >> pass;
    int num = pass[0] - 'A';
    if (search(0, num))
      cout << pass << endl;
  }

  return 0;
}
Problem p01012 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-8;

//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"

ld getans(ld l, ld r, int b, ld c) {
  if (b == 0 || abs(r - l) < eps) {
    return (1 - l) * (r - l);
  }
  ld aa = getans(l, (1 - c) * l + c * r, b - 1, c);
  ld ab = getans((1 - c) * l + c * r, r, b - 1, c);
  return aa + ab;
}
ld get() {
  int m, n, x;
  cin >> m >> n >> x;
  ld c = (ld(m)) / (m + n);
  x = min(x, 40);
  return getans(0, 1, x, c);
}

int main() {
  ld a = get();
  ld b = get();
  cout << setprecision(10) << fixed << a * b << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-7;

//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"

ld getans(ld l, ld r, int b, ld c) {
  if (b == 0 || abs(r - l) < eps) {
    return (1 - l) * (r - l);
  }
  ld aa = getans(l, (1 - c) * l + c * r, b - 1, c);
  ld ab = getans((1 - c) * l + c * r, r, b - 1, c);
  return aa + ab;
}
ld get() {
  int m, n, x;
  cin >> m >> n >> x;
  ld c = (ld(m)) / (m + n);
  x = min(x, 40);
  return getans(0, 1, x, c);
}

int main() {
  ld a = get();
  ld b = get();
  cout << setprecision(10) << fixed << a * b << endl;
  return 0;
}
Problem p01048 (C++)

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

#define Int long long int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REAP(i, a, n) for (int i = (a); i < (n); i++)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(), v.end()

int main() {
  int n;
  cin >> n;
  int num = 0;
  while (1) {
    num++;
    int cou = 0;
    REAP(i, 1, num + 1) {
      if (!num % i)
        cou++;
    }
    if (cou == n) {
      cout << num << endl;
      break;
    }
  }
}


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

#define Int long long int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REAP(i, a, n) for (int i = (a); i < (n); i++)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(), v.end()

int main() {
  int n;
  cin >> n;
  int num = 0;
  while (1) {
    num++;
    int cou = 0;
    REAP(i, 1, num + 1) {
      if (num % i == 0)
        cou++;
    }
    if (cou == n) {
      cout << num << endl;
      break;
    }
  }
}
Problem p01052 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define N 101
#define INF (1e9)
using namespace std;
int n, a[N], b[N], ans, c;
bool used[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= 31; i++) {
    c = INF;
    for (int j = 0; j < n; j++)
      if (!used[j] && a[j] <= i && i <= b[j] && b[j] <= b[c])
        c = j;
    if (c != INF)
      used[c] = true;
  }
  for (int i = 0; i < n; i++)
    if (used[i])
      ans++;
  cout << ans * 100 + (31 - ans) * 50 << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#define N 101
#define INF (1e9)
using namespace std;
int n, a[N], b[N], ans, c;
bool used[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  for (int i = 1; i <= 31; i++) {
    c = INF;
    for (int j = 0; j < n; j++)
      if (!used[j] && a[j] <= i && i <= b[j]) {
        if (c == INF)
          c = j;
        else if (b[j] < b[c])
          c = j;
      }
    if (c != INF)
      used[c] = true;
  }
  for (int i = 0; i < n; i++)
    if (used[i])
      ans++;
  cout << ans * 100 + (31 - ans) * 50 << endl;
  return 0;
}
Problem p01057 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/rope>
#define REP(x, y, z) for (int x = y; x <= z; x++)
#define FORD(x, y, z) for (int x = y; x >= z; x--)
#define MSET(x, y) memset(x, y, sizeof(x))
#define FOR(x, y) for (__typeof(y.begin()) x = y.begin(); x != y.end(); x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 200005
void RI() {}
template <typename... T> void RI(int &head, T &...tail) {
  scanf("%d", &head);
  RI(tail...);
}
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
int n, q;
rope<char> in[M], t1, t2;
char buf[M * 2];
int main() {
  int a, b, c, d;
  int z;
  RI(n, q);
  REP(i, 1, n) {
    scanf("%s", buf);
    in[i] = buf;
  }

  while (q--) {
    RI(z);
    if (z == 1) {
      RI(a, b, c, d);

      t1 = in[a].substr(b - 1, in[a].length() - b + 1);
      t2 = in[c].substr(d - 1, in[c].length() - d + 1);

      in[a] = in[a].substr(0, b - 1) + t2;
      in[c] = in[c].substr(0, d - 1) + t1;
    } else {
      RI(a, b);
      scanf("%s", buf);

      t1 = buf;

      int len = in[a].length();
      in[a] = in[a].substr(0, b - 1) + t1 + in[a].substr(b, len - b);
    }
  }

  REP(i, 1, n) printf("%s\n", in[i].c_str());
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/rope>
#define REP(x, y, z) for (int x = y; x <= z; x++)
#define FORD(x, y, z) for (int x = y; x >= z; x--)
#define MSET(x, y) memset(x, y, sizeof(x))
#define FOR(x, y) for (__typeof(y.begin()) x = y.begin(); x != y.end(); x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 500005
void RI() {}
template <typename... T> void RI(int &head, T &...tail) {
  scanf("%d", &head);
  RI(tail...);
}
using namespace std;
using namespace __gnu_cxx;
typedef long long LL;
int n, q;
rope<char> in[M], t1, t2;
char buf[M * 2];
int main() {
  int a, b, c, d;
  int z;
  RI(n, q);
  REP(i, 1, n) {
    scanf("%s", buf);
    in[i] = buf;
  }

  while (q--) {
    RI(z);
    if (z == 1) {
      RI(a, b, c, d);

      t1 = in[a].substr(b - 1, in[a].length() - b + 1);
      t2 = in[c].substr(d - 1, in[c].length() - d + 1);

      in[a] = in[a].substr(0, b - 1) + t2;
      in[c] = in[c].substr(0, d - 1) + t1;
    } else {
      RI(a, b);
      scanf("%s", buf);

      t1 = buf;

      int len = in[a].length();
      in[a] = in[a].substr(0, b - 1) + t1 + in[a].substr(b, len - b);
    }
  }

  REP(i, 1, n) printf("%s\n", in[i].c_str());
  return 0;
}
Problem p01061 (C++)

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

using namespace std;
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;

struct union_find {
  vl v;
  union_find(ll n) : v(n, -1) {}
  ll find(ll x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (-v[x] < -v[y])
      swap(x, y);
    v[x] += v[y];
    v[y] = x;
  }
  bool same(ll x, ll y) { return find(x) == find(y); }
  ll size(ll x) { return -v[find(x)]; }
};

int main() {
#ifdef _WIN32
  ifstream cin("sample.in");
  ofstream cout("sample.out");
#endif
  cout << fixed << setprecision(8);

  ll n, m;
  cin >> n >> m;
  vl a(n), b(n);
  REP(i, m) cin >> a[i] >> b[i];

  union_find uf(n);
  REP(i, m) uf.unite(a[i] - 1, b[i] - 1);

  ll cntm = 0;
  ll cnts = 0;
  REP(i, n) {
    if (uf.size(i) == 1) {
      cntm++;
    } else {
      if (uf.find(i) == i) {
        cnts++;
      }
    }
  }

  cout << abs(cntm - cnts) << endl;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;
#define ALL(c) (c).begin(), (c).end()
#define REP(i, n) for (ll i = 0; i < (n); ++i)
using ll = long long;
using vl = vector<ll>;

struct union_find {
  vl v;
  union_find(ll n) : v(n, -1) {}
  ll find(ll x) { return (v[x] < 0) ? x : (v[x] = find(v[x])); }
  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (-v[x] < -v[y])
      swap(x, y);
    v[x] += v[y];
    v[y] = x;
  }
  bool same(ll x, ll y) { return find(x) == find(y); }
  ll size(ll x) { return -v[find(x)]; }
};

int main() {
#ifdef _WIN32
  ifstream cin("sample.in");
  ofstream cout("sample.out");
#endif
  cout << fixed << setprecision(8);

  ll n, m;
  cin >> n >> m;
  vl a(m), b(m);
  REP(i, m) cin >> a[i] >> b[i];

  union_find uf(n);
  REP(i, m) uf.unite(a[i] - 1, b[i] - 1);

  ll cntm = 0;
  ll cnts = 0;
  REP(i, n) {
    if (uf.size(i) == 1) {
      cntm++;
    } else {
      if (uf.find(i) == i) {
        cnts++;
      }
    }
  }

  cout << abs(cntm - cnts) << endl;
}
Problem p01061 (C++)

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

struct UnionFind {
  vector<int> data;

  UnionFind(int size) { data.assign(size, -1); }
  int Find(int k) {
    if (data[k] < 0)
      return (k);
    return (data[k] = Find(data[k]));
  }
  void unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y)
      return;
    data[x] += data[y];
    data[y] = x;
  }
  int Size(int k) { return (-data[Find(k)]); }
};
int main() {
  int N, M;
  cin >> N >> M;
  UnionFind tree(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    tree.unite(A, B);
  }
  int mura = 0;
  int used[100] = {};
  for (int i = 0; i < N; i++) {
    int K = tree.Find(i);
    if (used[K]++)
      continue;
    if (tree.Size(K) == 1)
      ++mura;
    else
      --mura;
  }
  cout << abs(mura) << endl;
}

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

struct UnionFind {
  vector<int> data;

  UnionFind(int size) { data.assign(size, -1); }
  int Find(int k) {
    if (data[k] < 0)
      return (k);
    return (data[k] = Find(data[k]));
  }
  void unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y)
      return;
    data[x] += data[y];
    data[y] = x;
  }
  int Size(int k) { return (-data[Find(k)]); }
};
int main() {
  int N, M;
  cin >> N >> M;
  UnionFind tree(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    --A, --B;
    tree.unite(A, B);
  }
  int mura = 0;
  int used[1000] = {};
  for (int i = 0; i < N; i++) {
    int K = tree.Find(i);
    if (used[K]++)
      continue;
    if (tree.Size(K) == 1)
      ++mura;
    else
      --mura;
  }
  cout << abs(mura) << endl;
}
Problem p01062 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
vvi in;
vector<bool> d;
int n;
int coa, cob;
bool f(int a, int b) {
  if (coa == cob && coa == n / 2)
    return true;
  rep(i, in[a].size()) {
    if (d[in[a][i]])
      continue;
    d[in[a][i]] = true;
    coa++;
    rep(j, in[b].size()) {
      if (d[in[b][j]])
        continue;
      d[in[b][j]] = true;
      cob++;
      if (f(in[a][i], in[b][j]))
        return true;
      d[in[b][j]] = false;
      cob--;
    }
    d[in[a][i]] = false;
    coa--;
  }
  return false;
}
int main() {
  int a, b;
  coa = cob = 1;
  cin >> n >> a >> b;
  d = vector<bool>(n, false);
  a--;
  b--;
  d[a] = d[b] = true;
  vvi tmp(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tmp[a].pb(b);
    tmp[b].pb(a);
  }
  if (n % 2) {
    cout << "No" << endl;
    return 0;
  }
  in = tmp;
  cout << (f(a, b) ? "Yes" : "No") << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
vvi in;
vector<bool> d;
int n;
int coa, cob;
bool f(int a, int b) {
  if (coa == cob && coa == n / 2)
    return true;
  rep(i, in[a].size()) {
    if (d[in[a][i]])
      continue;
    d[in[a][i]] = true;
    coa++;
    rep(j, in[b].size()) {
      if (d[in[b][j]])
        continue;
      d[in[b][j]] = true;
      cob++;
      if (f(in[a][i], in[b][j]))
        return true;
      d[in[b][j]] = false;
      cob--;
    }
    d[in[a][i]] = false;
    coa--;
  }
  return false;
}
int main() {
  int a, b;
  coa = cob = 1;
  cin >> n >> a >> b;
  d = vector<bool>(n, false);
  a--;
  b--;
  d[a] = d[b] = true;
  vvi tmp(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tmp[a].pb(b);
    tmp[b].pb(a);
  }
  if (n % 2) {
    cout << "No" << endl;
    return 0;
  }
  in = tmp;
  int q = 0;
  rep(i, n) if (in[i].size() > 3) q++;
  if (q) {
    cout << "No" << endl;
    return 0;
  }
  q = 0;
  rep(i, n) if (in[i].size() == 3) q++;
  if (q > 2) {
    cout << "No" << endl;
    return 0;
  }
  cout << (f(a, b) ? "Yes" : "No") << endl;
}
Problem p01062 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999

vector<int> G[100003];
int N;

bool dfs(int pa, int pb, int number, bool used[100003]) {
  //    cout<<pa<<" "<<pb<<" "<<number<<endl;
  bool res = false;

  if (number == N)
    return true;
  vector<int> next1, next2;

  rep(i, G[pa].size()) {
    int to = G[pa][i];
    if (used[to])
      continue;
    next1.pb(to);
  }

  rep(i, G[pb].size()) {
    int to = G[pb][i];
    if (used[to])
      continue;
    next2.pb(to);
  }

  rep(i, next1.size()) {
    rep(j, next2.size()) {
      if (next1[i] == next2[j])
        continue;
      used[next1[i]] = true;
      used[next2[j]] = true;
      res |= dfs(next1[i], next2[j], number + 2, used);
      used[next1[i]] = false;
      used[next2[j]] = false;
    }
  }
  return res;
}

int main() {
  int u, v;
  cin >> N >> u >> v;
  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    G[a].pb(b);
    G[b].pb(a);
  }

  bool used[100003] = {};
  used[u] = used[v] = true;

  bool res = dfs(u, v, 2, used);

  if (res)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF 999999999

vector<int> G[100003];
int N;

bool dfs(int pa, int pb, int number, bool used[100003]) {
  //    cout<<pa<<" "<<pb<<" "<<number<<endl;
  bool res = false;

  if (number == N)
    return true;
  vector<int> next1, next2;

  rep(i, G[pa].size()) {
    int to = G[pa][i];
    if (used[to])
      continue;
    next1.pb(to);
  }

  rep(i, G[pb].size()) {
    int to = G[pb][i];
    if (used[to])
      continue;
    next2.pb(to);
  }

  rep(i, next1.size()) {
    rep(j, next2.size()) {
      if (next1[i] == next2[j])
        continue;
      used[next1[i]] = true;
      used[next2[j]] = true;
      res |= dfs(next1[i], next2[j], number + 2, used);
      used[next1[i]] = false;
      used[next2[j]] = false;
    }
  }
  return res;
}

int main() {
  int u, v;
  cin >> N >> u >> v;
  rep(i, N - 1) {
    int a, b;
    cin >> a >> b;
    G[a].pb(b);
    G[b].pb(a);
  }

  rep(i, N + 1) {
    if (G[i].size() >= 4) {
      cout << "No" << endl;
      return 0;
    }
  }

  bool used[100003] = {};
  used[u] = used[v] = true;

  bool res = dfs(u, v, 2, used);

  if (res)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p01064 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
  int n;
  cin >> n;
  int a, d;
  cin >> a >> d;
  int m;
  cin >> m;
  vvi in(n, vi(3));
  rep(i, m) rep(j, 3) cin >> in[i][j];
  int q;
  cin >> q;

  for (int i = m - 1; i >= 0; i--)
    if (in[i][0] == 0 && in[i][1] <= q && q <= in[i][2]) {
      q = in[i][2] - q + in[i][1];
    }
  int out = a + d * (q - 1);
  rep(i, m) {
    if (in[i][0] == 1) {
      if (in[i][1] <= q && q <= in[i][2])
        out++;
    } else if (in[i][0] == 2) {
      if (in[i][1] <= q && q <= in[i][2])
        out /= 2;
    } else if (in[i][1] <= q && q <= in[i][2]) {
      q = in[i][2] - q + in[i][1];
    }
  }
  cout << out << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double EPS = 1e-10;
const int inf = 1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
  int n;
  cin >> n;
  int a, d;
  cin >> a >> d;
  int m;
  cin >> m;
  vvi in(m, vi(3));
  rep(i, m) rep(j, 3) cin >> in[i][j];
  int q;
  cin >> q;

  for (int i = m - 1; i >= 0; i--)
    if (in[i][0] == 0 && in[i][1] <= q && q <= in[i][2]) {
      q = in[i][2] - q + in[i][1];
    }
  int out = a + d * (q - 1);
  rep(i, m) {
    if (in[i][0] == 1) {
      if (in[i][1] <= q && q <= in[i][2])
        out++;
    } else if (in[i][0] == 2) {
      if (in[i][1] <= q && q <= in[i][2])
        out /= 2;
    } else if (in[i][1] <= q && q <= in[i][2]) {
      q = in[i][2] - q + in[i][1];
    }
  }
  cout << out << endl;
}