alexjercan/bugnet huggingface dataset:
Problem p00147 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int seat[17] = {0};
  int X = 0;
  int stop[100] = {0};
  int time = 0;
  queue<int> Q;
  while (X < 100) {
    int x;
    if (time % 5 == 0 && time < 500) {
      Q.push(time / 5);
    }
    while (1) {
      if (Q.size())
        x = Q.front();
      else
        x = -1;
      bool f = false;

      if (~x) {
        int people = (x % 5 == 1 ? 5 : 2);
        int use = 19 + 3 * (x % 3) + 17 * (x % 2);
        rep(i, 17 - people + 1) {
          bool flag = true;
          rep(j, people) { flag &= seat[i + j] == 0; }
          if (flag) {
            rep(j, people) { seat[i + j] = use; }
            f = true;
            break;
          }
        }
      }
      if (f) {
        stop[x] = time - x * 5;
        Q.pop();
        X++;
      }
      if (!f)
        break;
    }
    rep(i, 17) { seat[i] = max(0, seat[i] - 1); }
    time++;
  }
  int n, c = 0;

  while (cin >> n) {
    if (n <= 5)
      c++;
    cout << stop[n] << endl;
  }
  int a = 0;
  while (c >= 2) {
    cout << a / a << endl;
  };
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int seat[17] = {0};
  int X = 0;
  int stop[100] = {0};
  int time = 0;
  queue<int> Q;
  while (X < 100) {
    int x;
    if (time % 5 == 0 && time < 500) {
      Q.push(time / 5);
    }
    while (1) {
      if (Q.size())
        x = Q.front();
      else
        x = -1;
      bool f = false;

      if (~x) {
        int people = (x % 5 == 1 ? 5 : 2);
        int use = 19 + 3 * (x % 3) + 17 * (x % 2);
        rep(i, 17 - people + 1) {
          bool flag = true;
          rep(j, people) { flag &= seat[i + j] == 0; }
          if (flag) {
            rep(j, people) { seat[i + j] = use; }
            f = true;
            break;
          }
        }
      }
      if (f) {
        stop[x] = time - x * 5;
        Q.pop();
        X++;
      }
      if (!f)
        break;
    }
    rep(i, 17) { seat[i] = max(0, seat[i] - 1); }
    time++;
  }
  int n, c = 0;

  while (cin >> n) {
    if (n < 50)
      c++;
    cout << stop[n] << endl;
  }
  int a = 0;
  while (c >= 2) {
    cout << a / a << endl;
  };
}
Problem p00147 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int seat[17] = {0};
  int X = 0;
  int stop[100] = {0};
  int time = 0;
  queue<int> Q;
  while (X < 100) {
    int x;
    if (time % 5 == 0 && time < 500) {
      Q.push(time / 5);
    }
    while (1) {
      if (Q.size())
        x = Q.front();
      else
        x = -1;
      bool f = false;

      if (~x) {
        int people = (x % 5 == 1 ? 5 : 2);
        int use = 19 + 3 * (x % 3) + 17 * (x % 2);
        rep(i, 17 - people + 1) {
          bool flag = true;
          rep(j, people) { flag &= seat[i + j] == 0; }
          if (flag) {
            rep(j, people) { seat[i + j] = use; }
            f = true;
            break;
          }
        }
      }
      if (f) {
        stop[x] = time - x * 5;
        Q.pop();
        X++;
      }
      if (!f)
        break;
    }
    rep(i, 17) { seat[i] = max(0, seat[i] - 1); }
    time++;
  }
  int n, c = 0;

  while (cin >> n) {
    if (n < 50)
      c++;
    cout << stop[n] << endl;
  }
  while (c >= 5) {
    return 1;
  };
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int seat[17] = {0};
  int X = 0;
  int stop[100] = {0};
  int time = 0;
  queue<int> Q;
  while (X < 100) {
    int x;
    if (time % 5 == 0 && time < 500) {
      Q.push(time / 5);
    }
    while (1) {
      if (Q.size())
        x = Q.front();
      else
        x = -1;
      bool f = false;

      if (~x) {
        int people = (x % 5 == 1 ? 5 : 2);
        int use = 19 + 3 * (x % 3) + 17 * (x % 2);
        rep(i, 17 - people + 1) {
          bool flag = true;
          rep(j, people) { flag &= seat[i + j] == 0; }
          if (flag) {
            rep(j, people) { seat[i + j] = use; }
            f = true;
            break;
          }
        }
      }
      if (f) {
        stop[x] = time - x * 5;
        Q.pop();
        X++;
      }
      if (!f)
        break;
    }
    rep(i, 17) { seat[i] = max(0, seat[i] - 1); }
    time++;
  }
  int n, c = 0;

  while (cin >> n) {
    if (n >= 50)
      c++;
    cout << stop[n] << endl;
  }
  while (c >= 5) {
  };
}
Problem p00147 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int seat[17] = {0};
  int X = 0;
  int stop[100] = {0};
  int time = 0;
  queue<int> Q;
  while (X < 100) {
    int x;
    if (time % 5 == 0 && time < 500) {
      Q.push(time / 5);
    }
    while (1) {
      if (Q.size())
        x = Q.front();
      else
        x = -1;
      bool f = false;

      if (~x) {
        int people = (x % 5 == 1 ? 5 : 2);
        int use = 19 + 3 * (x % 3) + 17 * (x % 2);
        rep(i, 17 - people + 1) {
          bool flag = true;
          rep(j, people) { flag &= seat[i + j] == 0; }
          if (flag) {
            rep(j, people) { seat[i + j] = use; }
            f = true;
            break;
          }
        }
      }
      if (f) {
        stop[x] = time - x * 5;
        Q.pop();
        X++;
      }
      if (!f)
        break;
    }
    rep(i, 17) { seat[i] = max(0, seat[i] - 1); }
    time++;
  }
  int n, c = 0;
  while (cin >> n) {
    cout << stop[n] << endl;
    c++;
  }
  while (c < 9) {
  };
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int seat[17] = {0};
  int X = 0;
  int stop[100] = {0};
  int time = 0;
  queue<int> Q;
  while (X < 100) {
    int x;
    if (time % 5 == 0 && time < 500) {
      Q.push(time / 5);
    }
    while (1) {
      if (Q.size())
        x = Q.front();
      else
        x = -1;
      bool f = false;

      if (~x) {
        int people = (x % 5 == 1 ? 5 : 2);
        int use = 19 + 3 * (x % 3) + 17 * (x % 2);
        rep(i, 17 - people + 1) {
          bool flag = true;
          rep(j, people) { flag &= seat[i + j] == 0; }
          if (flag) {
            rep(j, people) { seat[i + j] = use; }
            f = true;
            break;
          }
        }
      }
      if (f) {
        stop[x] = time - x * 5;
        Q.pop();
        X++;
      }
      if (!f)
        break;
    }
    rep(i, 17) { seat[i] = max(0, seat[i] - 1); }
    time++;
  }
  int n, c = 0;
  while (cin >> n) {
    cout << stop[n] << endl;
    c++;
  }
  while (c >= 9) {
  };
}
Problem p00147 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int search_sequence(vector<int> &a, int n) {
  int cnt = 0;
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] == -1)
      ++cnt;
    else
      cnt = 0;
    if (cnt >= n)
      return i - cnt + 1;
  }
  return -1;
}

