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

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

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) max((a), -(a))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main() {
  while (1) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(all(a));
    int ans = 1000000000;
    for (int i = 0; i < n - 1; i++) {
      ans = min(ans, a[i + 1] - a[i]);
    }
    cout << ans << endl;
  }
  return 0;
}


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

#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) max((a), -(a))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main() {
  while (1) {
    int n;
    cin >> n;
    if (n == 0)
      return 0;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(all(a));
    int ans = 1000000000;
    for (int i = 0; i < n - 1; i++) {
      ans = min(ans, a[i + 1] - a[i]);
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p01094 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;

using Cand = tuple<int, int>;

int get_name(const Cand &c) { return get<0>(c); }
int get_point(const Cand &c) { return get<1>(c); }

tuple<Cand, Cand> get_top_two_cands(const vector<int> &point) {
  Cand top = make_tuple(-1, -1), second = make_tuple(-1, -1);
  REP(j, 26) {
    if (point[j] > get_point(top)) {
      second = top;
      top = make_tuple(j, point[j]);
    } else if (point[j] > get_point(second)) {
      second = make_tuple(j, point[j]);
    }
  }
  return make_tuple(top, second);
}

int main() {
  int N;
  while (cin >> N && N) {
    vector<char> C(26);
    REP(i, N) { cin >> C[i]; }

    vector<int> point(26, 0);
    int votes = 0;
    Cand top = make_tuple(0, 0), second = make_tuple(0, 0);
    for (; votes < N && (N - votes) >= (get_point(top) - get_point(second));
         ++votes, tie(top, second) = get_top_two_cands(point)) {
      ++point[C[votes] - 'A'];
    }
    if (get_point(top) > get_point(second)) {
      char name = 'A' + get_name(top);
      cout << name << " " << votes << endl;
    } else {
      cout << "TIE" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;

using Cand = tuple<int, int>;

int get_name(const Cand &c) { return get<0>(c); }
int get_point(const Cand &c) { return get<1>(c); }

tuple<Cand, Cand> get_top_two_cands(const vector<int> &point) {
  Cand top = make_tuple(-1, -1), second = make_tuple(-1, -1);
  REP(j, 26) {
    if (point[j] > get_point(top)) {
      second = top;
      top = make_tuple(j, point[j]);
    } else if (point[j] > get_point(second)) {
      second = make_tuple(j, point[j]);
    }
  }
  return make_tuple(top, second);
}

int main() {
  int N;
  while (cin >> N && N) {
    vector<char> C(N);
    REP(i, N) { cin >> C[i]; }

    vector<int> point(26, 0);
    int votes = 0;
    Cand top = make_tuple(0, 0), second = make_tuple(0, 0);
    for (; votes < N && (N - votes) >= (get_point(top) - get_point(second));
         ++votes, tie(top, second) = get_top_two_cands(point)) {
      ++point[C[votes] - 'A'];
    }
    if (get_point(top) > get_point(second)) {
      char name = 'A' + get_name(top);
      cout << name << " " << votes << endl;
    } else {
      cout << "TIE" << endl;
    }
  }
  return 0;
}
Problem p01094 (C++)

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    int c[n];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }

    int can[26] = {0}; //????£????(candidate)????\¨??°

    for (int i = 0; i < n; i++) {
      can[(int)(c[i] - 'A')]++;

      int max1 = -1; //??????
      int max2 = -1; //??????

      // A~Z???????\¨??°???????????????
      for (int j = 0; j < 26; j++) {
        if (can[j] > max1) {
          max2 = max1;
          max1 = can[j];
        } else if (can[j] > max2) {
          max2 = can[j];
        }
      }

      //????????????????????????????\¨??°???????????????
      if (max1 - max2 > n - (i + 1)) {
        for (int j = 0; j < 26; j++) {
          if (can[j] == max1) {
            cout << (char)(j + 'A') << ' ';
            break;
          }
        }
        cout << (i + 1) << endl;
        break;
      }

      //???????????§????\¨????????´???
      if (i == n - 1) {
        cout << "TIE" << endl;
        break;
      }
    }
  }

  return 0;
}

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    char c[n];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }

    int can[26] = {0}; //????£????(candidate)????\¨??°

    for (int i = 0; i < n; i++) {
      can[(int)(c[i] - 'A')]++;

      int max1 = -1; //??????
      int max2 = -1; //??????

      // A~Z???????\¨??°???????????????
      for (int j = 0; j < 26; j++) {
        if (can[j] > max1) {
          max2 = max1;
          max1 = can[j];
        } else if (can[j] > max2) {
          max2 = can[j];
        }
      }

      //????????????????????????????\¨??°???????????????
      if (max1 - max2 > n - (i + 1)) {
        for (int j = 0; j < 26; j++) {
          if (can[j] == max1) {
            cout << (char)(j + 'A') << ' ';
            break;
          }
        }
        cout << (i + 1) << endl;
        break;
      }

      //???????????§????\¨????????´???
      if (i == n - 1) {
        cout << "TIE" << endl;
        break;
      }
    }
  }

  return 0;
}
Problem p01094 (C++)

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

