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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9 + 7;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> s(w + 1, 1e9);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x - y + 1 > 0)
      s[x - y + 1] = min(s[x - y + 1], y);
  }
  int res = h;
  for (int i = 2; i <= h; i++) {
    if (s[i] < s[i - 1]) {
      res = min(res, i + s[i] - 2);
    }
  }
  dump(res);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;
ll mod = 1e9 + 7;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> s(h + 1, 1e9);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x - y + 1 > 0)
      s[x - y + 1] = min(s[x - y + 1], y);
  }
  int res = h;
  for (int i = 2; i <= h; i++) {
    if (s[i] < s[i - 1]) {
      res = min(res, i + s[i] - 2);
    }
  }
  dump(res);
  return 0;
}
Problem p03203 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
ll gi() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    f ^= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
int mn[100010];
int main() {
#ifdef XZZSB
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  int n = gi(), m = gi(), k = gi(), x, y;
  memset(mn, 63, sizeof mn);
  while (k--) {
    x = gi(), y = gi();
    mn[x] = std::min(mn[x], y);
  }
  int R = 1;
  for (int i = 2; i <= n; ++i) {
    if (mn[i] <= R) {
      printf("%d\n", i - 1);
      return 0;
    }
    if (mn[i] != R + 1)
      ++R;
  }
  printf("%d\n", n);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
ll gi() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch))
    f ^= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
int mn[200010];
int main() {
#ifdef XZZSB
  freopen("in.in", "r", stdin);
  freopen("out.out", "w", stdout);
#endif
  int n = gi(), m = gi(), k = gi(), x, y;
  memset(mn, 63, sizeof mn);
  while (k--) {
    x = gi(), y = gi();
    mn[x] = std::min(mn[x], y);
  }
  int R = 1;
  for (int i = 2; i <= n; ++i) {
    if (mn[i] <= R) {
      printf("%d\n", i - 1);
      return 0;
    }
    if (mn[i] != R + 1)
      ++R;
  }
  printf("%d\n", n);
  return 0;
}
Problem p03203 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int n, h, w, ans, minp[100005];
int main() {
  scanf("%d%d%d", &h, &w, &n);
  ans = h;
  for (int i = 1; i <= h; i++)
    minp[i] = w + 1;
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    minp[x] = min(minp[x], y);
  }
  int now = 0;
  for (int i = 1; i <= h; i++) {
    if (minp[i] <= now) {
      printf("%d\n", i - 1);
      return 0;
    }
    if (minp[i] > now + 1)
      now++;
  }
  printf("%d\n", h);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int n, h, w, ans, minp[200005];
int main() {
  scanf("%d%d%d", &h, &w, &n);
  ans = h;
  for (int i = 1; i <= h; i++)
    minp[i] = w + 1;
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    minp[x] = min(minp[x], y);
  }
  int now = 0;
  for (int i = 1; i <= h; i++) {
    if (minp[i] <= now) {
      printf("%d\n", i - 1);
      return 0;
    }
    if (minp[i] > now + 1)
      now++;
  }
  printf("%d\n", h);
  return 0;
}
Problem p03203 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  vector<int> a[w + 1];
  rep(i, w + 1) a[i].push_back(inf);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    a[x].push_back(y);
  }
  a[w].push_back(0);
  rep(i, w + 1) sort(a[i].begin(), a[i].end());
  int H = 0;
  rep(i, w) {
    if (H >= a[i + 1][0]) {
      cout << i + 1 << endl;
      return 0;
    }
    int z = *lower_bound(a[i + 1].begin(), a[i + 1].end(), H + 1);
    if (z != H + 1)
      ++H;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, int> pli;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
  int h, w;
  cin >> w >> h;
  int n;
  cin >> n;
  vector<int> a[w + 1];
  rep(i, w + 1) a[i].push_back(inf);
  rep(i, n) {
    int x, y;
    cin >> x >> y;
    --x;
    --y;
    a[x].push_back(y);
  }
  a[w].push_back(0);
  rep(i, w + 1) sort(a[i].begin(), a[i].end());
  int H = 0;
  rep(i, w) {
    if (H >= a[i + 1][0]) {
      cout << i + 1 << endl;
      return 0;
    }
    int z = *lower_bound(a[i + 1].begin(), a[i + 1].end(), H + 1);
    if (z != H + 1)
      ++H;
  }
  return 0;
}
Problem p03203 (C++)

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  if (n == 0) {
    cout << h << endl;
    return 0;
  }
  vector<pair<int, int>> a;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x < y)
      continue;
    a.push_back(make_pair(x, y));
  }
  if (a.size() == 0) {
    cout << h << endl;
    return 0;
  }
  sort(a.begin(), a.end());
  int ans = 0;
  int pos = 0;
  int j = 1;
  for (int i = 1; i < h + 10; i++) {
    if (i == h)
      break;
    bool ok = false;
    bool right = true;
    while (a.at(pos).first == i + 1) {
      if (a.at(pos).second <= j && ok == false)
        ok = true;
      if (a.at(pos).second == j + 1)
        right = false;
      pos++;
      if (pos == a.size())
        break;
    }
    if (ok)
      break;
    if (right)
      j++;
    ans++;
  }
  cout << ans + 1 << endl;
}


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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  if (n == 0) {
    cout << h << endl;
    return 0;
  }
  vector<pair<int, int>> a;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    if (x < y)
      continue;
    a.push_back(make_pair(x, y));
  }
  if (a.size() == 0) {
    cout << h << endl;
    return 0;
  }
  sort(a.begin(), a.end());
  int ans = 0;
  int pos = 0;
  int j = 1;
  for (int i = 1; i < h + 10; i++) {
    if (i == h)
      break;
    bool ok = false;
    bool right = true;
    while (pos != a.size() && a.at(pos).first == i + 1) {
      if (a.at(pos).second <= j && ok == false)
        ok = true;
      if (a.at(pos).second == j + 1)
        right = false;
      pos++;
      if (pos == a.size())
        break;
    }
    if (ok)
      break;
    if (right)
      j++;
    ans++;
  }
  cout << ans + 1 << endl;
}
Problem p03203 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template <typename T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
double fin() {
  double x;
  scanf("%lf", &x);
  return x;
}
Int lin() {
  Int x;
  scanf("%lld", &x);
  return x;
}

