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

Buggy submission (status: Runtime Error):
def main():
    from itertools import accumulate

    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10**5 + 1)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    (*x,) = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    from itertools import accumulate

    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10**5 + 2)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m.sort(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    (*x,) = accumulate(table)
    ans = max(x)

    print(ans)


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

Buggy submission (status: Runtime Error):
def main():
    from itertools import accumulate

    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10**5 + 2)
    m = list(zip(stc[::3], stc[1::3], stc[2::3]))
    m = sorted(key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    (*x,) = accumulate(table)
    ans = max(x)

    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    from itertools import accumulate

    n, c, *stc = map(int, open(0).read().split())
    table = [0] * (10**5 + 2)
    m = sorted(list(zip(*[iter(stc)] * 3)), key=lambda a: (a[2], a[0], a[1]))

    ch_ = 0
    t_ = 0
    for s, t, ch in m:
        if ch != ch_:
            ch_ = ch
            t_ = 0
        if t_ == s:
            table[t_ + 1] += 1
        else:
            table[s] += 1

        table[t + 1] -= 1
        t_ = t

    (*x,) = accumulate(table)
    ans = max(x)

    print(ans)


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

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

tt = [[0] * (10**5 + 1) for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s - 1, t):
        tt[c - 1] = 1

ct = [0] * (10**5 + 1)
for i in range(C):
    for j in range(10**5 + 1):
        ct[j] += tt[i][j]

print(max(ct))


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

tt = [[0] * (10**5 + 1) for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    for i in range(s - 1, t):
        tt[c - 1][i] = 1

ct = [0] * (10**5 + 1)
for i in range(C):
    for j in range(10**5 + 1):
        ct[j] += tt[i][j]

print(max(ct))
Problem p03504 (Python)

Buggy submission (status: Time Limit Exceeded):
def main():
    N, C = map(int, input().split())
    stc = [list(map(int, input().split())) for _ in range(N)]
    st = []
    mxt = 0
    mnt = 0
    while len(stc) > 0:
        s, t, c = stc.pop()
        for i, (ss, tt, cc) in enumerate(stc):
            if c == cc:
                if s == tt:
                    stc.pop(i)
                    stc.append((ss, t, c))
                    break
                elif ss == t:
                    stc.pop(i)
                    stc.append((s, tt, c))
                    break
        else:
            mnt = min(mnt, s - 1)
            mxt = max(mxt, t)
            st.append((s - 1, t))
    cs = [0] * (mxt + 1)
    for s, t in st:
        cs[s] += 1
        cs[t] += -1
    ans = 0
    cc = 0
    for c in cs:
        cc += c
        ans = max(ans, cc)
    print(ans)


main()


Fixed submission:
def main():
    N, C = map(int, input().split())
    stc = [[0] * (10**5) for _ in range(C)]
    for _ in range(N):
        s, t, c = map(int, input().split())
        stc[c - 1][s - 1 : t] = [1] * (t - s + 1)
    print(max(map(sum, zip(*stc))))


main()
Problem p03504 (Python)

Buggy submission (status: Time Limit Exceeded):
N, C = map(int, input().split())

channels = [[] for _ in range(C)]
maxT = 0

for _ in range(N):
    s, t, c = map(int, input().split())
    maxT = max(maxT, t)
    channels[c - 1].append((s, t))

maxT = maxT * 2 + 10
tvSum = [0 for _ in range(maxT)]

for tv in channels:
    imos = [0 for _ in range(maxT)]
    for s, t in tv:
        imos[s * 2 - 1] += 1
        imos[t * 2] -= 1
    for i in range(1, maxT):
        imos[i] += imos[i - 1]
    for i in range(maxT):
        if imos[i] > 0:
            tvSum[i] += 1

ans = 0
for i in range(maxT):
    ans = max(ans, tvSum[i])

print(ans)


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

channels = [[] for _ in range(C)]
maxT = 0

for _ in range(N):
    s, t, c = map(int, input().split())
    maxT = max(maxT, t)
    channels[c - 1].append((s, t))

maxT = maxT * 2 + 10
tvSum = [0 for _ in range(maxT)]

for tv in channels:
    imos = [0 for _ in range(maxT)]
    for s, t in tv:
        imos[s * 2 - 1] += 1
        imos[t * 2] -= 1
    for i in range(1, maxT):
        imos[i] += imos[i - 1]
    for i in range(maxT):
        if imos[i] > 0:
            tvSum[i] += 1

print(max(tvSum))
Problem p03504 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
ans = -float("inf")
for i in range(1, 2**10):
    b, s = i, 0
    cnt = [0 for _ in range(N)]
    while b > 0:
        if b & 1:
            for j in range(N):
                cnt[j] += F[j][s]
        s += 1
        b >>= 1
    sub_ans = 0
    for j in range(N):
        sub_ans += P[j][cnt[j]]
    ans = max(ans, sub_ans)
print(ans)


Fixed submission:
import sys


def main():
    input = sys.stdin.readline
    N, C = map(int, input().split())
    dic = [[] for _ in range(C + 1)]
    for _ in range(N):
        s, t, c = input().split()
        dic[int(c)].append([int(s), int(t)])
    for c in range(C + 1):
        l = len(dic[c])
        if l == 1:
            continue
        dic[c] = sorted(dic[c])
        i = 0
        while i < l - 1:
            if i < l - 1 and dic[c][i][1] == dic[c][i + 1][0]:
                dic[c][i + 1][0] += 1
            else:
                i += 1
    f = [0 for _ in range(100002)]
    for c in range(C + 1):
        for t in dic[c]:
            f[t[0]] += 1
            f[t[1] + 1] -= 1
    ans = 0
    for i in range(1, 100001):
        f[i] += f[i - 1]
        if ans < f[i]:
            ans = f[i]
    print(ans)


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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
const int MAX = 1e8;
struct lll {
  int kaishi, jieshu, biaoji;
} a[11000], b[11000];
;
int cmp(lll a, lll b) { return a.jieshu < b.jieshu; }
int main() {
  int n;
  int x;
  cin >> n >> x;
  for (int i = 0; i < n; i++)
    scanf("%d%d%d", &a[i].kaishi, &a[i].jieshu, &a[i].biaoji);
  sort(a, a + n, cmp);
  int add = 1;
  b[0] = a[0];

  for (int i = 1; i < n; i++) {

    int temp;
    int min1 = MAX;
    for (int j = 0; j < add; j++) {
      if ((a[i].kaishi - b[j].jieshu >= 0 && a[i].kaishi - b[j].jieshu < min1 &&
           a[i].biaoji == b[j].biaoji) ||
          (a[i].kaishi - b[j].jieshu > 0 && a[i].kaishi - b[j].jieshu < min1 &&
           a[i].biaoji != b[j].biaoji)) {
        min1 = a[i].kaishi - b[j].jieshu;
        temp = j;
      }
    }
    if (min1 != MAX)
      b[temp] = a[i];
    else
      b[add++] = a[i];
  }
  cout << add << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
const int MAX = 1e8;
struct lll {
  int kaishi, jieshu, biaoji;
} a[110000], b[110000];
;
int cmp(lll a, lll b) { return a.jieshu < b.jieshu; }
int main() {
  int n;
  int x;
  cin >> n >> x;
  for (int i = 0; i < n; i++)
    scanf("%d%d%d", &a[i].kaishi, &a[i].jieshu, &a[i].biaoji);
  sort(a, a + n, cmp);
  int add = 1;
  b[0] = a[0];

  for (int i = 1; i < n; i++) {

    int temp;
    int min1 = MAX;
    for (int j = 0; j < add; j++) {
      if ((a[i].kaishi - b[j].jieshu >= 0 && a[i].kaishi - b[j].jieshu < min1 &&
           a[i].biaoji == b[j].biaoji) ||
          (a[i].kaishi - b[j].jieshu > 0 && a[i].kaishi - b[j].jieshu < min1 &&
           a[i].biaoji != b[j].biaoji)) {
        min1 = a[i].kaishi - b[j].jieshu;
        temp = j;
      }
    }
    if (min1 != MAX)
      b[temp] = a[i];
    else
      b[add++] = a[i];
  }
  cout << add << endl;
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define T 100005
bool ch[30][T];
int a[T];

int main(void) {
  int N, C;
  cin >> N >> C;
  rep(_, N) {
    int s, t, c;
    cin >> s >> t >> c;
    for (int i = s; i <= t; i++) {
      ch[c][i] = true;
    }
  }
  int res = 0;
  rep(k, C + 1) {
    rep(i, T) {
      if (ch[k][i]) {
        a[i]++;
        res = max(a[i], res);
      }
    }
  }
  cout << res << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define T 100005
bool ch[31][T];
int a[T];

int main(void) {
  int N, C;
  cin >> N >> C;
  rep(_, N) {
    int s, t, c;
    cin >> s >> t >> c;
    for (int i = s; i <= t; i++) {
      ch[c][i] = true;
    }
  }
  int res = 0;
  rep(k, C + 1) {
    rep(i, T) {
      if (ch[k][i]) {
        a[i]++;
        res = max(a[i], res);
      }
    }
  }
  cout << res << endl;

  return 0;
}
Problem p03504 (C++)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll N, C;
vector<P> ch[30];
vector<P> v;
vector<ll> r;

int main() {
  cin >> N >> C;
  for (int i = 0; i < N; i++) {
    ll s, t, c;
    cin >> s >> t >> c;
    ch[c - 1].push_back(make_pair(s, t));
  }
  for (int i = 0; i < C; i++) {
    if (ch[i].size() == 0)
      continue;
    sort(ch[i].begin(), ch[i].end());
    ll s, t, ls, lt;
    ls = ch[i][0].first;
    lt = ch[i][0].second;
    for (int j = 1; j < ch[i].size(); j++) {
      s = ch[i][j].first;
      t = ch[i][j].second;
      if (s != lt) {
        v.push_back(make_pair(lt, ls));
        ls = s;
        lt = t;
      } else {
        lt = t;
      }
    }
    v.push_back(make_pair(lt, ls));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < N; i++) {
    ll s, t;
    s = v[i].second;
    t = v[i].first;
    ll ind = -1;
    ll t_max = -1;
    for (int j = 0; j < r.size(); j++) {
      if (r[j] < s) {
        if (t_max < r[j]) {
          ind = j;
          t_max = r[j];
        }
      }
    }
    if (ind == -1)
      r.push_back(t);
    else
      r[ind] = t;
  }
  cout << r.size() << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

ll N, C;
vector<P> ch[30];
vector<P> v;
vector<ll> r;

int main() {
  cin >> N >> C;
  for (int i = 0; i < N; i++) {
    ll s, t, c;
    cin >> s >> t >> c;
    ch[c - 1].push_back(make_pair(s, t));
  }
  for (int i = 0; i < C; i++) {
    if (ch[i].size() == 0)
      continue;
    sort(ch[i].begin(), ch[i].end());
    ll s, t, ls, lt;
    ls = ch[i][0].first;
    lt = ch[i][0].second;
    for (int j = 1; j < ch[i].size(); j++) {
      s = ch[i][j].first;
      t = ch[i][j].second;
      if (s != lt) {
        v.push_back(make_pair(lt, ls));
        ls = s;
        lt = t;
      } else {
        lt = t;
      }
    }
    v.push_back(make_pair(lt, ls));
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < v.size(); i++) {
    ll s, t;
    s = v[i].second;
    t = v[i].first;
    ll ind = -1;
    ll t_max = -1;
    for (int j = 0; j < r.size(); j++) {
      if (r[j] < s) {
        if (t_max < r[j]) {
          ind = j;
          t_max = r[j];
        }
      }
    }
    if (ind == -1)
      r.push_back(t);
    else
      r[ind] = t;
  }
  cout << r.size() << endl;
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define repr(i, n) for (int i = (n)-1; 0 <= i; --i)
#define each(e, v) for (auto &&e : (v))
#define all(v) begin(v), end(v)
#define DUMP(x) cerr << #x << ": " << (x) << endl
#define DEBUG(x) cerr << #x << ": " << (x) << " (L" << __LINE__ << ")" << endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }

constexpr int tmax = 10000;

int main() {
  int N, C;
  cin >> N >> C;
  vector<vint> ch(C, vint(tmax + 5, 0));
  rep(i, N) {
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    ch[c][s - 1] += 1;
    ch[c][t] -= 1;
  }
  rep(c, C) rep(t, tmax) { ch[c][t + 1] += ch[c][t]; }
  rep(c, C) rep(t, tmax) {
    if (ch[c][t] > 1)
      ch[c][t] = 1;
  }
  vint imos(tmax);
  rep(t, tmax) {
    rep(c, C) { imos[t] += ch[c][t]; }
  }
  int maxim = 1;
  rep(t, tmax) {
    chmax(maxim, imos[t]);
    // cerr << imos[t] << " ";
  }
  // cerr << endl;
  cout << maxim << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define repr(i, n) for (int i = (n)-1; 0 <= i; --i)
#define each(e, v) for (auto &&e : (v))
#define all(v) begin(v), end(v)
#define DUMP(x) cerr << #x << ": " << (x) << endl
#define DEBUG(x) cerr << #x << ": " << (x) << " (L" << __LINE__ << ")" << endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }

constexpr int tmax = 100000;

int main() {
  int N, C;
  cin >> N >> C;
  vector<vint> ch(C, vint(tmax + 5, 0));
  rep(i, N) {
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    ch[c][s - 1] += 1;
    ch[c][t] -= 1;
  }
  rep(c, C) rep(t, tmax) { ch[c][t + 1] += ch[c][t]; }
  rep(c, C) rep(t, tmax) {
    if (ch[c][t] > 1)
      ch[c][t] = 1;
  }
  vint imos(tmax);
  rep(t, tmax) {
    rep(c, C) { imos[t] += ch[c][t]; }
  }
  int maxim = 1;
  rep(t, tmax) {
    chmax(maxim, imos[t]);
    // cerr << imos[t] << " ";
  }
  // cerr << endl;
  cout << maxim << endl;
  return 0;
}
Problem p03504 (C++)

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

using namespace std;

long long int N, C, s, t, d, ans = 0;
bool flag[30][100001] = {};

int main() {
  cin >> N >> C;
  for (int i = 1; i <= N; i++) {
    cin >> s >> t >> d;
    for (int j = s; j <= t; j++)
      flag[d][j] = true;
  }
  for (int i = 1; i <= 100000; i++) {
    long long int num = 0;
    for (int j = 1; j <= C; j++) {
      if (flag[j][i])
        num++;
    }
    ans = max(ans, num);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

long long int N, C, s, t, d, ans = 0;
bool flag[31][100001] = {};

int main() {
  cin >> N >> C;
  for (int i = 1; i <= N; i++) {
    cin >> s >> t >> d;
    for (int j = s; j <= t; j++)
      flag[d][j] = true;
  }
  for (int i = 1; i <= 100000; i++) {
    long long int num = 0;
    for (int j = 1; j <= C; j++) {
      if (flag[j][i])
        num++;
    }
    ans = max(ans, num);
  }
  cout << ans << endl;
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>

using namespace std;
#define REP(i, m, n) for (long long i = m; i < n; ++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(), v.end()

vector<vector<int>> v(50), neat(50);
vector<int> ch;
map<int, int> m;

int main() {
  int n, c;
  cin >> n >> c;
  REP(i, 0, n) {
    int s, t, a;
    cin >> s >> t >> a;
    v[a - 1].push_back(2 * s - 1);
    v[a - 1].push_back(2 * t);
  }
  REP(i, 0, c) {
    if (v[i].size() != 0) {
      sort(all(v[i]));
      neat[i].push_back(v[i][0]);
      REP(j, 1, v[i].size()) {
        if (v[i][j] == v[i][j - 1] + 1) {
          neat[i].pop_back();
        } else {
          neat[i].push_back(v[i][j]);
        }
      }
    }
  }
  REP(i, 0, c) {
    REP(j, 0, neat[i].size()) {
      if (j % 2 == 0) {
        m[neat[i][j]]++;
      } else {
        m[neat[i][j]]--;
      }
      ch.push_back(neat[i][j]);
    }
  }
  sort(all(ch));
  int hoge = m[ch[0]], ans = m[ch[0]];
  REP(i, 1, ch.size()) {
    if (ch[i] != ch[i - 1]) {
      hoge += m[ch[i]];
      ans = max(ans, hoge);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <vector>

using namespace std;
#define REP(i, m, n) for (long long i = m; i < n; ++i)
#define INF 10000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(), v.end()

vector<vector<int>> v(50), neat(50);
vector<int> ch;
map<int, int> m;

int main() {
  int n, c;
  cin >> n >> c;
  REP(i, 0, n) {
    int s, t, a;
    cin >> s >> t >> a;
    v[a - 1].push_back(2 * s - 1);
    v[a - 1].push_back(2 * t);
  }
  REP(i, 0, c) {
    if (v[i].size() != 0) {
      sort(all(v[i]));
      neat[i].push_back(v[i][0]);
      REP(j, 1, v[i].size()) {
        if (v[i][j] == v[i][j - 1] + 1) {
          neat[i].pop_back();
          j++;
          neat[i].push_back(v[i][j]);
        } else {
          neat[i].push_back(v[i][j]);
        }
      }
    }
  }
  REP(i, 0, c) {
    REP(j, 0, neat[i].size()) {
      if (j % 2 == 0) {
        m[neat[i][j]]++;
      } else {
        m[neat[i][j]]--;
      }
      ch.push_back(neat[i][j]);
    }
  }
  sort(all(ch));
  int hoge = m[ch[0]], ans = m[ch[0]];
  REP(i, 1, ch.size()) {
    if (ch[i] != ch[i - 1]) {
      hoge += m[ch[i]];
      ans = max(ans, hoge);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
  int N, M;
  cin >> N >> M;
  vi S(N), T(N), C(N);
  rep(i, N) { cin >> S[i] >> T[i] >> C[i]; }

  // const int N_MAX = 100005;
  const int N_MAX = 100;

  // 種類ごとに店にいた時刻を計測する
  // 各種類で求めた後に、全体で計算する

  vi mm(N_MAX);

  vi imos(N_MAX);
  for (int i = 1; i <= M; i++) {
    // 種類ごとに店にいた時刻を計測
    for (int j = 0; j < N_MAX; j++)
      imos[j] = 0;

    for (int j = 0; j < N; j++) {
      if (C[j] == i) {
        imos[S[j]]++;
        imos[T[j]]--;
      }
    }

    for (int j = 0; j < N_MAX - 1; j++) {
      imos[j + 1] += imos[j];
    }

    for (int j = 0; j < N_MAX - 1; j++) {
      if (imos[j] == 0 && imos[j + 1] == 1) {
        mm[j]++;
      } else if (imos[j] == 1)
        mm[j]++;
    }
  }
  int cnt = 0;
  rep(i, N_MAX) { cnt = max(cnt, mm[i]); }

  cout << cnt << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
  int N, M;
  cin >> N >> M;
  vi S(N), T(N), C(N);
  rep(i, N) { cin >> S[i] >> T[i] >> C[i]; }

  const int N_MAX = 100005;

  // 種類ごとに店にいた時刻を計測する
  // 各種類で求めた後に、全体で計算する

  vi mm(N_MAX);

  vi imos(N_MAX);
  for (int i = 1; i <= M; i++) {
    // 種類ごとに店にいた時刻を計測
    for (int j = 0; j < N_MAX; j++)
      imos[j] = 0;

    for (int j = 0; j < N; j++) {
      if (C[j] == i) {
        imos[S[j]]++;
        imos[T[j]]--;
      }
    }

    for (int j = 0; j < N_MAX - 1; j++) {
      imos[j + 1] += imos[j];
    }

    for (int j = 0; j < N_MAX - 1; j++) {
      if (imos[j] == 0 && imos[j + 1] == 1) {
        mm[j]++;
      } else if (imos[j] == 1)
        mm[j]++;
    }
  }
  int cnt = 0;
  rep(i, N_MAX) { cnt = max(cnt, mm[i]); }

  cout << cnt << endl;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, C;
  cin >> N >> C;
  vector<vector<pair<int, int>>> R(C);
  for (int i = 0; i < N; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    R[c].push_back(make_pair(s, t));
  }
  for (int i = 0; i < C; i++) {
    sort(R[i].begin(), R[i].end());
  }
  vector<vector<pair<int, int>>> R2(C);
  for (int i = 0; i < C; i++) {
    R2[i].push_back(R[i][0]);
    int cnt = R[i].size();
    for (int j = 1; j < cnt; j++) {
      if (R2[i].back().second == R[i][j].first) {
        R2[i].back().second = R[i][j].second;
      } else {
        R2[i].push_back(R[i][j]);
      }
    }
  }
  vector<int> cnt(1000002, 0);
  for (int i = 0; i < C; i++) {
    int sz = R2[i].size();
    for (int j = 0; j < sz; j++) {
      cnt[R2[i][j].first - 1]++;
      cnt[R2[i][j].second]--;
    }
  }
  for (int i = 1; i <= 100001; i++) {
    cnt[i] += cnt[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= 100001; i++) {
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, C;
  cin >> N >> C;
  vector<vector<pair<int, int>>> R(C);
  for (int i = 0; i < N; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    c--;
    R[c].push_back(make_pair(s, t));
  }
  for (int i = 0; i < C; i++) {
    sort(R[i].begin(), R[i].end());
  }
  vector<vector<pair<int, int>>> R2(C);
  for (int i = 0; i < C; i++) {
    if (!R[i].empty()) {
      R2[i].push_back(R[i][0]);
      int cnt = R[i].size();
      for (int j = 1; j < cnt; j++) {
        if (R2[i].back().second == R[i][j].first) {
          R2[i].back().second = R[i][j].second;
        } else {
          R2[i].push_back(R[i][j]);
        }
      }
    }
  }
  vector<int> cnt(1000002, 0);
  for (int i = 0; i < C; i++) {
    int sz = R2[i].size();
    for (int j = 0; j < sz; j++) {
      cnt[R2[i][j].first - 1]++;
      cnt[R2[i][j].second]--;
    }
  }
  for (int i = 1; i <= 100001; i++) {
    cnt[i] += cnt[i - 1];
  }
  int ans = 0;
  for (int i = 0; i <= 100001; i++) {
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n, x;
  cin >> n >> x;
  vector<vector<int>> p(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    p.at(i) = vector<int>{s, t, c};
  }
  sort(begin(p), end(p));
  vector<pair<int, int>> r(30);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 30; j++) {
      if (p.at(i).at(0) > r.at(j).second || p.at(i).at(2) == r.at(i).first) {
        r.at(j) = make_pair(p.at(i).at(2), p.at(i).at(1));
        chmax(ans, j + 1);
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int n, x;
  cin >> n >> x;
  vector<vector<int>> p(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    p.at(i) = vector<int>{s, t, c};
  }
  sort(begin(p), end(p));
  vector<pair<int, int>> r(30);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 30; j++) {
      if (p.at(i).at(0) > r.at(j).second || p.at(i).at(2) == r.at(j).first) {
        r.at(j) = make_pair(p.at(i).at(2), p.at(i).at(1));
        chmax(ans, j + 1);
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03504 (C++)

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

using namespace std;

int main() {
  int N, C;
  int i, j;
  int s, t, c;
  int T[30][10001] = {};
  scanf("%d %d", &N, &C);
  for (i = 0; i < N; i++) {
    scanf("%d %d %d", &s, &t, &c);
    for (j = s - 1; j < t - 1; j++) {
      T[c - 1][j] = 1;
    }
  }
  /*for (j = 0; j < C; j++) {
    for (i = 0; i < 12; i++) {
      printf("%d ", T[j][i]);
    }
    printf("\n");
    }*/
  for (j = 0; j < C; j++) {
    for (i = 0; i < 100000; i++) {
      if (T[j][i] == 0 && T[j][i + 1] == 1) {
        T[j][i] = 1;
      }
    }
  }
  /*for (j = 0; j < C; j++) {
    for (i = 0; i < 12; i++) {
      printf("%d ", T[j][i]);
    }
    printf("\n");
    }*/
  int ans = 0;
  for (i = 0; i < 100000; i++) {
    int ans_now = 0;
    for (j = 0; j < C; j++) {
      ans_now += T[j][i];
    }
    if (ans_now > ans) {
      ans = ans_now;
    }
  }
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <cstdio>

using namespace std;

int main() {
  int N, C;
  int i, j;
  int s, t, c;
  int T[30][100010] = {};
  scanf("%d %d", &N, &C);
  for (i = 0; i < N; i++) {
    scanf("%d %d %d", &s, &t, &c);
    for (j = s - 1; j < t - 1; j++) {
      T[c - 1][j] = 1;
    }
  }
  /*for (j = 0; j < C; j++) {
    for (i = 0; i < 12; i++) {
      printf("%d ", T[j][i]);
    }
    printf("\n");
    }*/
  for (j = 0; j < C; j++) {
    for (i = 0; i < 100000; i++) {
      if (T[j][i] == 0 && T[j][i + 1] == 1) {
        T[j][i] = 1;
      }
    }
  }
  /*for (j = 0; j < C; j++) {
    for (i = 0; i < 12; i++) {
      printf("%d ", T[j][i]);
    }
    printf("\n");
    }*/
  int ans = 0;
  for (i = 0; i < 100000; i++) {
    int ans_now = 0;
    for (j = 0; j < C; j++) {
      ans_now += T[j][i];
    }
    if (ans_now > ans) {
      ans = ans_now;
    }
  }
  printf("%d", ans);
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define mem(a, n) memset(a, n, sizeof(a))
#define pb(x) push_back(x)
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int N = 1e4 + 5;
struct node {
  int s, t, c;
} a[N];

bool cmp(node a, node b) { return a.s < b.s; }

pair<int, int> b[N];
int main() {
  ios::sync_with_stdio(false);
  int n, c, ans = 1;
  cin >> n >> c;
  for (int i = 1; i <= n; i++)
    cin >> a[i].s >> a[i].t >> a[i].c;
  sort(a + 1, a + n + 1, cmp);
  b[1].first = a[1].t, b[1].second = a[1].c;
  for (int i = 2; i <= n; i++) {
    bool flag = 0;
    for (int j = 1; j <= ans; j++)
      if ((b[j].second == a[i].c && a[i].s >= b[j].first) ||
          (b[j].second != a[i].c && a[i].s > b[j].first)) {
        b[j].first = a[i].t, b[j].second = a[i].c;
        flag = 1;
        break;
      }
    if (!flag)
      ans++, b[ans].first = a[i].t, b[ans].second = a[i].c;
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define mem(a, n) memset(a, n, sizeof(a))
#define pb(x) push_back(x)
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;
struct node {
  int s, t, c;
} a[N];

bool cmp(node a, node b) { return a.s < b.s; }

pair<int, int> b[N];
int main() {
  ios::sync_with_stdio(false);
  int n, c, ans = 1;
  cin >> n >> c;
  for (int i = 1; i <= n; i++)
    cin >> a[i].s >> a[i].t >> a[i].c;
  sort(a + 1, a + n + 1, cmp);
  b[1].first = a[1].t, b[1].second = a[1].c;
  for (int i = 2; i <= n; i++) {
    bool flag = 0;
    for (int j = 1; j <= ans; j++)
      if ((b[j].second == a[i].c && a[i].s >= b[j].first) ||
          (b[j].second != a[i].c && a[i].s > b[j].first)) {
        b[j].first = a[i].t, b[j].second = a[i].c;
        flag = 1;
        break;
      }
    if (!flag)
      ans++, b[ans].first = a[i].t, b[ans].second = a[i].c;
  }
  cout << ans;
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstdio>
#include <ctime>
#include <deque>
#include <exception>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

const int maxn = 1e+5 + 5;
int f[30][maxn];

void solve() {
  int n, C;
  cin >> n >> C;
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    for (int k = s; k <= t; k++) {
      f[c][k] = 1;
    }
  }

  int res = 0;
  for (int i = 0; i < maxn; i++) {
    int temp = 0;
    for (int k = 0; k < 30; k++) {
      temp += f[k][i];
    }
    res = max(temp, res);
  }
  cout << res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  // freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
  // freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cstdio>
#include <ctime>
#include <deque>
#include <exception>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

const int maxn = 1e+5 + 5;
int f[30][maxn];

void solve() {
  int n, C;
  cin >> n >> C;
  for (int i = 0; i < n; i++) {
    int s, t, c;
    cin >> s >> t >> c;
    s--, t--, c--;
    for (int k = s; k <= t; k++) {
      f[c][k] = 1;
    }
  }

  int res = 0;
  for (int i = 0; i < maxn; i++) {
    int temp = 0;
    for (int k = 0; k < 30; k++) {
      temp += f[k][i];
    }
    res = max(temp, res);
  }
  cout << res;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  // freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
  // freopen("file.in", "r", stdin);freopen("file.out", "w", stdout);
  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
  }

  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

struct prog {
  int s, t, c;
};

bool operator<(prog a, prog b) { return (a.c < b.c ? a.c < b.c : (a.s < b.s)); }

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

  int N, C;
  cin >> N >> C;

  vector<prog> dat(N);
  for (int i = 0; i < N; ++i)
    cin >> dat[i].s >> dat[i].t >> dat[i].c;

  sort(dat.begin(), dat.end());
  vector<int> cnt(100005);
  for (int i = 0; i < N; ++i) {
    cnt[dat[i].s - 1]++;
    if (i + 1 < N && dat[i].c == dat[i + 1].c && dat[i].t == dat[i + 1].s) {
      cnt[dat[i + 1].s - 1]--;
      continue;
    }
    cnt[dat[i].t]--;
  }

  int ans = 0;
  for (int i = 0; i <= 100000; ++i) {
    cnt[i + 1] += cnt[i];
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

struct prog {
  int s, t, c;
};

bool operator<(prog a, prog b) { return (a.c == b.c ? a.s < b.s : a.c < b.c); }

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

  int N, C;
  cin >> N >> C;

  vector<prog> dat(N);
  for (int i = 0; i < N; ++i)
    cin >> dat[i].s >> dat[i].t >> dat[i].c;

  sort(dat.begin(), dat.end());
  vector<int> cnt(100005);
  for (int i = 0; i < N; ++i) {
    cnt[dat[i].s - 1]++;
    if (i + 1 < N && dat[i].c == dat[i + 1].c && dat[i].t == dat[i + 1].s) {
      cnt[dat[i + 1].s - 1]--;
      continue;
    }
    cnt[dat[i].t]--;
  }

  int ans = 0;
  for (int i = 0; i <= 100000; ++i) {
    cnt[i + 1] += cnt[i];
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;

  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 20005

int main() {

  int n, ch;
  cin >> n >> ch;
  vector<int> s(n), t(n), c(n);

  REP(i, n) { cin >> s[i] >> t[i] >> c[i]; }

  int imos[ARRAY_MAX];
  int ans[ARRAY_MAX];
  REP(i, ARRAY_MAX) { ans[i] = 0; }

  for (int i = 1; i <= ch; i++) {

    REP(j, ARRAY_MAX) { imos[j] = 0; }

    REP(j, n) {
      if (c[j] == i) {
        imos[s[j] * 2 - 1]++;
        imos[t[j] * 2 + 1]--;
      }
    }
    REP(j, ARRAY_MAX - 1) { imos[j + 1] += imos[j]; }
    // 累積和
    REP(j, ARRAY_MAX) {
      // チャンネルを使用中
      if (imos[j] > 0) {
        ans[j]++;
      }
    }
  }
  int maxi = -1;
  REP(i, ARRAY_MAX) { maxi = max(maxi, ans[i]); }

  cout << maxi << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

#define ARRAY_MAX 200005

int main() {

  int n, ch;
  cin >> n >> ch;
  vector<int> s(n), t(n), c(n);

  REP(i, n) { cin >> s[i] >> t[i] >> c[i]; }

  int imos[ARRAY_MAX];
  int ans[ARRAY_MAX];
  REP(i, ARRAY_MAX) { ans[i] = 0; }

  for (int i = 1; i <= ch; i++) {

    REP(j, ARRAY_MAX) { imos[j] = 0; }

    REP(j, n) {
      if (c[j] == i) {
        imos[s[j] * 2 - 1]++;
        imos[t[j] * 2 + 1]--;
      }
    }
    REP(j, ARRAY_MAX - 1) { imos[j + 1] += imos[j]; }
    // 累積和
    REP(j, ARRAY_MAX) {
      // チャンネルを使用中
      if (imos[j] > 0) {
        ans[j]++;
      }
    }
  }
  int maxi = -1;
  REP(i, ARRAY_MAX) { maxi = max(maxi, ans[i]); }

  cout << maxi << endl;

  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
  int n, c;
  cin >> n >> c;
  vector<vector<pair<int, int>>> range(c);
  vector<int> num_recording(200);
  for (int i = 0; i < n; ++i) {
    int s, t, channel;
    cin >> s >> t >> channel;
    range[channel - 1].push_back(make_pair(s, t));
  }

  for (int i = 0; i < c; ++i) {
    sort(range[i].begin(), range[i].end());
    range[i].push_back(make_pair(inf, inf));
    auto cur = range[i].front();
    for (int j = 1; j < range[i].size(); ++j) {
      if (range[i][j].first == cur.second) {
        cur.second = range[i][j].second;
      } else {
        ++num_recording[2 * cur.first - 1];
        --num_recording[2 * cur.second];
        cur = range[i][j];
      }
    }
  }

  int ans = num_recording.front();
  for (int i = 1; i < num_recording.size(); ++i) {
    num_recording[i] += num_recording[i - 1];
    ans = max(num_recording[i], ans);
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000007LL;
constexpr int inf = 1000000007;

int main() {
  int n, c;
  cin >> n >> c;
  vector<vector<pair<int, int>>> range(c);
  vector<int> num_recording(200001);
  for (int i = 0; i < n; ++i) {
    int s, t, channel;
    cin >> s >> t >> channel;
    range[channel - 1].push_back(make_pair(s, t));
  }

  for (int i = 0; i < c; ++i) {
    sort(range[i].begin(), range[i].end());
    range[i].push_back(make_pair(inf, inf));
    auto cur = range[i].front();
    for (int j = 1; j < range[i].size(); ++j) {
      if (range[i][j].first == cur.second) {
        cur.second = range[i][j].second;
      } else {
        ++num_recording[2 * cur.first - 1];
        --num_recording[2 * cur.second];
        cur = range[i][j];
      }
    }
  }

  int ans = num_recording.front();
  for (int i = 1; i < num_recording.size(); ++i) {
    num_recording[i] += num_recording[i - 1];
    ans = max(num_recording[i], ans);
  }
  cout << ans << endl;
  return 0;
}
Problem p03504 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define MAX_N 10010
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
int b[31][MAX_N];
int main() {
  int i;
  int j;
  int N;
  int C;
  int s;
  int t;
  int c;
  int iMax;
  int iCnt;
  ios::sync_with_stdio(false);

  cin >> N;
  cin >> C;
  for (i = 1; i <= N; i++) {
    cin >> s;
    cin >> t;
    cin >> c;
    for (j = s - 1; j < t; j++)
      b[c][j] = true;
  }

  iMax = 0;
  for (j = 1; j <= MAX_N; j++) {
    iCnt = 0;
    for (i = 1; i <= C; i++) {
      if (b[i][j])
        iCnt++;
    }

    if (iMax < iCnt)
      iMax = iCnt;
  }

  cout << iMax << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#define MAX_N 100010
#define mem(a, b) memset(a, b, sizeof(a))
using namespace std;
int b[31][MAX_N];
int main() {
  int i;
  int j;
  int N;
  int C;
  int s;
  int t;
  int c;
  int iMax;
  int iCnt;
  ios::sync_with_stdio(false);

  cin >> N;
  cin >> C;
  for (i = 1; i <= N; i++) {
    cin >> s;
    cin >> t;
    cin >> c;
    for (j = s - 1; j < t; j++)
      b[c][j] = true;
  }

  iMax = 0;
  for (j = 1; j <= MAX_N; j++) {
    iCnt = 0;
    for (i = 1; i <= C; i++) {
      if (b[i][j])
        iCnt++;
    }

    if (iMax < iCnt)
      iMax = iCnt;
  }

  cout << iMax << endl;

  return 0;
}
Problem p03504 (C++)

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

using namespace std;

typedef long long ll;

const int T = 12;

int main() {
  int n, c;
  cin >> n >> c;
  int used[c + 1][T + 1];
  for (int i = 0; i <= c; i++) {
    for (int j = 0; j <= T; j++) {
      used[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int s, t, cc;
    cin >> s >> t >> cc;
    for (int ss = s - 1; ss < t; ss++) {
      used[cc][ss] = 1;
    }
  }
  /*for(int i=1;i<=c;i++){
    for(int j=1;j<=T;j++){
      cout << used[i][j] << " ";
    }
    cout << endl;
  }*/
  int ans = 0;
  for (int i = 1; i <= T; i++) {
    int used_sum = 0;
    for (int j = 1; j <= c; j++)
      used_sum = used_sum + used[j][i];
    ans = max(ans, used_sum);
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

const int T = 100000;

int main() {
  int n, c;
  cin >> n >> c;
  int used[c + 1][T + 1];
  for (int i = 0; i <= c; i++) {
    for (int j = 0; j <= T; j++) {
      used[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++) {
    int s, t, cc;
    cin >> s >> t >> cc;
    for (int ss = s - 1; ss < t; ss++) {
      used[cc][ss] = 1;
    }
  }
  /*for(int i=1;i<=c;i++){
    for(int j=1;j<=T;j++){
      cout << used[i][j] << " ";
    }
    cout << endl;
  }*/
  int ans = 0;
  for (int i = 1; i <= T; i++) {
    int used_sum = 0;
    for (int j = 1; j <= c; j++)
      used_sum = used_sum + used[j][i];
    ans = max(ans, used_sum);
  }
  cout << ans << endl;
}
Problem p03505 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
typedef long long LL;
using namespace std;
int main(int argc, char *argv[]) {
  LL K, A, B;
  cin >> K >> A >> B;
  if (K <= A) {
    cout << 1 << endl;
    return 0;
  }
  if (A < B) {
    cout << -1 << endl;
    return 0;
  }
  LL AB = A - B;
  LL x = (K - A) / AB;
  LL y = K % AB;
  LL z = x * AB;
  LL aw = 2 * x;
  while (z < K) {
    aw++;
    z += A;
    if (z >= K) {
      break;
    }
    z -= B;
    aw++;
  }
  cout << aw << endl;
  return 0;
}

Fixed submission:
#include <iostream>
typedef long long LL;
using namespace std;
int main(int argc, char *argv[]) {
  LL K, A, B;
  cin >> K >> A >> B;
  if (K <= A) {
    cout << 1 << endl;
    return 0;
  }
  if (A <= B) {
    cout << -1 << endl;
    return 0;
  }
  LL AB = A - B;
  LL x = (K - A) / AB;
  LL y = K % AB;
  LL z = x * AB;
  LL aw = 2 * x;
  while (z < K) {
    aw++;
    z += A;
    if (z >= K) {
      break;
    }
    z -= B;
    aw++;
  }
  cout << aw << endl;
  return 0;
}
Problem p03505 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K, A, B;
  cin >> K >> A >> B;
  if (A <= B && A < K) {
    cout << -1 << endl;
    return 0;
  }
  ll diff = max(K - A, 0LL);
  cout << ((diff + A - B - 1) / (A - B)) * 2 + 1 << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
#include <vector>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll K, A, B;
  cin >> K >> A >> B;
  if (A <= B) {
    if (A >= K) {
      cout << 1 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  ll diff = max(K - A, 0LL);
  cout << ((diff + A - B - 1) / (A - B)) * 2 + 1 << endl;
  return 0;
}
Problem p03505 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
long long a, b, sum, k;
int main() {
  cin >> k >> a >> b;
  if (a >= k) {
    cout << 1 << endl;
    return 0;
  }
  if (b > a)
    return cout << -1 << endl, 0;
  if ((k - a) % (a - b) >= 1)
    sum = 1;
  cout << ((k - a) / (a - b) + sum) * 2 + 1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long a, b, sum, k;
int main() {
  cin >> k >> a >> b;
  if (a >= k) {
    cout << 1 << endl;
    return 0;
  }
  if (b >= a)
    return cout << -1 << endl, 0;
  if ((k - a) % (a - b) >= 1)
    sum = 1;
  cout << ((k - a) / (a - b) + sum) * 2 + 1 << endl;
  return 0;
}
Problem p03505 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  ll po = k - a;
  ll yo = po / (a - b) + (po % (a - b) != 0);
  cout << yo * 2 + 1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  ll po = k - a;
  if (po <= 0) {
    cout << 1 << endl;
  } else if (b - a >= 0) {
    cout << -1 << endl;
  } else {
    ll yo = po / (a - b) + (po % (a - b) != 0);
    cout << yo * 2 + 1 << endl;
  }
  return 0;
}
Problem p03505 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  long long n, K, A, B;
  scanf("%lld %lld %lld", &K, &A, &B);
  n = (K - B) / (A - B);
  if (n > 0) {
    while (n * A - (n - 1) * B < K)
      n++;
    printf("%lld\n", n * 2 - 1);
  } else
    printf("-1\n");
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  long long n, K, A, B;
  scanf("%lld %lld %lld", &K, &A, &B);
  if (K <= A)
    n = 1;
  else if (A <= B)
    n = -1;
  else
    n = (K - B) / (A - B);
  if (n > 0) {
    while (n * A - (n - 1) * B < K)
      n++;
    printf("%lld\n", n * 2 - 1);
  } else
    printf("-1\n");
  return 0;
}