int main() {
  while (1) {
    int n;
    cin >> n;

    char c[100];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }

    int cnt[26] = {0};

    for (int i = 0; i < n; i++) {
      cnt[(int)(c[i] - 'A')]++;

      int max1 = -1;
      int max2 = -1;

      for (int j = 0; j < 26; j++) {
        if (cnt[j] > max1) {
          max2 = max1;
          max1 = cnt[j];
        } else if (cnt[j] > max2) {
          max2 = cnt[j];
        }
      }

      if (max1 - max2 > n - (i + 1)) {
        for (int j = 0; j < 26; j++) {
          if (cnt[j] == max1) {
            cout << (char)(j + 'A') << " ";
            break;
          }
        }
        cout << (i + 1) << endl;
        break;
      }

      if (i == (n - 1)) {
        cout << "TIE" << endl;
        break;
      }
    }
  }

  return 0;
}

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

int main() {
  while (1) {
    int n;
    cin >> n;

    if (n == 0)
      break;

    char c[100];
    for (int i = 0; i < n; i++) {
      cin >> c[i];
    }

    int cnt[26] = {0};

    for (int i = 0; i < n; i++) {
      cnt[(int)(c[i] - 'A')]++;

      int max1 = -1;
      int max2 = -1;

      for (int j = 0; j < 26; j++) {
        if (cnt[j] > max1) {
          max2 = max1;
          max1 = cnt[j];
        } else if (cnt[j] > max2) {
          max2 = cnt[j];
        }
      }

      if (max1 - max2 > n - (i + 1)) {
        for (int j = 0; j < 26; j++) {
          if (cnt[j] == max1) {
            cout << (char)(j + 'A') << " ";
            break;
          }
        }
        cout << (i + 1) << endl;
        break;
      }

      if (i == (n - 1)) {
        cout << "TIE" << endl;
        break;
      }
    }
  }

  return 0;
}
Problem p01095 (C++)

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

#define MAX 7368791

int main(void) {
  int m, n;
  int year[MAX];

  while (1) {
    scanf("%d %d", &m, &n);
    if (m == 0 && n == 0)
      break;

    for (int i = 0; i < MAX; i++)
      year[i] = false;

    int seed = 0;
    for (int i = m; i <= MAX; i++) {
      if (!year[i - 1]) {
        if (seed < n) {
          for (int j = i; j <= MAX; j += i)
            year[j - 1] = true;
          seed++;
        } else {
          seed = i;
          break;
        }
      }
    }

    printf("%d\n", seed);
  }

  return 0;
}


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

#define MAX 7368791

int main(void) {
  int m, n;
  bool year[MAX];

  while (1) {
    scanf("%d %d", &m, &n);
    if (m == 0 && n == 0)
      break;

    for (int i = 0; i < MAX; i++)
      year[i] = false;

    int seed = 0;
    for (int i = m; i <= MAX; i++) {
      if (!year[i - 1]) {
        if (seed < n) {
          for (int j = i; j <= MAX; j += i)
            year[j - 1] = true;
          seed++;
        } else {
          seed = i;
          break;
        }
      }
    }

    printf("%d\n", seed);
  }

  return 0;
}
Problem p01095 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define INT_MAX 2147483647
bool f[INT_MAX];

void del_flag(int m) {
  int tmp = m;
  while (tmp < INT_MAX) {
    f[tmp] = false;
    tmp += m;
  }
}