int main() {
  int H = in();
  int W = in();
  int N = in();
  set<pair<int, int>> X;
  for (int i = 0; i < N; ++i) {
    int r = in() - 1;
    int c = in() - 1;
    X.insert(make_pair(r, c));
  }

  vector<int> top(W, INF);
  int ar = 0, ac = 0;
  while (true) {
    chmin(top[ac], ar);
    ++ar;
    if (ar >= H) {
      break;
    }
    if (X.count(make_pair(ar, ac + 1)) == 0) {
      ++ac;
    }
  }

  int res = H;
  for (const auto &p : X) {
    if (top[p.second] < p.first) {
      chmin(res, p.first);
    }
  }
  printf("%d\n", res);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template <typename T> void pv(T a, T b) {
  for (T i = a; i != b; ++i)
    cout << *i << " ";
  cout << endl;
}
template <typename T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}
template <typename T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}
int in() {
  int x;
  scanf("%d", &x);
  return x;
}
double fin() {
  double x;
  scanf("%lf", &x);
  return x;
}
Int lin() {
  Int x;
  scanf("%lld", &x);
  return x;
}

int main() {
  int H = in();
  int W = in();
  int N = in();
  set<pair<int, int>> X;
  for (int i = 0; i < N; ++i) {
    int r = in() - 1;
    int c = in() - 1;
    X.insert(make_pair(r, c));
  }

  vector<int> top(W, INF);
  int ar = 0, ac = 0;
  while (true) {
    chmin(top[ac], ar);
    ++ar;
    if (ar >= H) {
      break;
    }
    if (X.count(make_pair(ar, ac + 1)) == 0 && ac + 1 < W) {
      ++ac;
    }
  }

  int res = H;
  for (const auto &p : X) {
    if (top[p.second] < p.first) {
      chmin(res, p.first);
    }
  }
  printf("%d\n", res);
  return 0;
}
Problem p03203 (C++)

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  int h, w, n;
  cin >> h >> w >> n;
  V<deque<int>> g(h);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[y].push_back(x);
  }
  int ans = w, er = -1;
  for (int y = 0; y < h; y++) {
    auto v = g[y];
    sort(v.begin(), v.end());
    while (v.size() && v.front() <= er)
      v.pop_front();
    while (v.size() && v.front() == er + 1) {
      er++;
      v.pop_front();
    }
    if (v.size())
      ans = min(ans, v.front());
    er++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  int h, w, n;
  cin >> w >> h >> n; // ha?
  V<deque<int>> g(h);
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    g[y].push_back(x);
  }
  int ans = w, er = -1;
  for (int y = 0; y < h; y++) {
    auto v = g[y];
    sort(v.begin(), v.end());
    while (v.size() && v.front() <= er)
      v.pop_front();
    while (v.size() && v.front() == er + 1) {
      er++;
      v.pop_front();
    }
    if (v.size())
      ans = min(ans, v.front());
    er++;
  }
  cout << ans << endl;
  return 0;
}
Problem p03203 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, a, b) for (decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
3 3 1
3 2
)");
#define cin input
#endif

int main() {
  int h, w, n;
  cin >> h >> w >> n;

  vector<set<int>> s(w);

  REP(i, n) {
    int x, y;
    cin >> x >> y;
    s[x - 1].insert(y - 1);
  }

  int x, y = 0;

  for (x = 0; x < h; ++x) {
    auto it = s[x].upper_bound(y);
    if (it != s[x].begin())
      break;
    if (x && (it == s[x].end() || *it != y + 1))
      ++y;
  }

  cout << x << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, a, b) for (decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
3 3 1
3 2
)");
#define cin input
#endif

int main() {
  int h, w, n;
  cin >> h >> w >> n;

  vector<set<int>> s(h);

  REP(i, n) {
    int x, y;
    cin >> x >> y;
    s[x - 1].insert(y - 1);
  }

  int x, y = 0;

  for (x = 0; x < h; ++x) {
    auto it = s[x].upper_bound(y);
    if (it != s[x].begin())
      break;
    if (x && (it == s[x].end() || *it != y + 1))
      ++y;
  }

  cout << x << endl;

  return 0;
}
Problem p03203 (C++)

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

using namespace std;

typedef pair<int, int> Pii;

set<int> mp[200000];

