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

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

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/abc103/tasks/abc103_d

int N, M;
pair<int, int> P[10000];

bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  cin >> N >> M;
  rep(i, M) { cin >> P[i].first >> P[i].second; }
  sort(P, P + M, comp);

  int ans = 0;
  int remove = 0;
  rep(i, M) {
    // cout << P[i] << endl;
    if (P[i].first > remove) {
      remove = P[i].second - 1;
      // cout << "removed:" << remove << endl;
      ans++;
    } else {
    }
  }
  cout << ans << endl;

  return 0;
}

// vim: foldmethod=marker


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

// template {{{
using namespace std;

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define fill(x, y) memset(x, y, sizeof(x))

using int64 = long long;

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

bool in_field(int W, int H, int x, int y) {
  return (0 <= x && x < W) && (0 <= y && y < H);
}

// pair
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
  return s << "(" << p.first << ", " << p.second << ")";
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << "\t";
  }
  return s;
}

// }}}

// url: https://atcoder.jp/contests/abc103/tasks/abc103_d

int N, M;
pair<int, int> P[100000];

bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  cin >> N >> M;
  rep(i, M) { cin >> P[i].first >> P[i].second; }
  sort(P, P + M, comp);

  int ans = 0;
  int remove = 0;
  rep(i, M) {
    // cout << P[i] << endl;
    if (P[i].first > remove) {
      remove = P[i].second - 1;
      // cout << "removed:" << remove << endl;
      ans++;
    } else {
    }
  }
  cout << ans << endl;

  return 0;
}

// vim: foldmethod=marker
Problem p03295 (C++)

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

int main() {
  // input
  int N, M;
  cin >> N >> M;
  int i, j;
  vector<pair<int, int>> start, goal;
  int a, b;
  for (i = 0; i < M; i++) {
    cin >> a >> b;
    start.push_back(make_pair(a - 1, i));
    goal.push_back(make_pair(b - 1, i));
  }

  // calc
  sort(start.begin(), start.end());
  sort(goal.begin(), goal.end());
  bool usable[N];
  fill(usable, usable + N, 1);
  int ans = 0, j_sta = 0;
  for (i = 0; i < M; i++) {
    if (usable[goal[i].second]) {
      ans++;
      usable[goal[i].second] = 0;
      for (j = j_sta; j < M; j++) {
        if (start[j].first < goal[i].first) {
          usable[start[j].second] = 0;
        } else {
          break;
        }
      }
      j_sta = j;
    }
  }

  // answer
  cout << ans << endl;
  system("pause");
  return 0;
}

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