int main() {
  int m, n;
  while (cin >> m >> n, n) {
    for (int i = 0; i < INT_MAX; ++i) {
      f[i] = true;
    }
    int tmp = m;
    for (int i = 0; i < n; ++i) {
      while (!f[tmp])
        ++tmp;
      del_flag(tmp);
    }
    while (!f[tmp])
      ++tmp;
    cout << tmp << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <float.h>
#include <functional>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

void A();
void B();
#define INT_MAX 7368793
bool f[INT_MAX];

void del_flag(int m) {
  int tmp = m;
  while (tmp < INT_MAX) {
    f[tmp] = false;
    tmp += m;
  }
}

int main() {
  int m, n;
  while (cin >> m >> n, n) {
    for (int i = 0; i < INT_MAX; ++i) {
      f[i] = true;
    }
    int tmp = m;
    for (int i = 0; i < n; ++i) {
      while (!f[tmp])
        ++tmp;
      del_flag(tmp);
    }
    while (!f[tmp])
      ++tmp;
    cout << tmp << endl;
  }
  return 0;
}
Problem p01095 (C++)

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
  int n, m;
  while (scanf("%d %d", &m, &n) != EOF) {
    if (n == 0 && m == 0)
      break;
    const int Max = 8e6;
    // set<int> st;
    // REP(i, m , Max) st.insert(i);
    // rep(i, n) {
    // 	int t = *st.begin();
    // 	for(int j = t; j < Max; j += t) {
    // 		if(st.count(j)) st.erase(j);
    // 	}
    // }
    // cout << *st.begin() << endl;
    vi v(Max, 0);
    int cnt = 0;
    REP(i, m, Max) {
      if (v[i])
        continue;
      if (cnt == n) {
        printf("%d\n", i);
        break;
      }
      cnt++;
      for (int j = i; j < Max; j += i)
        v[j] = 1;
    }
  }
}

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define pb push_back
#define all(r) (r).begin(), (r).end()
#define rall(r) (r).rbegin(), (r).rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main() {
  int n, m;
  while (scanf("%d %d", &m, &n) != EOF) {
    if (n == 0 && m == 0)
      break;
    const int Max = 7368791 + 10;
    // set<int> st;
    // REP(i, m , Max) st.insert(i);
    // rep(i, n) {
    // 	int t = *st.begin();
    // 	for(int j = t; j < Max; j += t) {
    // 		if(st.count(j)) st.erase(j);
    // 	}
    // }
    // cout << *st.begin() << endl;
    vi v(Max, 0);
    int cnt = 0;
    REP(i, m, Max) {
      if (v[i])
        continue;
      if (cnt == n) {
        printf("%d\n", i);
        break;
      }
      cnt++;
      for (int j = i; j < Max; j += i)
        v[j] = 1;
    }
  }
}
Problem p01095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
bool ok[7368792];
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n), m) {
    memset(ok, 0, sizeof(ok));
    int cnt = 0;
    for (int i = m;; i++) {
      if (!ok[i])
        continue;
      if (++cnt > n) {
        printf("%d\n", i);
        break;
      }
      for (int j = i; j <= 7368791; j += i)
        ok[j] = true;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
bool ok[7368792];
int main() {
  int m, n;
  while (scanf("%d%d", &m, &n), m) {
    memset(ok, 0, sizeof(ok));
    int cnt = 0;
    for (int i = m;; i++) {
      if (ok[i])
        continue;
      if (++cnt > n) {
        printf("%d\n", i);
        break;
      }
      for (int j = i; j <= 7368791; j += i)
        ok[j] = true;
    }
  }
}
Problem p01095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int MAX = 736891;
int main() {
  int n, m;
  bool f[MAX + 1];
  while (1) {
    cin >> m >> n;
    if (m + n == 0)
      break;
    REP(i, MAX + 1) f[i] = false;
    for (int i = m;; i++) {
      if (!f[i]) {
        if (n == 0) {
          cout << i << endl;
          break;
        } else {
          n--;
          for (int j = i; j <= MAX; j += i) {
            f[j] = true;
          }
        }
      }
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int MAX = 7368791;
int main() {
  int n, m;
  bool f[MAX + 1];
  while (1) {
    cin >> m >> n;
    if (m + n == 0)
      break;
    REP(i, MAX + 1) f[i] = false;
    for (int i = m;; i++) {
      if (!f[i]) {
        if (n == 0) {
          cout << i << endl;
          break;
        } else {
          n--;
          for (int j = i; j <= MAX; j += i) {
            f[j] = true;
          }
        }
      }
    }
  }
}
Problem p01095 (C++)

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

int prime[N] = {0};
int n, m, now = 0;

int sprime() {
  int i, j;
  for (i = n; i < N; ++i)
    if (prime[i] == 0) {
      if (now == m)
        return i;
      ++now;
      for (j = 1; i * j < N; ++j)
        prime[i * j] = 1;
    }
  return 0;
}

int main() {
  while (1) {
    memset(prime, 0, sizeof(prime));
    cin >> n >> m;
    now = 0;
    if (n + m == 0)
      break;
    cout << sprime() << endl;
  }
  return 0;
}


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

int prime[N] = {0};
int n, m, now = 0;

int sprime() {
  int i, j;
  for (i = n; i < N; ++i)
    if (prime[i] == 0) {
      if (now == m)
        return i;
      ++now;
      for (j = 1; i * j < min(N, m * 1000); ++j)
        prime[i * j] = 1;
    }
  return 0;
}

int main() {
  while (1) {
    memset(prime, 0, sizeof(prime));
    cin >> n >> m;
    now = 0;
    if (n + m == 0)
      break;
    cout << sprime() << endl;
  }
  return 0;
}
Problem p01095 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
bool a[7368800];
int main() {
  int m = 3, n = 1;
  while (/*cin >>m>> n&&*/ n != 0 && m != 0) {
    int sum = m, n2 = n;
    fill(a, a + 7368800, false);
    while (n2 != 0 || a[sum]) {
      if (!a[sum]) {
        a[sum] = true;
        int j = 2;
        while (sum * j < 7368800) {
          a[sum * j] = true;
          j++;
        }
        n2--;
      }
      sum++;
    }
    cout << sum << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
bool a[7368800];
int main() {
  int m = 3, n = 1;
  while (cin >> m >> n && n != 0 && m != 0) {
    int sum = m, n2 = n;
    fill(a, a + 7368800, false);
    while (n2 != 0 || a[sum]) {
      if (!a[sum]) {
        a[sum] = true;
        int j = 2;
        while (sum * j < 7368800) {
          a[sum * j] = true;
          j++;
        }
        n2--;
      }
      sum++;
    }
    cout << sum << endl;
  }
}
Problem p01095 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef pair<int, P> PP;

bool memo[8000000];
int m, n;

void furui(int n, int count) {
  fill(memo, memo + 8000000, true);

  int cnt = 0;
  for (int i = m; i <= m + n; i++) {
    if (memo[i - m]) {
      memo[i - m] = false;
      for (int j = 2 * i; j <= n; j += i) {
        memo[j - m] = false;
      }
      cnt++;
      break;
      if (cnt == count)
        return;
    }
  }
  return;
}

int main() {
  while (cin >> m >> n) {
    if (m == 0 && n == 0)
      return 0;
    fill(memo, memo + 8000000, true);

    int l = m;
    for (int k = 0; k < n; k++) {
      for (int i = l; i <= 8000000; i++) {
        if (memo[i - m]) {
          l = i;
          memo[i - m] = false;
          for (int j = ((m - i + 1) / i) * i; j <= 8000000; j += i) {
            memo[j - m] = false;
          }
          break;
        }
      }
      /*
      for(int i=m;i<=13;i++){
              cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
      }
      cout<<endl;
      */
    }
    for (int i = 0; i <= 8000000; i++) {
      if (memo[i]) {
        cout << i + m << endl;
        break;
      }
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef pair<int, P> PP;

bool memo[8000000];
int m, n;

void furui(int n, int count) {
  fill(memo, memo + 8000000, true);

  int cnt = 0;
  for (int i = m; i <= m + n; i++) {
    if (memo[i - m]) {
      memo[i - m] = false;
      for (int j = 2 * i; j <= n; j += i) {
        memo[j - m] = false;
      }
      cnt++;
      break;
      if (cnt == count)
        return;
    }
  }
  return;
}

int main() {
  while (cin >> m >> n) {
    if (m == 0 && n == 0)
      return 0;
    fill(memo, memo + 8000000, true);

    int l = m;
    for (int k = 0; k < n; k++) {
      for (int i = l; i <= 8000000; i++) {
        if (memo[i - m]) {
          l = i;
          memo[i - m] = false;
          for (int j = ((m + i - 1) / i) * i; j <= 8000000; j += i) {
            memo[j - m] = false;
          }
          break;
        }
      }
      /*
      for(int i=m;i<=13;i++){
              cout<<i<<" memo[i-m]:"<<memo[i-m]<<" ";
      }
      cout<<endl;
      */
    }
    for (int i = 0; i <= 8000000; i++) {
      if (memo[i]) {
        cout << i + m << endl;
        break;
      }
    }
  }

  return 0;
}
Problem p01095 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long int a[10000000] = {};
int main() {
  const long long int mod = 1000000007;
  map<long long int, long long int> mp;
  // cout << fixed << setprecision(10);
  long long int n, m, b, c, d, k, sa, h, w, left = 1, right = 0;
  long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0,
                              now = 0, mi = 9999999999;

  string str, t;

  cin >> m >> n;
  while (1) {
    res = 0;
    count = n;
    now = m;
    if (m == 0 && n == 0) {
      return 0;
    }
    while (1) {
      if (count == 0 && a[now] == 0) {
        cout << now << endl;
        for (int i = 2; i < 7500000; i++) {
          a[i] = 0;
        }
        break;
      }
      if (a[now] == 0) {
        for (int i = 2; i * now < 7500000; i++) {
          a[i * now] = 1;
        }
        count--;
      }
      now++;
    }
    cin >> m >> n;
  }
}


Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int a[10000000] = {};
int main() {
  const long long int mod = 1000000007;
  map<long long int, long long int> mp;
  // cout << fixed << setprecision(10);
  long long int n, m, b, c, d, k, sa, h, w, left = 1, right = 0;
  long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0,
                              now = 0, mi = 9999999999;

  string str, t;

  cin >> m >> n;
  while (1) {
    res = 0;
    count = n;
    now = m;
    if (m == 0 && n == 0) {
      return 0;
    }
    while (1) {
      if (count == 0 && a[now] == 0) {
        cout << now << endl;
        for (int i = 2; i < 7500000; i++) {
          a[i] = 0;
        }
        break;
      }
      if (a[now] == 0) {
        for (int i = 2; i * now < 7500000; i++) {
          a[i * now] = 1;
        }
        count--;
      }
      now++;
    }
    cin >> m >> n;
  }
}
Problem p01095 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  while (cin >> m >> n, m) {
    bool s[7654321] = {};
    int i = m, j = 0, k;
    for (; j <= n; i++)
      if (!s[i] && j != n)
        for (k = 2, j++; i * k < 7654321; k++)
          s[i * k] = 1;
    cout << i - 1 << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int m, n;
  while (cin >> m >> n, m) {
    bool s[7654321] = {};
    int i = m, j = 0, k;
    for (; j <= n; i++)
      if (!s[i])
        for (k = 2, j++; i * k < 7654321; k++)
          s[i * k] = 1;
    cout << i - 1 << endl;
  }
  return 0;
}
Problem p01095 (C++)

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

using namespace std;

const int MAX_N = 1e7;
int primes[MAX_N + 1]; // i????´???°??????true

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

  while (true) {
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    for (int i = 0; i < MAX_N; i++)
      primes[i] = true;
    int count = 0;
    primes[0] = primes[1] = false;
    for (int i = m; i <= MAX_N; i++) {
      if (primes[i]) {
        for (int j = 2 * i; j <= MAX_N; j += i)
          primes[j] = false;
        count++;
        if (count > n) {
          cout << i << endl;
          break;
        }
      }
    }
  }
}

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

using namespace std;

const int MAX_N = 7.4 * 1e6;
int primes[MAX_N + 1]; // i????´???°??????true

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

  while (true) {
    int m, n;
    cin >> m >> n;
    if (m == 0 && n == 0)
      break;
    for (int i = 0; i < MAX_N; i++)
      primes[i] = true;
    int count = 0;
    primes[0] = primes[1] = false;
    for (int i = m; i <= MAX_N; i++) {
      if (primes[i]) {
        for (int j = 2 * i; j <= MAX_N; j += i)
          primes[j] = false;
        count++;
        if (count > n) {
          cout << i << endl;
          break;
        }
      }
    }
  }
}
Problem p01095 (C++)

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

using namespace std;

bool e[7368792];

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m + n == 0) {
      break;
    }

    memset(e, false, sizeof(e));
    int count = 0;
    for (int i = m; count < n; i++) {
      if (!e[i]) {
        count++;
      }
      for (int j = 1; i * j < 7368792; j++) {
        e[i * j] = true;
      }
    }

    for (int i = m + 1;; i++) {
      if (!e[i]) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}

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

using namespace std;

bool e[7368792];

int main() {
  while (true) {
    int m, n;
    cin >> m >> n;
    if (m + n == 0) {
      break;
    }

    memset(e, false, sizeof(e));
    int count = 0;
    for (int i = m; count < n; i++) {
      if (!e[i]) {
        count++;
      } else {
        continue;
      }
      for (int j = 1; i * j < 7368792; j++) {
        e[i * j] = true;
      }
    }

    for (int i = m + 1;; i++) {
      if (!e[i]) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}
Problem p01095 (C++)

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

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    vector<int> goodyear(7368792, 0);
    int cnt = 0;
    int res = -1;
    for (int i = m;; i++) {
      if (goodyear[i] == 0) {
        if (cnt == n) {
          res = i;
          break;
        } else {
          cnt++;
          for (int j = i; j < 1e7; j += i) {
            goodyear[j] = 1;
          }
        }
      }
    }
    cout << res << endl;
  }
}

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

int main() {
  int m, n;
  while (cin >> m >> n, m) {
    vector<int> goodyear(7368792, 0);
    int cnt = 0;
    int res = -1;
    for (int i = m;; i++) {
      if (goodyear[i] == 0) {
        if (cnt == n) {
          res = i;
          break;
        } else {
          cnt++;
          for (int j = i; j < 7368792; j += i) {
            goodyear[j] = 1;
          }
        }
      }
    }
    cout << res << endl;
  }
}
Problem p01095 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>

#define MAX (7368791 + 1)

using namespace std;

bool a[MAX];

int main(void) {
  int m, n;
  while (cin >> m >> n, m || n) {
    fill(a, a + MAX, true);
    int count = 0;
    for (int i = m; i < MAX; i++) {
      if (a[i] == true) {
        if (count == n) {
          cout << i << endl;
          break;
        }
        count++;
        for (int j = i + i; j < MAX; j += i) {
          a[j] = false;
        }
      }
    }
  }
  while (1)
    ;
  return 0;
}


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

#define MAX (7368791 + 1)

using namespace std;

bool a[MAX];

int main(void) {
  int m, n;
  while (cin >> m >> n, m || n) {
    fill(a, a + MAX, true);
    int count = 0;
    for (int i = m; i < MAX; i++) {
      if (a[i] == true) {
        if (count == n) {
          cout << i << endl;
          break;
        }
        count++;
        for (int j = i + i; j < MAX; j += i) {
          a[j] = false;
        }
      }
    }
  }
  return 0;
}
Problem p01096 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;

int n;
vector<int> w;
int dp[310][310];

int calc(int l, int r) {
  if (dp[l][r] != -1)
    return dp[l][r];
  if (l + 1 >= r)
    return dp[l][r] = 0;
  int res = 0;
  rep(i, l, r - 1) {
    rep(j, i + 1, r) {
      int tmp = 0;
      tmp += calc(l, i) + calc(i + 1, j) + calc(j + 1, r);
      int cent = calc(i + 1, j);
      int len = j - i - 1;
      if (abs(w[i] - w[j]) <= 1 && len == cent * 2)
        tmp++;
      res = max(res, tmp);
    }
  }
  return dp[l][r] = res;
}

int main() {
  while (cin >> n, n) {
    w.clear();
    w.resize(n);
    rep(i, 0, n) cin >> w[i];
    rep(i, 0, n + 1) rep(j, 0, n + 1) dp[i][j] = -1;
    int ans = calc(0, n);
    cout << ans * 2 << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
using namespace std;

int n;
vector<int> w;
int dp[310][310];

int calc(int l, int r) {
  if (dp[l][r] != -1)
    return dp[l][r];
  if (l + 1 >= r)
    return dp[l][r] = 0;
  int res = 0;
  rep(i, l, r) {
    int tmp = 0;
    int cent = calc(l + 1, i);
    int len = i - l - 1;
    if (abs(w[l] - w[i]) <= 1 && len == cent * 2)
      tmp++;
    tmp += cent + calc(i + 1, r);
    res = max(res, tmp);
  }
  return dp[l][r] = res;
}

int main() {
  while (cin >> n, n) {
    w.clear();
    w.resize(n);
    rep(i, 0, n) cin >> w[i];
    rep(i, 0, n + 1) rep(j, 0, n + 1) dp[i][j] = -1;
    int ans = calc(0, n);
    cout << ans * 2 << endl;
  }
}
Problem p01096 (C++)

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a <= x && x < b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
// #define int ll

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

int w[305], dp[305][305];
signed main(void) {
  while (true) {
    int n;
    cin >> n;
    if (!n)
      break;
    REP(i, n) cin >> w[i];
    REP(i, 305) REP(j, 305) dp[i][j] = 0;

    FOR(W, 2, n + 1) {
      REP(i, n) {
        int j = i + W - 1;
        // cout << i << " " << j << endl;

        if (dp[i + 1][j - 1] == W - 2 && abs(w[i] - w[j]) <= 1)
          dp[i][j] = W;
        FOR(k, i, j) {
          dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]);
          // cout << dp[i][j] << endl;
        }
      }
    }
    /*REP(i, n) {
            cout << i << ":";
            REP(j, n) {
                    cout << dp[i][j] << " ";
            }
            cout << endl;
    }*/
    cout << dp[0][n - 1] << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a <= x && x < b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
// #define int ll

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

int w[305], dp[305][305];
signed main(void) {
  while (true) {
    int n;
    cin >> n;
    if (!n)
      break;
    REP(i, n) cin >> w[i];
    REP(i, 305) REP(j, 305) dp[i][j] = 0;

    FOR(W, 2, n + 1) {
      REP(i, n) {
        int j = i + W - 1;
        if (j >= n)
          continue;
        // cout << i << " " << j << endl;

        if (dp[i + 1][j - 1] == W - 2 && abs(w[i] - w[j]) <= 1)
          dp[i][j] = W;
        FOR(k, i, j) {
          dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]);
          // cout << dp[i][j] << endl;
        }
      }
    }
    /*REP(i, n) {
            cout << i << ":";
            REP(j, n) {
                    cout << dp[i][j] << " ";
            }
            cout << endl;
    }*/
    cout << dp[0][n - 1] << endl;
  }

  return 0;
}
Problem p01096 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
using namespace std;
int dx[5] = {1, 0, -1, 0, 0}, dy[5] = {0, 1, 0, -1, 0};
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
#define INF 2000000000
#define MOD 1000000007
#define sym cout << "---------" << endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int, int>

int dp[305][305];

signed main() {
  int n;
  while (cin >> n && n) {
    int w[305];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++)
      cin >> w[i];

    for (int W = 2; W <= n; W++) {
      for (int l = 0; l < n; l++) {
        int r = l + W;

        if (dp[l + 1][r - 1] == W - 2 && abs(w[l] - w[r - 1]) <= 1)
          dp[l][r] = W;

        for (int mid = l; mid <= r; mid++) {
          dp[l][r] = max(dp[l][r], dp[l][mid] + dp[mid][r]);
        }
      }
    }
    cout << dp[0][n] << en;
  }
}


Fixed submission:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
using namespace std;
int dx[5] = {1, 0, -1, 0, 0}, dy[5] = {0, 1, 0, -1, 0};
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  } else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  if (a == 0) {
    return b;
  }
  return a / gcd(a, b) * b;
}
#define INF 2000000000
#define MOD 1000000007
#define sym cout << "---------" << endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int, int>

int dp[305][305];

signed main() {
  int n;
  while (cin >> n && n) {
    int w[305];
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < n; i++)
      cin >> w[i];

    for (int W = 2; W <= n; W++) {
      for (int l = 0; l < n; l++) {
        int r = l + W;
        if (r > n)
          continue;

        if (dp[l + 1][r - 1] == W - 2 && abs(w[l] - w[r - 1]) <= 1)
          dp[l][r] = W;

        for (int mid = l; mid <= r; mid++) {
          dp[l][r] = max(dp[l][r], dp[l][mid] + dp[mid][r]);
        }
      }
    }
    cout << dp[0][n] << en;
  }
}
Problem p01096 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

bool check(int a, int b) { return abs(a - b) <= 1; }

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> w(n);
    rep(i, n) { cin >> w[i]; }

    int dp[300][300] = {{0}};
    range(W, 2, n + 1) {
      rep(i, n) {
        int j = i + W - 1;
        if (check(w[i], w[j]) && dp[i + 1][j - 1] == W - 2) {
          dp[i][j] = W;
        }
        range(k, i, j) { dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]); }
      }
    }
    cout << dp[0][n - 1] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

bool check(int a, int b) { return abs(a - b) <= 1; }

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> w(n);
    rep(i, n) { cin >> w[i]; }

    int dp[300][300] = {{0}};
    range(W, 2, n + 1) {
      rep(i, n) {
        int j = i + W - 1;
        if (i + W - 1 >= 300)
          break;
        if (check(w[i], w[j]) && dp[i + 1][j - 1] == W - 2) {
          dp[i][j] = W;
        }
        range(k, i, j) { dp[i][j] = max(dp[i][j], dp[i][k] + dp[k + 1][j]); }
      }
    }
    cout << dp[0][n - 1] << endl;
  }
}
Problem p01096 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#define ll long long
using namespace std;
typedef pair<int, int> P;
int N, W[300], dp[300][300];