int main() {
  int h, w, n, x, y;
  cin >> h >> w >> n;

  for (int i = 0; i < n; ++i) {
    cin >> x >> y;
    mp[y].insert(x);
  }

  for (int i = 1; i <= w; ++i)
    mp[i].insert(h + 1);

  vector<Pii> v;
  int j_lower_lim = 1;
  for (int i = 1; i <= w; ++i) {
    while (mp[i].find(j_lower_lim) != mp[i].end())
      ++j_lower_lim;
    set<int>::iterator j_itr = mp[i].upper_bound(j_lower_lim);
    if (j_itr != mp[i].end()) {
      v.emplace_back(*j_itr, i);
    }
    ++j_lower_lim;
  }
  sort(v.begin(), v.end());

  cout << v[0].first - 1 << "\n";
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> Pii;

set<int> mp[200001];

int main() {
  int h, w, n, x, y;
  cin >> h >> w >> n;

  for (int i = 0; i < n; ++i) {
    cin >> x >> y;
    mp[y].insert(x);
  }

  for (int i = 1; i <= w; ++i)
    mp[i].insert(h + 1);

  vector<Pii> v;
  int j_lower_lim = 1;
  for (int i = 1; i <= w; ++i) {
    while (mp[i].find(j_lower_lim) != mp[i].end())
      ++j_lower_lim;
    set<int>::iterator j_itr = mp[i].upper_bound(j_lower_lim);
    if (j_itr != mp[i].end()) {
      v.emplace_back(*j_itr, i);
    }
    ++j_lower_lim;
  }
  sort(v.begin(), v.end());

  cout << v[0].first - 1 << "\n";
}
Problem p03203 (C++)

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

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  map<P, int> mp;
  vector<vector<int>> g(H);
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y, X--, Y--;
    g[X].push_back(Y);
    mp[{X, Y}] = 1;
  }
  for (int x = 0; x <= H; x++) {
    mp[{x, W}] = 1;
  }
  for (int y = 0; y <= W; y++) {
    mp[{H, y}] = 1;
  }

  int ans = 1;
  int y = 0;
  for (int x = 1; x <= H; x++) {
    int cnt = 0;
    for (auto v : g[x]) {
      if (v < y)
        cnt++;
    }
    if (cnt > 0 || mp[{x, y}])
      break;
    if (!mp[{x, y + 1}])
      y++;
    ans++;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  map<P, int> mp;
  vector<vector<int>> g(H + 1);
  for (int i = 0; i < N; i++) {
    int X, Y;
    cin >> X >> Y, X--, Y--;
    g[X].push_back(Y);
    mp[{X, Y}] = 1;
  }
  for (int x = 0; x <= H; x++) {
    mp[{x, W}] = 1;
  }
  for (int y = 0; y <= W; y++) {
    mp[{H, y}] = 1;
  }

  int ans = 1;
  int y = 0;
  for (int x = 1; x <= H; x++) {
    int cnt = 0;
    for (auto v : g[x]) {
      if (v < y)
        cnt++;
    }
    if (cnt > 0 || mp[{x, y}])
      break;
    if (!mp[{x, y + 1}])
      y++;
    ans++;
  }

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

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int, int> pii;
typedef pair<i64, int> pli;
typedef pair<int, i64> pil;
typedef pair<i64, i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T> T id(T b) { return b; };
template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); }
template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); }

const int MAX_N = 200000;
int h, w, n;
pii xy[MAX_N];
pii yx[MAX_N];

int main() {
  cin >> h >> w >> n;
  for (int i = 0; i < n; ++i) {
    cin >> xy[i].first >> xy[i].second;
    yx[i].first = xy[i].second;
    yx[i].second = xy[i].first;
  }

  sort(xy, xy + n);
  sort(yx, yx + n);
  int col = 1, row = 1, m = h;
  for (int i = 0; i < h; i++) {
    auto it = lower_bound(yx, yx + n, mp(col, row + 1));
    if (it != yx + n && it->first == col)
      m = min(m, it->second - 1);
    if (find(xy, xy + n, mp(row + 1, col + 1)) == xy + n && col < w) {
      col++;
    }
    if (row < h)
      row++;
  }

  cout << m << endl;

  return 0;
}


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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int, int> pii;
typedef pair<i64, int> pli;
typedef pair<int, i64> pil;
typedef pair<i64, i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T> T id(T b) { return b; };
template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); }
template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); }

const int MAX_N = 200000;
int h, w, n;
pii xy[MAX_N];
pii yx[MAX_N];

int main() {
  cin >> h >> w >> n;
  for (int i = 0; i < n; ++i) {
    cin >> xy[i].first >> xy[i].second;
    yx[i].first = xy[i].second;
    yx[i].second = xy[i].first;
  }

  sort(xy, xy + n);
  sort(yx, yx + n);
  int col = 1, row = 1, m = h;
  for (int i = 0; i < h; i++) {
    auto it = lower_bound(yx, yx + n, mp(col, row + 1));
    if (it != yx + n && it->first == col)
      m = min(m, it->second - 1);
    if (col < w && !binary_search(xy, xy + n, mp(row + 1, col + 1))) {
      col++;
    }
    if (row < h)
      row++;
  }

  cout << m << endl;

  return 0;
}
Problem p03203 (C++)