int main() {
  // input
  int N, M;
  cin >> N >> M;
  int i, j;
  vector<pair<int, int>> start, goal;
  int a, b;
  for (i = 0; i < M; i++) {
    cin >> a >> b;
    start.push_back(make_pair(a - 1, i));
    goal.push_back(make_pair(b - 1, i));
  }

  // calc
  sort(start.begin(), start.end());
  sort(goal.begin(), goal.end());
  bool usable[M];
  fill(usable, usable + M, 1);
  int ans = 0, j_sta = 0;
  for (i = 0; i < M; i++) {
    if (usable[goal[i].second]) {
      ans++;
      usable[goal[i].second] = 0;
      for (j = j_sta; j < M; j++) {
        if (start[j].first < goal[i].first) {
          usable[start[j].second] = 0;
        } else {
          break;
        }
      }
      j_sta = j;
    }
  }

  // answer
  cout << ans << endl;
  system("pause");
  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
typedef long long ll;
typedef pair<int, int> P;

int p[29], ans = 0, a[29], b[29];
const int nmax = 8;
bool graph[nmax][nmax];
bool pairCompare(const P &firstElof, const P &secondElof) {
  return firstElof.second < secondElof.second;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  scanf("%d %d", &N, &M);

  vector<P> warsP(M);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    warsP[i] = P(a, b);
  }
  sort(warsP.begin(), warsP.end(), pairCompare);
  int ans = 0;
  while (warsP.size()) {
    int x = warsP[0].second;
    ans++;
    for (int i = warsP.size() - 1; i >= 0; i--) {
      if (x <= warsP[i].second && x > warsP[i].first) {
        warsP.erase(warsP.begin() + i);
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
typedef long long ll;
typedef pair<int, int> P;

int p[29], ans = 0, a[29], b[29];
const int nmax = 8;
bool graph[nmax][nmax];
bool pairCompare(const P &firstElof, const P &secondElof) {
  return firstElof.second < secondElof.second;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N, M;
  scanf("%d %d", &N, &M);

  vector<P> warsP(M);
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    warsP[i] = P(a, b);
  }
  sort(warsP.begin(), warsP.end(), pairCompare);
  int ans = 1;
  int brk = 0;
  REP(i, warsP.size()) {
    int x = warsP[brk].second;
    if (x <= warsP[i].first) {
      brk = i;
      ans++;
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Runtime Error):

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

int main(void) {
  int n, m, x, y, cou = 0;
  cin >> n >> m;
  vector<pair<int, int>> vec(m);
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    vec[i] = make_pair(y, x);
  }

  sort(vec.begin(), vec.end());
  n = 0;
  for (int i = 0; i < m; i++) {
    if (n <= vec[i].second) {
      n = vec[i].first;
      cou++;
    }
  }
  cout << cou << endl;

  return 1;
}


Fixed submission:

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

int main(void) {
  int n, m, x, y, cou = 0;
  cin >> n >> m;
  vector<pair<int, int>> vec(m);
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    vec[i] = make_pair(y, x);
  }

  sort(vec.begin(), vec.end());
  n = 0;
  for (int i = 0; i < m; i++) {
    if (n <= vec[i].second) {
      n = vec[i].first;
      cou++;
    }
  }
  cout << cou << endl;

  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <queue>
#include <unordered_map>
#define MOD 1000000007
#define REP(i, st, num) for (int i = (st); i < (num); ++i)
#define ll long long
using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b) {
  return a.second < b.second || a.first < b.first;
}

int main() {
  ios::sync_with_stdio(false);
  int N, M, a, b;
  vector<pair<int, int>> vp;
  cin >> N >> M;
  REP(i, 0, M) {
    cin >> a >> b;
    vp.push_back(make_pair(a, b));
  }
  sort(vp.begin(), vp.end(), cmp);
  int right = -1, ans = 0;
  REP(i, 0, M) {
    if (right <= vp[i].first) {
      right = vp[i].second;
      ans++;
    }
  }
  cout << ans;
  return 0;
}
// 1 2 3 4x5 6 7x8 9
// 1 8
// 2 7
// 3 5
// 4 6
// 7 9

Fixed submission:
#include <bits/stdc++.h>
#include <queue>
#include <unordered_map>
#define MOD 1000000007
#define REP(i, st, num) for (int i = (st); i < (num); ++i)
#define ll long long
using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.second == b.second) {
    return a.first < b.first;
  }
  return a.second < b.second;
}

int main() {
  ios::sync_with_stdio(false);
  int N, M, a, b;
  vector<pair<int, int>> vp;
  cin >> N >> M;
  REP(i, 0, M) {
    cin >> a >> b;
    vp.push_back(make_pair(a, b));
  }
  sort(vp.begin(), vp.end(), cmp);
  int right = -1, ans = 0;
  REP(i, 0, M) {
    if (right <= vp[i].first) {
      right = vp[i].second;
      ans++;
    }
  }
  cout << ans;
  return 0;
}
// 1 2 3 4x5 6 7x8 9
// 1 8
// 2 7
// 3 5
// 4 6
// 7 9
Problem p03295 (C++)

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

int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  vector<vector<int>> br(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    br[a].push_back(b);
  }

  vector<int> dp(N + 1);

  for (int i = 1; i <= N; ++i) {
    dp[i] = max(dp[i], dp[i - 1]);
    for (int j : br[i])
      dp[j] = max(dp[j], dp[i] + 1);
  }
  cout << dp[N] << endl;
  return 0;
}


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

int main() {
  int N, M, ans = 0;
  cin >> N >> M;
  vector<vector<int>> br(N + 1);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    br[a].push_back(b);
  }

  vector<int> dp(N + 1);

  for (int i = 1; i <= N; ++i) {
    dp[i] = max(dp[i], dp[i - 1]);
    for (int j : br[i])
      dp[j] = max(dp[j], dp[i] + 1);
  }
  cout << dp[N] << endl;
  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <vector>
int main() {
  int n, m, a, b;
  std::vector<std::pair<int, int>> v;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    v.push_back({b, a});
  }
  std::sort(v.begin(), v.end());
  int i = 0, ans = 0;
  while (i < m) {
    b = v[i].first;
    a = v[i].second;
    ans++;
    while (v[i].second < b)
      i++;
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <vector>
int main() {
  int n, m, a, b;
  std::vector<std::pair<int, int>> v;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a, &b);
    v.push_back({b, a});
  }
  std::sort(v.begin(), v.end());
  int i = 0, ans = 0;
  while (i < m) {
    b = v[i].first;
    a = v[i].second;
    ans++;
    while (i < m && v[i].second < b)
      i++;
  }
  printf("%d", ans);
  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(x) (x).begin(), (x).end()

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> ci(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ci[i] = {b, a};
  }
  sort(all(ci));
  int res = 0;
  int ma = -1;
  rep(i, m) {
    if (ma > ci[i].second)
      continue;
    if (chmax(ma, ci[i].first))
      res++;
  }
  cout << res << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(x) (x).begin(), (x).end()

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> ci(m);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    ci[i] = {b, a};
  }
  sort(all(ci));
  int res = 0;
  int ma = -1;
  rep(i, m) {
    if (ma > ci[i].second)
      continue;
    if (chmax(ma, ci[i].first))
      res++;
  }
  cout << res << endl;

  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define MAX 300000