int rec(int l, int r) {
  if (l >= r)
    return 0;
  if (dp[l][r] != -1)
    return (dp[l][r]);
  int ret = 0;
  if (abs(W[l] - W[r]) <= 1 && rec(l + 1, r - 1) == r - l - 1)
    ret = r - l + 1;
  for (int m = l; m < r; m++)
    ret = max(ret, rec(l, m) + rec(m + 1, r));
  return (dp[l][r] = ret);
}

int main() {
  while (1) {
    cin >> N;
    for (int i = 0; i < N; i++)
      cin >> W[i];
    memset(dp, -1, sizeof(dp));
    cout << rec(0, N - 1) << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#define ll long long
using namespace std;
typedef pair<int, int> P;
int N, W[300], dp[300][300];

int rec(int l, int r) {
  if (l >= r)
    return 0;
  if (dp[l][r] != -1)
    return (dp[l][r]);
  int ret = 0;
  if (abs(W[l] - W[r]) <= 1 && rec(l + 1, r - 1) == r - l - 1)
    ret = r - l + 1;
  for (int m = l; m < r; m++)
    ret = max(ret, rec(l, m) + rec(m + 1, r));
  return (dp[l][r] = ret);
}

int main() {
  while (1) {
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++)
      cin >> W[i];
    memset(dp, -1, sizeof(dp));
    cout << rec(0, N - 1) << endl;
  }
}
Problem p01101 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  while (cin >> m >> n, n || m) {
    vector<int> data(n);
    for (int i = 0; i < n; i++) { // input
      cin >> data[i];
    }

    int max = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int tmp = data[i] + data[j];
        if (tmp <= m && tmp > max) {
          max = tmp;
        }
      }
    }

    if (max == 0) { // output
      cout << "NONE" << endl;
    } else {
      cout << max << endl;
    }
  }

  return 0;
}


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