Buggy submission (status: Runtime Error):
//* AuThOr GaRyMr *//
#include <bits/stdc++.h>
#define rb(a, b, c) for (int a = b; a <= c; ++a)
#define rl(a, b, c) for (int a = b; a >= c; --a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a, b) make_pair(a, b)
#define FIR first
#define SEC second
#define FREO freopen("check.out", "w", stdout)
#define rep(a, b) for (int a = 0; a < b; ++a)
#define KEEP while (1)
#define SRAND                                                                  \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng() % a
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> mp;
typedef pair<mp, mp> superpair;
int up_bound, low_bound;
vector<int> each[200000];
int main() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  rep(i, n) {
    int x, y;
    scanf("%d %d", &x, &y);
    each[y].PB(x);
  }
  int res;
  low_bound = h;
  up_bound = 1;
  for (auto it : each[1]) {
    low_bound = min(low_bound, it - 1);
  }
  res = low_bound;
  rb(i, 2, w) {
    up_bound++;
    sort(each[i].begin(), each[i].end());
    for (auto it : each[i]) {
      if (it > low_bound)
        break;
      if (it < up_bound)
        continue;
      if (it == up_bound)
        up_bound++;
      else
        low_bound = it - 1;
    }
    res = low_bound;
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
//* AuThOr GaRyMr *//
#include <bits/stdc++.h>
#define rb(a, b, c) for (int a = b; a <= c; ++a)
#define rl(a, b, c) for (int a = b; a >= c; --a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a, b) make_pair(a, b)
#define FIR first
#define SEC second
#define FREO freopen("check.out", "w", stdout)
#define rep(a, b) for (int a = 0; a < b; ++a)
#define KEEP while (1)
#define SRAND                                                                  \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng() % a
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> mp;
typedef pair<mp, mp> superpair;
int up_bound, low_bound;
vector<int> each[200000 + 10];
int main() {
  int h, w;
  cin >> h >> w;
  int n;
  cin >> n;
  rep(i, n) {
    int x, y;
    scanf("%d %d", &x, &y);
    each[y].PB(x);
  }
  int res;
  low_bound = h;
  up_bound = 1;
  for (auto it : each[1]) {
    low_bound = min(low_bound, it - 1);
  }
  res = low_bound;
  rb(i, 2, w) {
    up_bound++;
    sort(each[i].begin(), each[i].end());
    for (auto it : each[i]) {
      if (it > low_bound)
        break;
      if (it < up_bound)
        continue;
      if (it == up_bound)
        up_bound++;
      else
        low_bound = it - 1;
    }
    res = low_bound;
  }
  cout << res << endl;
  return 0;
}
Problem p03203 (C++)

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

constexpr int inf = 1e9;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<vector<int>> xs(w, vector<int>(1, h + 1));
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    xs[y - 1].push_back(x);
  }
  for (auto &xx : xs)
    sort(xx.begin(), xx.end());

  auto dist = [&](int x, int y) {
    return *upper_bound(xs[y].begin(), xs[y].end(), x) - x;
  };

  auto find_hole = [&](int x, int y) {
    if (y + 1 == w)
      return -1;
    int res = -1;
    while (x < h) {
      const int nx = *lower_bound(xs[y + 1].begin(), xs[y + 1].end(), x + 1);
      if (nx > x + 1) {
        res = x + 1;
        break;
      }
      x = nx;
    }
    return res;
  };

  int ans = inf, x = 1;
  for (int y = 0; y < h; ++y) {
    const int d = dist(x, y);
    ans = min(ans, x + d - 1);
    if (y + 1 != w) {
      const int hole = find_hole(x, y);
      if (hole == -1) {
        break;
      }
      x = hole;
    }
  }

  cout << ans << endl;
}


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