#define INF 3000
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int N, M, a, b, temp = 0, ans = 0;
  P A[110000];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    A[i] = make_pair(b, a);
  }
  for (int i = 0; i < M; i++) {
    sort(A, A + M);
  }
  for (int i = 0; i < M; i++) {
    if (temp <= A[i].second) {
      ans++;
      temp = A[i].first;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;
#define MAX 300000
#define INF 3000
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int N, M, a, b, temp = 0, ans = 0;
  P A[110000];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    A[i] = make_pair(b, a);
  }
  sort(A, A + M);
  for (int i = 0; i < M; i++) {
    if (temp <= A[i].second) {
      ans++;
      temp = A[i].first;
    }
  }
  cout << ans << endl;
}
Problem p03295 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())

ab = [0] * M
for _ in range(M):
    a, b = map(int, input().split())
    ab[a].append(b)

dp = [0] * (N + 1)
for i in range(1, N + 1):
    dp[i] = max(dp[i], dp[i - 1])
    for j in ab[i]:
        dp[j] = max(dp[j], dp[i] + 1)

print(dp[N])


Fixed submission:
N, M = map(int, input().split())

ab = [[] for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    ab[a].append(b)

dp = [0] * (N + 1)
for i in range(1, N + 1):
    dp[i] = max(dp[i], dp[i - 1])
    for j in ab[i]:
        dp[j] = max(dp[j], dp[i] + 1)

print(dp[N])
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef unsigned long long uLL;
const int M = 2005;
const int N = 1000005;
const int mod = 1000000007;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const LL lINF = 0x3f3f3f3f3f3f3f3fLL;
const int sINF = 0xcfcfcfcf;
#define ls (rt << 1)
#define rs (rt << 1 | 1)
P a[M];
LL n, m;
bool cmp(P a, P b) { return a.second < b.second; }
int main() {
  while (~scanf("%lld%lld", &n, &m)) {
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &a[i].first, &a[i].second);
    }
    sort(a, a + m, cmp);
    int l = 0, cnt = 0;
    for (int i = 0; i < m; i++) {
      if (a[i].first >= l) {
        l = a[i].second;
        cnt++;
      }
    }
    printf("%d\n", cnt);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef unsigned long long uLL;
const int M = 100005;
const int N = 1000005;
const int mod = 1000000007;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const LL lINF = 0x3f3f3f3f3f3f3f3fLL;
const int sINF = 0xcfcfcfcf;
#define ls (rt << 1)
#define rs (rt << 1 | 1)
P a[M];
LL n, m;
bool cmp(P a, P b) { return a.second < b.second; }
int main() {
  while (~scanf("%lld%lld", &n, &m)) {
    for (int i = 0; i < m; i++) {
      scanf("%d%d", &a[i].first, &a[i].second);
    }
    sort(a, a + m, cmp);
    int l = 0, cnt = 0;
    for (int i = 0; i < m; i++) {
      if (a[i].first >= l) {
        l = a[i].second;
        cnt++;
      }
    }
    printf("%d\n", cnt);
  }
}
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
struct node {
  int z;
  int y;
} a[20001];
int cmp(node m, node n) { return m.z == n.z ? m.y < n.y : m.z < n.z; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].z, &a[i].y); // cin>>a[i].z>>a[i].y;
  }
  sort(a + 1, a + 1 + m, cmp);
  int ans = 0, time = 0;
  for (int i = 1; i <= m; i++) {
    if (a[i].z < time && a[i].y >= time)
      continue;
    else {
      ans++;
      time = a[i].y;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
struct node {
  int z;
  int y;
} a[100001];
int cmp(node m, node n) { return m.y == n.y ? m.z < n.z : m.y < n.y; }
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].z, &a[i].y); // cin>>a[i].z>>a[i].y;
  }
  sort(a + 1, a + 1 + m, cmp);
  int ans = 0, time = 0;
  for (int i = 1; i <= m; i++) {
    if (a[i].z < time && a[i].y >= time)
      continue;
    else {
      ans++;
      time = a[i].y;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03295 (C++)

Buggy submission (status: Runtime Error):


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

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low, high, i) for (i = low; i < high; i++)
#define forrev(high, low, i) for (i = high; i >= low; i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod = 1e9 + 7;

ll power(ll x, ll y) {
  x %= mod;
  if (y == 0)
    return 1;
  ll p = power(x, y / 2) % mod;
  p = (p * p) % mod;

  return (y % 2 == 0) ? p : (x * p) % mod;
}

int main() {
  IOS
#ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  IOS ll n, m;
  cin >> n >> m;
  pll a[m];
  for (ll i = 0; i < m; i++) {
    cin >> a[i].ff >> a[i].ss;
  }
  sort(a, a + m, [](pll x, pll y) { return x.ss < y.ss; });
  ll last = a[0].ss - 1;
  ll ans = 1;
  for (ll i = 1; i < m; i++) {
    if (a[i].ff > last) {
      ans++;
      last = a[i].ss - 1;
    }
  }

  cout << ans << endl;
}


Fixed submission:


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

#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low, high, i) for (i = low; i < high; i++)
#define forrev(high, low, i) for (i = high; i >= low; i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;

typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod = 1e9 + 7;

ll power(ll x, ll y) {
  x %= mod;
  if (y == 0)
    return 1;
  ll p = power(x, y / 2) % mod;
  p = (p * p) % mod;

  return (y % 2 == 0) ? p : (x * p) % mod;
}

int main() {
  IOS

      ll n,
      m;
  cin >> n >> m;
  pll a[m];
  for (ll i = 0; i < m; i++) {
    cin >> a[i].ff >> a[i].ss;
  }
  sort(a, a + m, [](pll x, pll y) { return x.ss < y.ss; });
  ll last = a[0].ss - 1;
  ll ans = 1;
  for (ll i = 1; i < m; i++) {
    if (a[i].ff > last) {
      ans++;
      last = a[i].ss - 1;
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <ctime>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
#define ii pair<int, int>
#define f first
#define s second
#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);
#define iii pair<int, ii>
#define in freopen("arquivoentrada", "r", stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define pi 3.14159265359
const int mod = 7723;

using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;

using namespace std;

const int maxn = 1e4 + 10;

int n, m;

ii arr[maxn];
signed main() {
  //~ in
  cin >> n >> m;

  for (int i = 0; i < m; i++)
    cin >> arr[i].f >> arr[i].s;

  sort(arr, arr + m, [&](ii a, ii b) {
    if (a.f == b.f) {
      return a.s < b.s;
    }
    return a.f < b.f;
  });

  int ans = 1;
  ii aux = arr[0];
  for (int i = 1; i < m; i++) {
    if (aux.s > arr[i].f)
      aux.s = min(arr[i].s, aux.s);
    else
      ++ans, aux = arr[i];
  }

  cout << ans << '\n';

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <ctime>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
#define ii pair<int, int>
#define f first
#define s second
#define fast_io                                                                \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(nullptr);
#define iii pair<int, ii>
#define in freopen("arquivoentrada", "r", stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define pi 3.14159265359
const int mod = 7723;

using namespace std;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long long ll;

using namespace std;

const int maxn = 3e5 + 100;

int n, m;

ii arr[maxn];
signed main() {
  //~ in
  cin >> n >> m;

  for (int i = 0; i < m; i++)
    cin >> arr[i].f >> arr[i].s;

  sort(arr, arr + m, [&](ii a, ii b) {
    if (a.f == b.f) {
      return a.s < b.s;
    }
    return a.f < b.f;
  });

  int ans = 1;
  ii aux = arr[0];
  for (int i = 1; i < m; i++) {
    if (aux.s > arr[i].f)
      aux.s = min(arr[i].s, aux.s);
    else
      ++ans, aux = arr[i];
  }

  cout << ans << '\n';

  return 0;
}
Problem p03295 (Python)

Buggy submission (status: Time Limit Exceeded):
islands = []
bridges = []

N, M = map(int, input().split())

for i in range(M):
    a, b = map(int, input().split())
    islands.append({"a": a, "b": b})

islands.sort(key=lambda x: x["b"])
# print(islands)

for i in islands:
    b = [j for j in bridges if j >= i["a"]]
    b = [j for j in b if j < i["b"]]
    if len(b) == 0:
        bridges.append(i["b"] - 1)

# print(bridges)
print(len(bridges))


Fixed submission:
islands = []
bridges = []

N, M = map(int, input().split())

for i in range(M):
    a, b = map(int, input().split())
    islands.append({"a": a, "b": b})

islands.sort(key=lambda x: x["b"])
# print(islands)

for i in islands:
    b = [j for j in bridges if j >= i["a"]]
    if len(b) == 0:
        bridges.append(i["b"] - 1)

# print(bridges)
print(len(bridges))
Problem p03295 (Python)

Buggy submission (status: Runtime Error):
import sys

N, M = map(int, input().split())
A = [tuple(map(int, line.split())) for line in sys.stdin.buffer.readlines()]
A.sort()
cnt = 0
R = 0
for a, b in A:
    if R <= a:
        cnt += 1
        R = b
    elif b < R:
        R = b
print(cnt)


Fixed submission:
N, M, *A = map(int, open(0).read().split())
(*A,) = zip(*[iter(A)] * 2)
A.sort()
cnt = 0
R = 0
for a, b in A:
    if R <= a:
        cnt += 1
        R = b
    elif b < R:
        R = b
print(cnt)
Problem p03295 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys

input = sys.stdin.readline

n, m = [int(x) for x in input().split()]

islands = [set() for _ in range(n + 1)]

for _ in range(m):
    ab = [int(x) for x in input().split()]
    islands[min(ab)].add(max(ab))

ans = 0

for i in range(1, n):
    if i + 1 in islands[i]:
        ans += 1
    else:
        islands[i + 1] = islands[i] | islands[i + 1]

ans += len(islands[n])

print(ans)


Fixed submission:
import sys

input = sys.stdin.readline

n, m = [int(x) for x in input().split()]

islands = [set() for _ in range(n + 1)]

for _ in range(m):
    ab = [int(x) for x in input().split()]
    islands[min(ab)].add(max(ab))

ans = 0

for i in range(1, n):
    if i + 1 in islands[i]:
        ans += 1
    elif len(islands[i]) > 0:
        islands[i + 1].add(min(islands[i]))

ans += len(islands[n])

print(ans)
Problem p03295 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int INF = 1e9 + 7;
int mod = 100000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  int N, M;
  cin >> N >> M;
  vector<P> ab(M);
  for (int i = 0; i < M; i++) {
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab.begin(), ab.end());
  priority_queue<int, vector<int>, greater<int>> que;
  int ans = 0, now = 0;
  for (int i = 1; i <= N; i++) {
    while (ab[now].first == i) {
      que.push(ab[now].second - 1);
      now++;
      if (now == M) {
        goto home;
      }
    }
    int x = que.top();
    if (x == i) {
      ans++;
      while (!que.empty()) {
        que.pop();
      }
    }
  }
home:;
  if (!que.empty()) {
    ans++;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> P;
int INF = 1e9 + 7;
int mod = 100000;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  int N, M;
  cin >> N >> M;
  vector<P> ab(M);
  for (int i = 0; i < M; i++) {
    cin >> ab[i].first >> ab[i].second;
  }
  sort(ab.begin(), ab.end());
  priority_queue<int, vector<int>, greater<int>> que;
  int ans = 0, now = 0;
  for (int i = 1; i <= N; i++) {
    while (ab[now].first == i) {
      que.push(ab[now].second - 1);
      now++;
      if (now == M) {
        goto home;
      }
    }
    if (!que.empty()) {
      int x = que.top();
      if (x == i) {
        ans++;
        while (!que.empty()) {
          que.pop();
        }
      }
    }
  }
home:;
  if (!que.empty()) {
    ans++;
  }
  cout << ans << endl;
}
Problem p03295 (C++)

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

bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.second;
  }
}

int main(void) {

  int N, M;

  cin >> N >> M;

  vector<pair<int, int>> v;
  v.resize(M);
  for (int i = 0; i < M; i++)
    cin >> v[i].first >> v[i].second;

  sort(v.begin(), v.end(), comp);
  int mx = 0;
  int cont = 0;

  for (auto u : v) {

    if (mx <= u.first) {
      cont++;
      mx = u.second;
    }
  }

  cout << cont << endl;
  return 0;
}


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

bool comp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; }

int main(void) {

  int N, M;

  cin >> N >> M;

  vector<pair<int, int>> v;
  v.resize(M);
  for (int i = 0; i < M; i++)
    cin >> v[i].first >> v[i].second;

  sort(v.begin(), v.end(), comp);
  int mx = 0;
  int cont = 0;

  for (auto u : v) {

    if (mx <= u.first) {
      cont++;
      mx = u.second;
    }
  }

  cout << cont << endl;
  return 0;
}
Problem p03296 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
a = list(map(int, input().split()))

count = 0

for x in range(N):
    if x != N - 1:
        if a[x] == a[x + 1]:
            if x + 1 < N:
                if a[x + 2] == 10000:
                    a[x + 1] = 9999
                    count += 1
                else:
                    a[x + 1] = 10000
                    count += 1
            else:
                a[x + 1] = 10000
                count += 1
print(count)


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

count = 0

for x in range(N):
    if x != N - 1:
        if a[x] == a[x + 1]:
            if x < N - 2:
                if a[x + 2] == 10000:
                    a[x + 1] = 9999
                    count += 1
                else:
                    a[x + 1] = 10000
                    count += 1
            else:
                a[x + 1] = 10000
                count += 1
print(count)
Problem p03296 (C++)

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<int>> matrix;

#define SET(Ar, val) memset(Ar, val, sizeof(Ar))
#define rep(i, val, n) for (int i = val; i < n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LMAX LONG_LONG_MAX
#define LMIN LONG_LONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define M 1000000007ll
#define md 998244353

/*--------------------------------------------------------------------------------------------------------------------------------*/

template <class T> T modpower(T a, T b, T MOD) {
  T ans = 1;
  while (b != 0) {
    if (b % 2 == 1)
      ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return ans;
}

void init() {
  int n;
  cin >> n;
  vi v1;
  v1.resize(n);
  rep(i, 0, n) cin >> v1[i];
  int ans = 0;
  int i = 1;
  while (i < n) {
    if (v1[i] == v1[i - 1]) {
      ans++;
      i += 2;
    } else {
      i++;
    }
  }
  cout << ans;
}

int main() {
  clock_t time1 = clock();
#ifndef ONLINE_JUDGE
  freopen("input1.txt", "r", stdin);
#else
// ONLINE_JUDGE
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  clock_t time2 = clock();
  cerr << "Time: " << (double)(time2 - time1) / CLOCKS_PER_SEC * 100000
       << " seconds" << endl;
  return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<int>> matrix;

#define SET(Ar, val) memset(Ar, val, sizeof(Ar))
#define rep(i, val, n) for (int i = val; i < n; i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LMAX LONG_LONG_MAX
#define LMIN LONG_LONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define M 1000000007ll
#define md 998244353

/*--------------------------------------------------------------------------------------------------------------------------------*/

template <class T> T modpower(T a, T b, T MOD) {
  T ans = 1;
  while (b != 0) {
    if (b % 2 == 1)
      ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b /= 2;
  }
  return ans;
}

void init() {
  int n;
  cin >> n;
  vi v1;
  v1.resize(n);
  rep(i, 0, n) cin >> v1[i];
  int ans = 0;
  int i = 1;
  while (i < n) {
    if (v1[i] == v1[i - 1]) {
      ans++;
      i += 2;
    } else {
      i++;
    }
  }
  cout << ans;
}

int main() {
  clock_t time1 = clock();

  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  clock_t time2 = clock();
  cerr << "Time: " << (double)(time2 - time1) / CLOCKS_PER_SEC * 100000
       << " seconds" << endl;
  return 0;
}
Problem p03296 (C++)

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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int)(u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}

template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
  register T sum = 0, fg = 1;
  register char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      fg = -1;
  for (; isdigit(ch); ch = getchar())
    sum = (sum << 3) + (sum << 1) - '0' + ch;
  return sum * fg;
}

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

const int MAXN = (int)100;

int n;

int a[MAXN + 5];

inline void input() {
  n = read<int>();
  for (int i = 1; i <= n; ++i)
    a[i] = read<int>();
}

inline void solve() {
  int ans = 0;
  for (int i = 2; i <= n; ++i)
    if (a[i] == a[i - 1])
      a[i] = -1, ++ans;
  printf("%d\n", ans);
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("A.in", "r", stdin);
  freopen("A.out", "w", stdout);
#endif

  input();
  solve();

  return 0;
}


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

using namespace std;

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define fst first
#define snd second
#define SZ(u) ((int)(u).size())
#define ALL(u) (u).begin(), (u).end()

inline void proc_status() {
  ifstream t("/proc/self/status");
  cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>())
       << endl;
}

template <typename T> inline bool chkmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T> inline bool chkmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T> inline T read() {
  register T sum = 0, fg = 1;
  register char ch(getchar());
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      fg = -1;
  for (; isdigit(ch); ch = getchar())
    sum = (sum << 3) + (sum << 1) - '0' + ch;
  return sum * fg;
}

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

const int MAXN = (int)100;

int n;

int a[MAXN + 5];

inline void input() {
  n = read<int>();
  for (int i = 1; i <= n; ++i)
    a[i] = read<int>();
}

inline void solve() {
  int ans = 0;
  for (int i = 2; i <= n; ++i)
    if (a[i] == a[i - 1])
      a[i] = -1, ++ans;
  printf("%d\n", ans);
}

int main() {
  input();
  solve();

  return 0;
}
Problem p03296 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, a[50], answer = 0;
  cin >> n >> a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    if (a[i - 1] == a[i]) {
      i++;
      answer++;
    }
  }
  cout << answer;
  /* code */
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, a[1000], answer = 0;
  cin >> n >> a[0];
  for (int i = 1; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i < n; i++) {
    if (a[i - 1] == a[i]) {
      i++;
      answer++;
    }
  }
  cout << answer;
  /* code */
  return 0;
}
Problem p03296 (C++)

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