using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n || m) {
    vector<int> data(n);
    for (int i = 0; i < n; i++) { // input
      cin >> data[i];
    }

    int max = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        int tmp = data[i] + data[j];
        if (tmp <= m && tmp > max) {
          max = tmp;
        }
      }
    }

    if (max == 0) { // output
      cout << "NONE" << endl;
    } else {
      cout << max << endl;
    }
  }

  return 0;
}
Problem p01101 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
//
int main() {
  int N, M;
  int A[1000];
  while (1) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) {
      break;
    }
    FOR(i, 0, N) { cin >> A[i]; }
    VE S;
    FOR(i, 0, N) {
      FOR(j, i + 1, N) { S.PB(A[i] + A[j]); }
    }
    sort(S.begin(), S.end());
    int ans = 0, now = 0;
    while (1) {
      if (S[now] <= M) {
        ans = S[now];
        now++;
      } else {
        break;
      }
    }
    if (now == 0) {
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int, int>
#define MA make_pair
#define LL long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
#define YES(i) cout << (i ? "YES" : "NO") << endl
#define Yes(i) cout << (i ? "Yes" : "No") << endl
using namespace std;
//
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
//
int main() {
  int N, M;
  int A[1000];
  while (1) {
    int N, M;
    cin >> N >> M;
    if (N == 0 && M == 0) {
      break;
    }
    FOR(i, 0, N) { cin >> A[i]; }
    VE S;
    FOR(i, 0, N) {
      FOR(j, i + 1, N) { S.PB(A[i] + A[j]); }
    }
    sort(S.begin(), S.end());
    int ans = 0, now = 0;
    while (now < N * (N - 1) / 2) {
      if (S[now] <= M) {
        ans = S[now];
        now++;
      } else {
        break;
      }
    }
    if (now == 0) {
      cout << "NONE" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}
Problem p01101 (C++)

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

int main() {
  int n, m, MAX = 0, SUM;
  int a, size;
  vector<int> v;

  while (cin >> n >> m, n) {

    for (int i = 0; i < n; i++) {
      cin >> a;
      v.push_back(a);
    }

    for (int i = 0; i < v.size(); i++) {
      for (int j = i + 1; j < v.size(); j++) {
        SUM = v[i] + v[j];
        if (SUM <= m) {
          MAX = max(MAX, SUM);
          // cout << MAX << endl;
        }
      }
    }

    if (MAX == 0) {
      cout << "NONE" << endl;
    } else {
      cout << MAX << endl;
    }
  }

  return 0;
}


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

int main() {
  int n, m, MAX = 0, SUM;
  int a, size;
  vector<int> v;

  while (cin >> n >> m, n) {

    int MAX = 0, SUM, a, size;
    vector<int> v;

    for (int i = 0; i < n; i++) {
      cin >> a;
      v.push_back(a);
    }

    for (int i = 0; i < v.size(); i++) {
      for (int j = i + 1; j < v.size(); j++) {
        SUM = v[i] + v[j];
        if (SUM <= m) {
          MAX = max(MAX, SUM);
          // cout << MAX << endl;
        }
      }
    }

    if (MAX == 0) {
      cout << "NONE" << endl;
    } else {
      cout << MAX << endl;
    }
  }

  return 0;
}
Problem p01101 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    cin >> n >> m;
    int a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (a[i] + a[j] <= m)
          ans = max(ans, a[i] + a[j]);
      }
    }
    if (ans == 0)
      cout << "NONE" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 2147483647
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long

using namespace std;
int main() {
  int n, m;
  while (cin >> n >> m, n + m) {
    int a[n];
    for (int i = 0; i < n; i++)
      cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        if (a[i] + a[j] <= m)
          ans = max(ans, a[i] + a[j]);
      }
    }
    if (ans == 0)
      cout << "NONE" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
Problem p01102 (C++)

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

using namespace std;

int main() {
  string S, T;
  while (cin >> S, S != ".") {
    cin >> T;
    int beet = 0;
    string latte, malta;
    vector<string> oi, ushi;
    for (int i = 0; i < S.size(); i++) {
      if (beet % 2 == 0)
        latte += S[i], oi.push_back("");
      else
        oi.back() += S[i];
      if (S[i] == '\"')
        ++beet;
    }
    beet = 0;
    for (int i = 0; i < T.size(); i++) {
      if (beet % 2 == 0)
        malta += T[i], ushi.push_back("");
      else
        ushi.back() += T[i];
      if (T[i] == '\"')
        ++beet;
    }
    int incorrect = 0;
    if (oi.size() != ushi.size())
      incorrect = 114514;
    for (int i = 0; i < oi.size(); i++)
      incorrect += oi[i] != ushi[i];

    if (latte != malta || incorrect >= 2) {
      cout << "DIFFERENT" << endl;
    } else if (S == T) {
      cout << "IDENTICAL" << endl;
    } else {
      cout << "CLOSE" << endl;
    }
  }
}

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

using namespace std;

int main() {
  string S, T;
  while (cin >> S, S != ".") {
    cin >> T;
    int beet = 0;
    string latte, malta;
    vector<string> oi, ushi;
    for (int i = 0; i < S.size(); i++) {
      if (beet % 2 == 0)
        latte += S[i], oi.push_back("");
      else
        oi.back() += S[i];
      if (S[i] == '\"')
        ++beet;
    }
    beet = 0;
    for (int i = 0; i < T.size(); i++) {
      if (beet % 2 == 0)
        malta += T[i], ushi.push_back("");
      else
        ushi.back() += T[i];
      if (T[i] == '\"')
        ++beet;
    }
    int incorrect = 0;
    if (oi.size() != ushi.size())
      incorrect = 114514;
    else
      for (int i = 0; i < oi.size(); i++)
        incorrect += oi[i] != ushi[i];

    if (latte != malta || incorrect >= 2) {
      cout << "DIFFERENT" << endl;
    } else if (S == T) {
      cout << "IDENTICAL" << endl;
    } else {
      cout << "CLOSE" << endl;
    }
  }
}