constexpr int inf = 1e9;

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<vector<int>> xs(w, vector<int>(1, h + 1));
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    xs[y - 1].push_back(x);
  }
  for (auto &xx : xs)
    sort(xx.begin(), xx.end());

  auto dist = [&](int x, int y) {
    return *upper_bound(xs[y].begin(), xs[y].end(), x) - x;
  };

  auto find_hole = [&](int x, int y) {
    if (y + 1 == w)
      return -1;
    int res = -1;
    while (x < h) {
      const int nx = *lower_bound(xs[y + 1].begin(), xs[y + 1].end(), x + 1);
      if (nx > x + 1) {
        res = x + 1;
        break;
      }
      x = nx;
    }
    return res;
  };

  int ans = inf, x = 1;
  for (int y = 0; y < w; ++y) {
    const int d = dist(x, y);
    ans = min(ans, x + d - 1);
    if (y + 1 != w) {
      const int hole = find_hole(x, y);
      if (hole == -1) {
        break;
      }
      x = hole;
    }
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
typedef long long LL;
LL H, W, N;
typedef pair<int, int> P;
vector<int> G[200011];
int main() {
  cin >> H >> W >> N;
  REP(i, N) {
    int X, Y;
    cin >> X >> Y;
    G[Y].push_back(X);
  }
  REP(i, 200011) { sort(G[i].begin(), G[i].end()); }
  int ans = H;
  LL now = 1;
  REP(i, 200011) {
    // if(i>W+5)break;
    // cout<<now<<endl;
    if (i == 0)
      continue;
    if (G[i].size() == 0) {
      now++;
      REP(j, G[i + 1].size()) {
        if (now == G[i + 1][j]) {
          now++;
        }
      }
      continue;
    }
    if (i == 1) {
      // 1より大きく始めにぶつかる場所
      ans = min(ans, G[1][0] - 1);
      now++;
      REP(j, G[i + 1].size()) {
        if (now == G[i + 1][j]) {
          now++;
        }
      }
    } else {
      LL t = 300000;
      REP(j, G[i].size()) {
        if (now < G[i][j]) {
          ans = min(ans, G[i][j] - 1);
        }
      }
      now++;
      REP(j, G[i + 1].size()) {
        if (now == G[i + 1][j]) {
          now++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
typedef long long LL;
LL H, W, N;
typedef pair<int, int> P;
vector<int> G[200011];
int main() {
  cin >> H >> W >> N;
  REP(i, N) {
    int X, Y;
    cin >> X >> Y;
    G[Y].push_back(X);
  }
  REP(i, 200011) { sort(G[i].begin(), G[i].end()); }
  int ans = H;
  LL now = 1;
  REP(i, 200009) {
    // if(i>W+5)break;
    // cout<<now<<endl;
    if (i == 0)
      continue;
    if (G[i].size() == 0) {
      now++;
      REP(j, G[i + 1].size()) {
        if (now == G[i + 1][j]) {
          now++;
        }
      }
      continue;
    }
    if (i == 1) {
      // 1より大きく始めにぶつかる場所
      ans = min(ans, G[1][0] - 1);
      now++;
      REP(j, G[i + 1].size()) {
        if (now == G[i + 1][j]) {
          now++;
        }
      }
    } else {
      LL t = 300000;
      REP(j, G[i].size()) {
        if (now < G[i][j]) {
          ans = min(ans, G[i][j] - 1);
        }
      }
      now++;
      REP(j, G[i + 1].size()) {
        if (now == G[i + 1][j]) {
          now++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03203 (C++)

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);

const int N = (int)1e5 + 9;
vector<int> P[N];
map<pii, bool> cor;

int main() {
  fastIO;
  int n, m, q;
  cin >> n >> m >> q;
  int x, y;
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    cor[mp(y, x)] = true;
    P[y].push_back(x);
  }
  for (int i = 1; i <= m; i++)
    P[i].push_back(n + 1);
  for (int i = 1; i <= m; i++)
    sort(P[i].begin(), P[i].end());
  int low = P[1][0];
  int pos = 2;
  int res = P[1][0] - 1;
  int idx;
  for (int i = 2; i <= m; i++) {
    while (pos < low && cor[mp(i, pos)]) {
      pos++;
    }
    if (pos >= low)
      break;
    idx = 0;
    while (P[i][idx] < pos)
      ++idx;
    res = min(res, P[i][idx] - 1);
    pos++;
  }
  cout << res;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0);

const int N = (int)2e5 + 9;
vector<int> P[N];
map<pii, bool> cor;

int main() {
  fastIO;
  int n, m, q;
  cin >> n >> m >> q;
  int x, y;
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    cor[mp(y, x)] = true;
    P[y].push_back(x);
  }
  for (int i = 1; i <= m; i++)
    P[i].push_back(n + 1);
  for (int i = 1; i <= m; i++)
    sort(P[i].begin(), P[i].end());
  int low = P[1][0];
  int pos = 2;
  int res = P[1][0] - 1;
  int idx;
  for (int i = 2; i <= m; i++) {
    while (pos < low && cor[mp(i, pos)]) {
      pos++;
    }
    if (pos >= low)
      break;
    idx = 0;
    while (P[i][idx] < pos)
      ++idx;
    res = min(res, P[i][idx] - 1);
    pos++;
  }
  cout << res;
  return 0;
}
Problem p03204 (C++)

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

using namespace std;

int N;
vector<int> g[200000];
int ans[100000];
map<int, int> mp[200000];

int dfs2(int idx, int par, int v) {
  if (mp[idx].count(v))
    return mp[idx][v];
  int ret = 1;
  for (auto &to : g[idx]) {
    if (to == par)
      continue;
    if (to < v)
      ret += dfs2(to, idx, v);
  }
  return mp[idx][v] = ret;
}

void dfs(int idx, int par, int c, int delta) {
  int add = dfs2(idx, par, max(c, par));
  if (c > idx)
    add -= dfs2(idx, par, c);
  delta += add;
  ans[idx] = delta;
  for (auto &to : g[idx]) {
    if (to == par)
      continue;
    dfs(to, idx, max(c, par), delta);
  }
}

int main() {
  cin >> N;
  for (int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (auto to : g[0])
    dfs(to, 0, 0, 0);
  for (int i = 1; i < N; i++)
    cout << ans[i] << " ";
  cout << endl;
}

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

using namespace std;

int N;
vector<int> g[200000];
int ans[200000];
map<int, int> mp[200000];

int dfs2(int idx, int par, int v) {
  if (mp[idx].count(v))
    return mp[idx][v];
  int ret = 1;
  for (auto &to : g[idx]) {
    if (to == par)
      continue;
    if (to < v)
      ret += dfs2(to, idx, v);
  }
  return mp[idx][v] = ret;
}

void dfs(int idx, int par, int c, int delta) {
  int add = dfs2(idx, par, max(c, par));
  if (c > idx)
    add -= dfs2(idx, par, c);
  delta += add;
  ans[idx] = delta;
  for (auto &to : g[idx]) {
    if (to == par)
      continue;
    dfs(to, idx, max(c, par), delta);
  }
}

int main() {
  cin >> N;
  for (int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (auto to : g[0])
    dfs(to, 0, 0, 0);
  for (int i = 1; i < N; i++)
    cout << ans[i] << " ";
  cout << endl;
}
Problem p03204 (C++)

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

int n, head[100001], nxt[200001], b[200001], k, ans2[100001];
void push(int s, int t) {
  nxt[++k] = head[s];
  head[s] = k;
  b[k] = t;
}
void dfs(int x, int f, int mx, int skdmx, int down, bool update) {
  if (x > mx)
    skdmx = mx, mx = x, update = 1;
  else if (x > skdmx)
    skdmx = x, update = 0;
  ++ans2[x], --ans2[update ? mx : down];
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f)
      dfs(b[i], x, mx, skdmx, (x == mx) ? b[i] : down, update);
}
void dfs2(int x, int f) {
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f)
      dfs2(b[i], x), ans2[x] += ans2[b[i]];
}
void getans(int x, int f, int sum) {
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f)
      sum += ans2[b[i]];
  ans2[x] = ++sum;
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f)
      getans(b[i], x, sum - ans2[b[i]]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    push(u, v);
    push(v, u);
  }
  dfs(1, 0, 0, 0, 0, 0);
  dfs2(1, 0);
  getans(1, 0, -1);
  for (int i = 2; i <= n; i++)
    printf("%d ", ans2[i]);
}

Fixed submission:
#include <cstdio>

int n, head[200001], nxt[400001], b[400001], k, ans2[200001];
void push(int s, int t) {
  nxt[++k] = head[s];
  head[s] = k;
  b[k] = t;
}
void dfs(int x, int f, int mx, int skdmx, int down, bool update) {
  if (x > mx)
    skdmx = mx, mx = x, update = 1;
  else if (x > skdmx)
    skdmx = x, update = 0;
  ++ans2[x], --ans2[update ? mx : down];
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f)
      dfs(b[i], x, mx, skdmx, (x == mx) ? b[i] : down, update);
}
void dfs2(int x, int f) {
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f)
      dfs2(b[i], x), ans2[x] += ans2[b[i]];
}
void getans(int x, int f, int sum) {
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f)
      sum += ans2[b[i]];
  ans2[x] = ++sum;
  for (int i = head[x]; i; i = nxt[i])
    if (b[i] != f)
      getans(b[i], x, sum - ans2[b[i]]);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d%d", &u, &v);
    push(u, v);
    push(v, u);
  }
  dfs(1, 0, 0, 0, 0, 0);
  dfs2(1, 0);
  getans(1, 0, -1);
  for (int i = 2; i <= n; i++)
    printf("%d ", ans2[i]);
}
Problem p03204 (C++)

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

const int N = 2e5 + 5;
int n, c[N];
vector<int> G[N];
inline void addedge(int u = 0, int v = 0) {
  scanf("%d%d", &u, &v), G[u].push_back(v), G[v].push_back(u);
}

int calc(int u, int fa, int lim) {
  int res = 1;
  for (auto v : G[u])
    if (v < lim)
      res += calc(v, u, lim);
  return res;
}
void solve(int u, int fa, int t1, int t2) {
  if (u > t2)
    c[u] = c[fa] + calc(u, fa, t1);
  else if (t1 > t2)
    c[u] = c[fa] + calc(u, fa, t1) - calc(u, fa, t2);
  else
    c[u] = c[fa];
  for (auto v : G[u])
    if (v != fa)
      solve(v, u, max(t1, u), max(t2, fa));
}

int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i)
    addedge();
  solve(1, 0, 1, 1);
  for (int i = 2; i <= n; ++i)
    printf("%d ", c[i]);
  return puts(""), 0;
}

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