using namespace std;

int main() {
  int n, arr[n], count = 0;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> arr[i];
  for (int i = 1; i < n; ++i) {
    if (arr[i] == arr[i - 1]) {
      count++;
      arr[i] = -1;
    }
  }
  cout << count;
  return 0;
}


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

using namespace std;

int main() {
  int n, arr[1000000], count = 0;
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> arr[i];
  for (int i = 1; i < n; ++i) {
    if (arr[i] == arr[i - 1]) {
      count++;
      arr[i] = -1;
    }
  }
  cout << count;
  return 0;
}
Problem p03296 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int i = 1;
  if (n == 2) {
    if (v[0] == v[1])
      cout << 1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  int count = 0;
  while (i < n) {
    if (v[i] == v[i - 1]) {
      count++;
      i = i + 2;
    } else if ((i + 1 < n) && v[i] == v[i + 1]) {
      count++;
      i = i + 3;
    } else
      ;
  }
  cout << count << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int i = 1;
  if (n == 2) {
    if (v[0] == v[1])
      cout << 1 << endl;
    else
      cout << 0 << endl;
    return 0;
  }
  int count = 0;
  while (i < n) {
    if (v[i] == v[i - 1]) {
      count++;
      i = i + 2;
    } else if ((i + 1 < n) && v[i] == v[i + 1]) {
      count++;
      i = i + 3;
    } else
      i = i + 2;
  }
  cout << count << endl;
  return 0;
}
Problem p03296 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define boost                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define rep(i, n) for (i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007
#define __builtin_popcountll bitc
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  boost ll n, i, j, c = 0;
  cin >> n;
  ll a[n];
  rep(i, n) { cin >> a[i]; }
  for (i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      c++;
      a[i] = 0;
    }
  }
  cout << c;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define boost                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define rep(i, n) for (i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007
#define __builtin_popcountll bitc
int main() {

  ll n, i, j, c = 0;
  cin >> n;
  ll a[n];
  rep(i, n) { cin >> a[i]; }
  for (i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      c++;
      a[i] = 0;
    }
  }
  cout << c;
}
Problem p03296 (C++)

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