int main(void) {
  vector<int> seat(17, -1);
  int time[100], finish[100];
  queue<pair<int, int>> q;
  int x = 0, y = 0;
  for (int t = 0; y < 100; ++t) {
    if (t % 5 == 0 && x < 100)
      q.push(make_pair(x++, (x % 5 == 1) ? 5 : 2));
    for (int i = 0; i < 17; ++i) {
      if (seat[i] != -1 && finish[seat[i]] == t) {
        fill(&seat[i], &seat[i + ((seat[i] % 5 == 1) ? 5 : 2)], -1);
        // cerr<<t<<":";for(int i=0;i<17;++i)cerr<<seat[i]<<((i!=16)?" ":"\\n");
      }
    }
    while (!q.empty()) {
      pair<int, int> p = q.front();
      if (search_sequence(seat, p.second) == -1)
        break;
      fill(&seat[search_sequence(seat, p.second)],
           &seat[search_sequence(seat, p.second) + p.second], p.first);
      // cerr<<t<<":";for(int i=0;i<17;++i)cerr<<seat[i]<<((i!=16)?" ":"\\n");
      finish[p.first] = t + 17 * (p.first % 2) + 3 * (p.first % 3) + 19;
      time[p.first] = t - 5 * p.first;
      q.pop();
      ++y;
    }
  }
  int n;
  while (cin >> n) {
    cout << time[n] << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int search_sequence(vector<int> &a, int n) {
  int cnt = 0;
  for (int i = 0; i < a.size(); ++i) {
    if (a[i] == -1)
      ++cnt;
    else
      cnt = 0;
    if (cnt >= n)
      return i - cnt + 1;
  }
  return -1;
}

int main(void) {
  vector<int> seat(17, -1);
  int time[100], finish[100];
  queue<pair<int, int>> q;
  int x = 0, y = 0;
  for (int t = 0; y < 100; ++t) {
    if (t % 5 == 0)
      q.push(make_pair(x++, (x % 5 == 1) ? 5 : 2));
    for (int i = 0; i < 17; ++i) {
      if (seat[i] != -1 && finish[seat[i]] == t) {
        fill(&seat[i], &seat[i + ((seat[i] % 5 == 1) ? 5 : 2)], -1);
        // cerr<<t<<":";for(int i=0;i<17;++i)cerr<<seat[i]<<((i!=16)?" ":"\\n");
      }
    }
    while (search_sequence(seat, q.front().second) != -1) {
      fill(&seat[search_sequence(seat, q.front().second)],
           &seat[search_sequence(seat, q.front().second) + q.front().second],
           q.front().first);
      // cerr<<t<<":";for(int i=0;i<17;++i)cerr<<seat[i]<<((i!=16)?" ":"\\n");
      finish[q.front().first] =
          t + 17 * (q.front().first % 2) + 3 * (q.front().first % 3) + 19;
      time[q.front().first] = t - 5 * q.front().first;
      q.pop();
      ++y;
    }
  }
  int n;
  while (cin >> n) {
    cout << time[n] << endl;
  }
  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int n;
  while (cin >> n) {
    n %= 39;
    if (n == 0)
      n = 39;
    printf("3C%02d\\n", n);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  while (1) {
    int n;
    cin >> n;
    n %= 39;
    printf("3C%02d", n);
  }
  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int i, kai;

  while (scanf("%d", &i) != EOF) {
    i %= 39;
    if (i == 0)
      i = 39;
    if (i > 9)
      printf("3C%d\\n", i);
    else
      printf("3C0%d\\n", i);
  }
  return 0;
}

Error: -11

Fixed submission:

#include <stdio.h>

int main(void) {
  int i, kai;

  while (scanf("%d", i) != EOF) {
    i %= 39;
    if (i == 0)
      i = 39;
    printf("3C%d\\n", i);
  }
  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
  int x;
  while (cin >> x) {
    x = x % 39;
    if (x == 0)
      x = 39;
    printf("3C%02d\\n", x);
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

using namespace std;

int main() {
  int x;
  while (scanf("%d", &x)) {
    x = x % 39;
    if (x == 0)
      x = 39;
    printf("3C%02d\\n", x);
  }
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a;
  while (cin >> a) {
    a = a % 39;
    if (a == 0)
      cout << "3C39" << endl;
    else if (a < 10)
      cout << "3C0" << a << endl;
    else
      cout << "3C" << a << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a;
  while (true) {
    cin >> a;
    if (!a)
      return 0;
    a = a % 39;
    if (a < 10)
      cout << "3C0" << a << endl;
    else
      cout << "3C0" << a << endl;
  }
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
  if (a < b)
    a = b;
}
template <class T, class C> void chmin(T &a, C b) {
  if (b < a)
    a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }

int main() {
  for (int i; cin >> i; printf("3C%02d\\n", i))
    i = (i - 1) % 39 + 1;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
template <class T> T RoundOff(T a) { return int(a + .5 - (a < 0)); }
template <class T, class C> void chmax(T &a, C b) {
  if (a < b)
    a = b;
}
template <class T, class C> void chmin(T &a, C b) {
  if (b < a)
    a = b;
}
template <class T, class C> pair<T, C> mp(T a, C b) { return make_pair(a, b); }

int main() {
  for (int i; scanf("%d", &i); printf("3C%02d\\n", i))
    i = (i - 1) % 39 + 1;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    int num = (n - 1) % 39 + 1;
    if (num < 10)
      cout << "3C0" << num << endl;
    else
      cout << "3C" << num << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

    int num = (n - 1) % 39 + 1;
    if (num < 10)
      cout << "3C0" << num << endl;
    else
      cout << "3C" << num << endl;
  }
  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
int main(void) {
  int n;
  while (cin >> n) {
    n = n % 39;
    if (!n)
      n = 39;
    if (n >= 10)
      cout << "3C" << n << endl;
    else
      cout << "3C0" << n << endl;
  }
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

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

int main(void) {
  int n;
  int const teamname = 0;
  int const point = 1;
  while (cin >> n, n) {
    vector<vector<int>> team(n + 1, vector<int>(2));
    rep(i, n) {

      int m, s;
      cin >> team[i][teamname];
      rep(h, 4) {
        cin >> m >> s;
        team[i][point] += m * 60 + s;
      }
    }

    rep(i, n - 1) {
      loop(j, i, n) {
        if (team[i][point] > team[j][point]) {
          team[n][teamname] = team[i][teamname];
          team[i][teamname] = team[j][teamname];
          team[j][teamname] = team[n][teamname];
          team[n][teamname] = 0;

          team[n][point] = team[i][point];
          team[i][point] = team[j][point];
          team[j][point] = team[n][point];
          team[n][point] = 0;
        }
      }
    }

    /*    rep(i,n){
            cout<<team[i][teamname]<<" "<<team[i][point]<<endl;
        }
        */
    rep(i, 2) { cout << team[i][teamname] << endl; }
    cout << team[n - 2][teamname] << endl;
  }
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int n;
int main() {
  while (cin >> n) {
    int pos = n % 39;
    printf("3C%02d\\n", pos == 0 ? 39 : pos);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, string>> P;
const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int n;
int main() {
  string team;
  vector<P> data;

  int w, l, d;
  int c = 0;
  while (cin >> n, n) {
    if (c != 0) {
      cout << endl;
    }
    data.clear();
    for (int i = 0; i < n; i++) {
      cin >> team >> w >> l >> d;
      int sum = w * 3 + d * 1;
      data.push_back(P(sum, mp(-i, team)));
    }
    sort(data.begin(), data.end(), greater<P>());
    for (int i = 0; i < data.size(); i++) {
      string out = data[i].second.second;
      int score = data[i].first;
      cout << out << "," << score << endl;
    }
    c++;
  }
  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int a, b;
  while (scanf("%d", &a) != EOF) {
    b = a % 39;
    if (b == 0)
      b = 39;
    printf("3C%02d\\n", b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int a, b;
  while (scanf("%d", &a) != EOF) {
    while (1) {
      b = a - 39;
      if (a <= 39)
        break;
    }
    printf("3C%02d\\n", a);
  }
  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;

  for (; cin >> n;) {
    int ans = n % 39;
    if (n % 39 == 0)
      ans = 39;
    printf("3C%02d\\n", ans);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;

  for (;;) {
    cin >> n;
    if (n == 0)
      break;
    int ans = n % 39;
    if (n % 39 == 0)
      ans = 39;
    printf("3C%02d\\n", ans);
  }
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, count;
  while (cin >> n) {
    count = n % 39;
    if (count == 0)
      count = 39;
    cout << "3C";
    (count / 10 == 0) ? cout << "0" << count : cout << count;
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#define EOF -1

int main() {
  int n, count;
  while (1) {
    cin >> n;
    if (n == EOF)
      break;
    count = n % 39;
    if (count == 0)
      count = 39;
    cout << "3C" << count << endl;
  }
  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {

  int n, a;

  while (cin >> n) {

    a = n % 39;

    if (a > 0 && a < 10)
      cout << "3C0" << a << endl;
    else if (a >= 10)
      cout << "3C" << a << endl;
    else if (a == 0)
      cout << "3C39" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {

  int n, a;

  while (1) {

    cin >> n;

    if (n == 0)
      break;

    a = n % 39;

    if (a > 0 && a < 10)
      cout << "3C0" << a << endl;
    else if (a >= 10 && a < 39)
      cout << "3C" << a << endl;
    else if (a == 0)
      cout << "3C39" << endl;
  }

  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>

int main() {
  int a = 0;
  int n = 0;
  while (scanf("%d", &a) != EOF) {

    n = a % 39;
    if (n == 0) {
      n = 39;
    }

    if (n < 10) {
      printf("3C0%d\\n", n);
    } else {
      printf("3C%d\\n", n);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int candy = 0;

  while (true) {
    cin >> candy;
    if (candy == -1) {
      break;
    }

    cout << candy % 39 << endl;
  }
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;
#define rep2(x, from, to) for (int x = (from); x < (to); ++(x))
#define rep(x, to) rep2(x, 0, to)
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    printf("3C%02d\\n", n % 39 == 0 ? 39 : n % 39);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
#define rep2(x, from, to) for (int x = (from); x < (to); ++(x))
#define rep(x, to) rep2(x, 0, to)
int main() {
  int n;
  while (scanf("%d", &n)) {
    printf("3C%02d\\n", n % 39 == 0 ? 39 : n % 39);
  }
  return 0;
}
Problem p00148 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main(void) {
  int n;
  while (scanf("%d", &n) != EOF) {
    printf("3C%02d\\n", n % 39 == 0 ? 39 : n % 39);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int n;
  while (cin >> n, n) {
    printf("3C%02d\\n", n % 39 == 0 ? 39 : n % 39);
  }
  return 0;
}