const int N = 2e5 + 5;
int n, c[N];
vector<int> G[N];
inline void addedge(int u = 0, int v = 0) {
  scanf("%d%d", &u, &v), G[u].push_back(v), G[v].push_back(u);
}

int calc(int u, int fa, int lim) {
  int res = 1;
  for (auto v : G[u])
    if (v < lim && v != fa)
      res += calc(v, u, lim);
  return res;
}
void solve(int u, int fa, int t1, int t2) {
  if (u > t2)
    c[u] = c[fa] + calc(u, fa, t1);
  else if (t1 > t2)
    c[u] = c[fa] + calc(u, fa, t1) - calc(u, fa, t2);
  else
    c[u] = c[fa];
  for (auto v : G[u])
    if (v != fa)
      solve(v, u, max(t1, u), max(t2, fa));
}

int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i)
    addedge();
  solve(1, 0, 1, 1);
  for (int i = 2; i <= n; ++i)
    printf("%d ", c[i]);
  return puts(""), 0;
}
Problem p03204 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
using namespace std;
const int N = 1010;
vector<int> G[N];
int n, f[N], u, v, fa[N][20], c[N], d[N];
int get(int v, int t) {
  int u = v;
  per(i, 18, 0) if (c[fa[fa[u][i]][0]] > v && d[fa[u][i]] >= t) u = fa[u][i];
  return u;
}
void dfs(int u, int t) {
  ++f[t];
  for (int &v : G[u])
    if (v ^ fa[u][0]) {
      d[v] = d[u] + 1, c[v] = max(c[u], v), fa[v][0] = u;
      rep(i, 1, 18) fa[v][i] = fa[fa[v][i - 1]][i - 1];
      dfs(v, get(v, d[t]));
    }
}
void DFS(int u) {
  for (int &v : G[u])
    if (v ^ fa[u][0])
      f[v] += f[u], DFS(v);
}
int main() {
  scanf("%d", &n);
  rep(i, 1, n - 1) scanf("%d%d", &u, &v), G[u].pb(v), G[v].pb(u);
  d[1] = 1;
  c[1] = 1;
  dfs(1, 1);
  DFS(1);
  rep(i, 2, n) printf("%d ", f[i] - 1);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
using namespace std;
const int N = 2e5 + 10;
vector<int> G[N];
int n, f[N], u, v, fa[N][20], c[N], d[N];
int get(int v, int t) {
  int u = v;
  per(i, 18, 0) if (c[fa[fa[u][i]][0]] > v && d[fa[u][i]] >= t) u = fa[u][i];
  return u;
}
void dfs(int u, int t) {
  ++f[t];
  for (int &v : G[u])
    if (v ^ fa[u][0]) {
      d[v] = d[u] + 1, c[v] = max(c[u], v), fa[v][0] = u;
      rep(i, 1, 18) fa[v][i] = fa[fa[v][i - 1]][i - 1];
      dfs(v, get(v, d[t]));
    }
}
void DFS(int u) {
  for (int &v : G[u])
    if (v ^ fa[u][0])
      f[v] += f[u], DFS(v);
}
int main() {
  scanf("%d", &n);
  rep(i, 1, n - 1) scanf("%d%d", &u, &v), G[u].pb(v), G[v].pb(u);
  d[1] = 1;
  c[1] = 1;
  dfs(1, 1);
  DFS(1);
  rep(i, 2, n) printf("%d ", f[i] - 1);
  return 0;
}
Problem p03204 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 100010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int mx[maxn], c[maxn], n;
vector<int> nxt[maxn];
map<int, int> F[maxn];
template <class T> void read(T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int f(int x, int y, int fa) {
  if (F[x].count(y))
    return F[x][y];
  int ret = 0;
  for (auto &v : nxt[x]) {
    if (v != fa && v <= y)
      ret += 1 + f(v, y, x);
  }
  return F[x][y] = ret;
}
void dfs(int x, int fa) {
  mx[x] = max(mx[fa], fa);
  if (x > mx[fa])
    c[x] = c[fa] + f(x, mx[x], fa) + 1;
  else
    c[x] = c[fa] + f(x, mx[x], fa) - f(x, mx[fa], fa);
  for (auto &v : nxt[x]) {
    if (v != fa)
      dfs(v, x);
  }
}
int main() {
  read(n);
  for (int i = 1, u, v; i <= n - 1; i++) {
    read(u), read(v), nxt[u].pb(v), nxt[v].pb(u);
  }
  for (auto &v : nxt[1]) {
    dfs(v, 1);
  }
  for (int i = 2; i <= n; i++) {
    printf("%d%c", c[i], i == n ? '\n' : ' ');
  }
  return 0;
}

Fixed submission:
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#define maxn 200010
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define IL inline
#define ss system
using namespace std;

int mx[maxn], c[maxn], n;
vector<int> nxt[maxn];
map<int, int> F[maxn];
template <class T> void read(T &x) {
  char ch = x = 0;
  bool fl = false;
  while (!isdigit(ch))
    fl |= ch == '-', ch = getchar();
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  x = fl ? -x : x;
}
int f(int x, int y, int fa) {
  if (F[x].count(y))
    return F[x][y];
  int ret = 0;
  for (auto &v : nxt[x]) {
    if (v != fa && v <= y)
      ret += 1 + f(v, y, x);
  }
  return F[x][y] = ret;
}
void dfs(int x, int fa) {
  mx[x] = max(mx[fa], fa);
  if (x > mx[fa])
    c[x] = c[fa] + f(x, mx[x], fa) + 1;
  else
    c[x] = c[fa] + f(x, mx[x], fa) - f(x, mx[fa], fa);
  for (auto &v : nxt[x]) {
    if (v != fa)
      dfs(v, x);
  }
}
int main() {
  read(n);
  for (int i = 1, u, v; i <= n - 1; i++) {
    read(u), read(v), nxt[u].pb(v), nxt[v].pb(u);
  }
  for (auto &v : nxt[1]) {
    dfs(v, 1);
  }
  for (int i = 2; i <= n; i++) {
    printf("%d%c", c[i], i == n ? '\n' : ' ');
  }
  return 0;
}
Problem p03204 (C++)

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

using namespace std;
const int N = 1e5 + 10;

struct Edge {
  int to, nex;
} e[N << 1];
int head[N], ecnt;

void adde(int fr, int to) {
  e[++ecnt] = (Edge){to, head[fr]};
  head[fr] = ecnt;
}

void addedge(int fr, int to) {
  adde(to, fr);
  adde(fr, to);
}

int n, par[N], c[N], mx[N];
map<int, int> exi[N];

void dfs(int x, int fa) {
  par[x] = fa;
  for (int j = head[x]; j; j = e[j].nex)
    if (e[j].to != fa) {
      mx[e[j].to] = max(mx[x], x);
      dfs(e[j].to, x);
    }
}
int Q(int x, int v) {
  if (exi[x].count(v))
    return exi[x][v];
  int res = 0;
  for (int j = head[x]; j; j = e[j].nex) {
    if (e[j].to <= v && e[j].to != par[x]) {
      res += Q(e[j].to, v) + 1;
    }
  }
  return exi[x][v] = res;
}

void dfs2(int x) {
  for (int j = head[x]; j; j = e[j].nex) {
    if (e[j].to != par[x]) {

      if (e[j].to > mx[x]) {
        c[e[j].to] = c[x] + Q(e[j].to, mx[e[j].to]) + 1;
      } else {
        c[e[j].to] = c[x] + Q(e[j].to, mx[e[j].to]) - Q(e[j].to, mx[x]);
      }
      dfs2(e[j].to);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }
  mx[1] = -1;
  dfs(1, 0);
  dfs2(1);

  for (int i = 2; i <= n; i++)
    printf("%d ", c[i]);
  return 0;
}

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

using namespace std;
const int N = 2e5 + 10;

struct Edge {
  int to, nex;
} e[N << 1];
int head[N], ecnt;

void adde(int fr, int to) {
  e[++ecnt] = (Edge){to, head[fr]};
  head[fr] = ecnt;
}

void addedge(int fr, int to) {
  adde(to, fr);
  adde(fr, to);
}

int n, par[N], c[N], mx[N];
map<int, int> exi[N];

void dfs(int x, int fa) {
  par[x] = fa;
  for (int j = head[x]; j; j = e[j].nex)
    if (e[j].to != fa) {
      mx[e[j].to] = max(mx[x], x);
      dfs(e[j].to, x);
    }
}
int Q(int x, int v) {
  if (exi[x].count(v))
    return exi[x][v];
  int res = 0;
  for (int j = head[x]; j; j = e[j].nex) {
    if (e[j].to <= v && e[j].to != par[x]) {
      res += Q(e[j].to, v) + 1;
    }
  }
  return exi[x][v] = res;
}

void dfs2(int x) {
  for (int j = head[x]; j; j = e[j].nex) {
    if (e[j].to != par[x]) {

      if (e[j].to > mx[x]) {
        c[e[j].to] = c[x] + Q(e[j].to, mx[e[j].to]) + 1;
      } else {
        c[e[j].to] = c[x] + Q(e[j].to, mx[e[j].to]) - Q(e[j].to, mx[x]);
      }
      dfs2(e[j].to);
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }
  mx[1] = -1;
  dfs(1, 0);
  dfs2(1);

  for (int i = 2; i <= n; i++)
    printf("%d ", c[i]);
  return 0;
}
Problem p03205 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, lk[maxn + 10], vis[maxn + 10], clk;
int l[maxn + 10], r[maxn + 10];
vector<int> g[maxn + 10];

bool dfs(int p) {
  for (int i = 0; i < (int)g[p].size(); ++i) {
    int e = g[p][i];
    if (vis[e] != clk) {
      vis[e] = clk;
      if (!lk[e] || dfs(lk[e])) {
        lk[e] = p;
        return 1;
      }
    }
  }
  return 0;
}

void getans(int p, int lst) {
  for (int i = 0; i < (int)g[p].size(); ++i) {
    int e = g[p][i];
    if (e != lst && vis[e] != clk) {
      vis[e] = clk;
      l[e] = p;
      r[e] = lk[e];
      getans(lk[e], e);
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int x;
      scanf("%d", &x);
      g[x].push_back(i);
    }
  }
  for (int i = 1; i < n; ++i) {
    ++clk;
    if (!dfs(i)) {
      printf("-1");
      return 0;
    }
  }
  ++clk;
  getans(n, 0);
  for (int i = 1; i < n; ++i)
    if (!l[i]) {
      printf("-1");
      return 0;
    }
  for (int i = 1; i < n; ++i)
    printf("%d %d\n", l[i], r[i]);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, lk[maxn + 10], vis[maxn + 10], clk;
int l[maxn + 10], r[maxn + 10];
vector<int> g[maxn + 10];

bool dfs(int p) {
  for (int i = 0; i < (int)g[p].size(); ++i) {
    int e = g[p][i];
    if (vis[e] != clk) {
      vis[e] = clk;
      if (!lk[e] || dfs(lk[e])) {
        lk[e] = p;
        return 1;
      }
    }
  }
  return 0;
}

void getans(int p, int lst) {
  for (int i = 0; i < (int)g[p].size(); ++i) {
    int e = g[p][i];
    if (e != lst && vis[e] != clk) {
      vis[e] = clk;
      l[e] = p;
      r[e] = lk[e];
      getans(lk[e], e);
    }
  }
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int x;
      scanf("%d", &x);
      g[x].push_back(i);
    }
  }
  for (int i = 1; i <= n; ++i)
    random_shuffle(g[i].begin(), g[i].end());
  for (int i = 1; i < n; ++i) {
    ++clk;
    if (!dfs(i)) {
      printf("-1");
      return 0;
    }
  }
  ++clk;
  getans(n, 0);
  for (int i = 1; i < n; ++i)
    if (!l[i]) {
      printf("-1");
      return 0;
    }
  for (int i = 1; i < n; ++i)
    printf("%d %d\n", l[i], r[i]);
}
Problem p03206 (Python)

Buggy submission (status: Runtime Error):
s = int(input)
if s == 22:
    print("Christmas Eve Eve Eve")
if s == 23:
    print("Christmas Eve Eve")
if s == 24:
    print("Christmas Eve")
if s == 25:
    print("Christmas")


Fixed submission:
s = int(input())
if s == 22:
    print("Christmas Eve Eve Eve")
if s == 23:
    print("Christmas Eve Eve")
if s == 24:
    print("Christmas Eve")
if s == 25:
    print("Christmas")
Problem p03206 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  int n;
  while (scanf("%d", &n)) {
    if (n == 25)
      printf("Christmas\n");
    if (n == 24)
      printf("Christmas Eve\n");
    if (n == 23)
      printf("Christmas Eve Eve\n");
    if (n == 22)
      printf("Christmas Eve Eve Eve\n");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int n;
  scanf("%d", &n);

  if (n == 25)
    printf("Christmas\n");
  if (n == 24)
    printf("Christmas Eve\n");
  if (n == 23)
    printf("Christmas Eve Eve\n");
  if (n == 22)
    printf("Christmas Eve Eve Eve\n");

  return 0;
}
Problem p03206 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
#include <stdlib.h>

int main() {
  int d;
  while (scanf("%d", &d)) {
    if (d == 25)
      printf("Christmas\n");
    else if (d == 24)
      printf("Christmas Eve\n");
    else if (d == 23)
      printf("Christmas Eve Eve\n");
    else if (d == 22)
      printf("Christmas Eve Eve Eve\n");
  }
}


Fixed submission:
#include <stdio.h>
#include <stdlib.h>

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

  if (d == 25)
    printf("Christmas\n");
  else if (d == 24)
    printf("Christmas Eve\n");
  else if (d == 23)
    printf("Christmas Eve Eve\n");
  else if (d == 22)
    printf("Christmas Eve Eve Eve\n");
}
Problem p03206 (C++)

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

int main() {
  int d;
  cin >> d;
  string ans = "Christmas";
  while (d < 25) {
    ans += " Eve";
  }
  cout << ans << endl;
}


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

int main() {
  int d;
  cin >> d;
  string ans = "Christmas";
  while (d++ < 25) {
    ans += " Eve";
  }
  cout << ans << endl;
}