#define PI 3.14159265359
#define rep(i, a, n) for (int i = a; i < (int)n; ++i)
#define SZ(x) ((int)(x).size()) // size() unsigned -> int
#define descSort(a) sort(a.begin(), a.end(), std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  int ans = 0, j;
  for (int i = 0; i < n;) {
    int cnt = 1;
    int j = i + 1;
    while (a[i] == a[j]) {
      cnt++;
      j++;
    }
    ans += cnt / 2;
  }
  cout << ans << endl;
  return 0;
}

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

#define PI 3.14159265359
#define rep(i, a, n) for (int i = a; i < (int)n; ++i)
#define SZ(x) ((int)(x).size()) // size() unsigned -> int
#define descSort(a) sort(a.begin(), a.end(), std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  int ans = 0, j;
  for (int i = 0; i < n;) {
    int cnt = 1;
    int j = i + 1;
    while (a[i] == a[j]) {
      cnt++;
      j++;
    }
    i = j;
    ans += cnt / 2;
  }
  cout << ans << endl;
  return 0;
}
Problem p03296 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout << "debuglandınız\n";
#define md 1000000007
ll int n, m, a, ar[105], i, ans, su = 1;
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> ar[i];
  i = 0;
  while (i < n - 1) {
    if (ar[i] == ar[i + 1])
      su++;
    else {
      ans += su / 2;
      su = 1;
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define de cout << "debuglandınız\n";
#define md 1000000007
ll int n, m, a, ar[105], i, ans, su = 1;
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  cin >> n;
  for (i = 0; i < n; i++)
    cin >> ar[i];
  ar[n] = n + 5;
  for (i = 0; i < n; i++) {
    if (ar[i] == ar[i + 1])
      su++;
    else {
      ans += su / 2;
      su = 1;
    }
  }
  cout << ans;
  return 0;
}
Problem p03296 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int> a;
  for (int i = 0; i < N; ++i)
    cin >> a[i];

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


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

int main() {
  int N;
  cin >> N;
  vector<int> a;
  a.resize(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  int ans = 0;
  for (int i = 1; i < N; ++i) {
    if (a[i] == a[i - 1]) {
      a[i] = -1;
      ++ans;
    }
  }
  cout << ans << endl;
}
Problem p03296 (Python)

Buggy submission (status: Runtime Error):
def main(n: int, a: list):
    prev = [0, 0]
    ans = 0

    for _a in a:
        if _a == prev[0]:
            if prev[1] % 2 == 0:
                ans += 1

            prev[1] += 1
        else:
            prev = [_a, 0]

    print(ans)


if __name__ == "__main__":
    n = int(input())
    a = map(int(input().split()))

    main(n, a)


Fixed submission:
def main(n: int, a: list):
    prev = [0, 0]
    ans = 0

    for _a in a:
        if _a == prev[0]:
            if prev[1] % 2 == 0:
                ans += 1

            prev[1] += 1
        else:
            prev = [_a, 0]

    print(ans)


if __name__ == "__main__":
    n = int(input())
    a = map(int, input().split())

    main(n, a)
Problem p03297 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  long long a[333], b[333], c[333], d[333], t, i, r, p, cb, cd, ca, flag;
  scanf("%lld", &t);
  for (i = 0; i < t; i++)
    scanf("%lld%lld%lld%lld", &a[i], &b[i], &c[i], &d[i]);
  for (i = 0; i < t; i++) {
    flag = 1;
    cb = b[i];
    cd = d[i];
    if (cb > cd) {
      p = cb;
      cb = cd;
      cd = p;
    }
    p = cb;
    while (cd % p != 0) {
      cb = cd % p;
      cd = p;
      p = cb;
    }
    ca = a[i] % b[i];
    while ((ca + p) < b[i])
      ca += p;
    if (a[i] < b[i])
      flag = 0;
    if (d[i] < b[i])
      flag = 0;
    if (ca > c[i])
      flag = 0;
    if (flag == 1)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  long long a[333], b[333], c[333], d[333], t, i, r, p, cb, cd, ca, flag;
  scanf("%lld", &t);
  for (i = 0; i < t; i++)
    scanf("%lld%lld%lld%lld", &a[i], &b[i], &c[i], &d[i]);
  for (i = 0; i < t; i++) {
    flag = 1;
    cb = b[i];
    cd = d[i];
    if (cb > cd) {
      p = cb;
      cb = cd;
      cd = p;
    }
    p = cb;
    while (cd % p != 0) {
      cb = cd % p;
      cd = p;
      p = cb;
    }
    ca = a[i] % b[i];
    ca = b[i] - p + (ca % p);
    if (a[i] < b[i])
      flag = 0;
    if (d[i] < b[i])
      flag = 0;
    if (ca > c[i])
      flag = 0;
    if (flag == 1)
      printf("Yes\n");
    else
      printf("No\n");
  }
  return 0;
}
Problem p03297 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
using namespace std;

long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

int main() {
  long long T;
  cin >> T;
  int count = 0;
  long long A[T], B[T], C[T], D[T];
  for (long long i = 0; i < T; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
  }
  for (long long i = 0; i < T; i++) {
    bool flag = true;
    bool subflag = false;
    long long k = A[i] % B[i];
    long long x, y;
    long long g = GCD(B[i], D[i]);
    if (B[i] > A[i])
      flag = false;
    if (B[i] > D[i])
      flag = false;
    if (flag == true && C[i] >= B[i]) {
      subflag = true;
    }
    if (flag == true && subflag == false) {
      for (long long j = 0; j < B[i]; j++) {
        if ((A[i] + g * j) % B[i] > C[i])
          flag = false;
      }
    }
    if (flag == true)
      cout << "Yes" << endl;
    else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <stdio.h>
#include <string>
using namespace std;

long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

long long extGCD(long long a, long long b, long long &x, long long &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}

int main() {
  long long T;
  cin >> T;
  int count = 0;
  long long A[T], B[T], C[T], D[T];
  for (long long i = 0; i < T; i++) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
  }
  for (long long i = 0; i < T; i++) {
    bool flag = true;
    bool subflag = false;
    long long k = A[i] % B[i];
    long long x, y;
    long long g = GCD(B[i], D[i]);
    if (B[i] > A[i])
      flag = false;
    if (B[i] > D[i])
      flag = false;
    if (flag == true && C[i] >= B[i]) {
      subflag = true;
    }
    if (flag == true && subflag == false) {
      if (B[i] + (A[i] % g) - g > C[i])
        flag = false;
    }
    if (flag == true)
      cout << "Yes" << endl;
    else {
      cout << "No" << endl;
    }
  }

  return 0;
}