alexjercan/bugnet huggingface dataset:
Problem p00273 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int x, y, b, p;
    int p1, p2;
    cin >> x >> y >> b >> p;
    p1 = x * b + y * p;
    p2 = x * max(5, b) + y * max(2, p);
    p2 *= 0.8;
    cout << min(p1, p2) << endl;
  }
  return 0;
}

Error: 200

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int x, y, b, p;
    int p1, p2;
    cin >> x >> y >> b >> p;
    p1 = x * b + y * p;
    p2 = x * max(5, b) + y * max(2, p);
    p2 *= 0.8;
    return min(p1, p2);
  }
  return 0;
}
Problem p00274 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  while (1) {
    int i;
    int n;
    int possibility = 0;
    int sum = 0;

    scanf("%d", &n);
    if (n == 0)
      return 0;

    for (i = 0; i < n; i++) {
      int a;

      scanf("%d", &a);
      if (a >= 2)
        possibility = 1;
      if (a >= 1)
        ++sum;
    }

    if (possibility) {
      printf("%d\\n", sum + 1);
    } else {
      printf("NA\\n");
    }
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main() {
  while (1) {
    int i;
    int n;
    int possibility = 0;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
      int a;

      scanf("%d", &a);
      if (a >= 2)
        possibility = 1;
    }

    if (possibility) {
      printf("%d\\n", n + 1);
    } else {
      printf("NA\\n");
    }
  }
}
Problem p00274 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, roop = 0, ans[100];
  while (cin >> n && n != 0) {
    int k[n], cou = 0;
    for (int i = 0; i < n; i++) {
      cin >> k[i];
      if (k[i] > 0)
        cou++;
    }
    sort(k, k + n);
    if (k[n - 1] < 2)
      ans[roop] = -1;
    else
      ans[roop] = cou + 1;
    roop++;
  }
  for (int i = 0; i < roop; i++) {
    if (ans[i] != -1)
      cout << ans[i] << endl;
    else
      cout << "NA" << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k[100], roop = 0, ans[100];
  while (cin >> n && n != 0) {
    int cou = 0;
    for (int i = 0; i < n; i++) {
      cin >> k[i];
      if (k[i] > 0)
        cou++;
    }

    sort(k, k + n);

    if (k[n - 1] < 2)
      ans[roop] = -1;
    else
      ans[roop] = cou + 1;
    roop++;
  }
  for (int i = 0; i < roop; i++) {
    if (ans[i] != -1)
      cout << ans[i] << endl;
    else
      cout << "NA" << endl;
  }
}
Problem p00274 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
int main(void) {
  int N = 1;
  static int k[10000];
  int i;
  int a, b;

  for (;;) {
    scanf("%d", &N);

    if (N == 0)
      break;

    for (i = 0; i < N; i++)
      scanf("%d", &k[i]);

    a = 0, b = 0;
    for (i = 0; i < N; i++) {
      if (k[i] == 0)
        a++;
      if (k[i] < 2)
        b++;
    }

    if (b == N)
      printf("NA\\n");
    else {
      N = N - a + 1;
      printf("%d\\n", N);
    }
  }
}


Error: 0

Fixed submission:

#include <stdio.h>
int main(void) {
  int N = 1;
  static int k[100];
  int i;
  int a, b;

  for (;;) {
    scanf("%d", &N);

    if (N == 0)
      break;

    for (i = 0; i < N; i++)
      scanf("%d", &k[i]);

    a = 0, b = 0;
    for (i = 0; i < N; i++) {
      if (k[i] == 0)
        a++;
      if (k[i] < 2)
        b++;
    }

    if (b == N)
      printf("NA\\n");
    else {
      N = N - a + 1;
      printf("%d\\n", N);
    }
  }
}
Problem p00274 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int N, i, c;
  int *k, *kk;
  while (1) {
    scanf("%d", &N);
    if (N == 0)
      break;
    k = new int[N];
    kk = new int[N];
    for (i = 0; i < N; i++)
      kk[i] = 0;
    for (i = 0; i < N; i++)
      scanf("%d", &k[i]);

    i = 0, c = 0;
    while (1) {
      if (k[i % N] > 0) {
        k[i % N]--;
        kk[i % N]++;
        c++;
      }
      if (kk[i % N] == 2) {
        printf("%d\\n", c);
        break;
      }
      if (i > N * 2) {
        printf("NA\\n");
        break;
      }
      i++;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int N, i, c;
  int *k, *kk;
  while (1) {
    scanf("%d", &N);
    if (N == 0)
      break;
    k = new int[N];
    kk = new int[N];
    for (i = 0; i < N; i++)
      kk[i] = 0;
    for (i = 0; i < N; i++)
      scanf("%d", &k[i]);

    i = 0, c = 0;
    while (1) {
      if (k[i % N] > 0) {
        k[i % N]--;
        kk[i % N]++;
        c++;
      }
      if (kk[i % N] == 2) {
        printf("%d\\n", c);
        break;
      }
      if (i > N * N) {
        printf("NA\\n");
        break;
      }
      i++;
    }
  }
  return 0;
}
Problem p00274 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int n;

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
      cin >> vec[i];
    }

    sort(vec.begin(), vec.end());

    int index = 0;

    while (index < vec.size() && vec[index] < 2) {
      index++;
    }

    if (index == vec.size()) {
      cout << "NA" << endl;
    } else {
      index = 0;

      while (vec[index] == 0) {
        index++;
      }

      if (index != 0) {
        vec.erase(vec.begin(), vec.begin() + index);
      }

      cout << vec.size() + 1 << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {

  int n;

  while (1) {
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
      cin >> vec[i];
    }

    sort(vec.begin(), vec.end());

    int index = 0;

    while (vec[index] == 0) {
      index++;
    }

    if (index != 0) {
      vec.erase(vec.begin(), vec.begin() + index - 1);
    }

    index = 0;

    while (index < vec.size() && vec[index] < 2) {
      index++;
    }

    if (index == vec.size()) {
      cout << "NA" << endl;
    }

    else {
      cout << vec.size() + 1 << endl;
    }
  }

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

#include <stdio.h>

int main(void) {
  int i, s, k, max, kai;
  while (0 == 0) {
    scanf("%d", &k);
    if (k == 0)
      break;
    kai = k;
    scanf("%d", &s);
    max = s;
    if (s == 0)
      kai--;
    for (i = 1; i < k; i++) {
      scanf(" %d", &s);
      if (max < s)
        max = s;
      if (s == 0)
        kai--;
    }
    if (max < 2)
      printf("NA\\n");
    else
      printf("%d\\n", kai + 1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

int main(void) {
  int i, s, k, max;
  while (scanf("%d", &k) != 0) {
    scanf("%d", &s);
    max = s;
    for (i = 1; i < k; i++) {
      scanf("%d", &s);
      if (max == 1 && s != 1)
        max = s;
    }
    if (max = 1)
      printf("NA\\n");
    else
      printf("%d\\n", k + 1);
  }
  return 0;
}
Problem p00274 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, i, j;
  int a[100001];
  while (1) {
    cin >> n;
    int c = 0;
    int s = 0;
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] <= 1) {
        c++;
        if (a[i] == 0) {
          s++;
        }
      }
    }
    if (n == 1 && a[0] >= 2) {
      cout << 2 << endl;
    } else {
      if (c == n || n == 1 && a[0] <= 1) {
        cout << "NA" << endl;
      } else {
        cout << n - s + 1 << endl;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, j;
  int a[1000];
  while (1) {
    cin >> n;
    int c = 0;
    int s = 0;
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (a[i] <= 1) {
        c++;
        if (a[i] == 0) {
          s++;
        }
      }
    }
    if (n == 1 && a[0] >= 2) {
      cout << 2 << endl;
    } else {
      if (c == n || n == 1 && a[0] <= 1) {
        cout << "NA" << endl;
      } else {
        cout << n - s + 1 << endl;
      }
    }
  }
  return 0;
}
Problem p00274 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int k[10000000];

int main() {
  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    for (int i = 0; i < N; i++)
      cin >> k[i];

    bool ok = false;
    int ans = 1;
    for (int i = 0; i < N; i++) {
      if (k[i] >= 1)
        ans++;
      if (k[i] >= 2)
        ok = true;
    }
    if (ok)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    int k[10000000];
    for (int i = 0; i < N; i++)
      cin >> k[i];

    bool ok = false;
    int ans = 1;
    for (int i = 0; i < N; i++) {
      if (k[i] >= 1)
        ans++;
      if (k[i] >= 2)
        ok = true;
    }
    if (ok)
      cout << ans << endl;
    else
      cout << "NA" << endl;
  }
}
Problem p00274 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  while (1) {
    int n, k[10010];
    scanf("%d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      scanf("%d", &k[i]);
    }
    int cnt = 0;
    bool t = false;
    for (int i = 0; i < n; i++) {
      if (k[i] > 0)
        cnt++;
      if (k[i] >= 2)
        t = true;
    }
    if (t)
      printf("%d\\n", cnt + 1);
    else
      puts("NA");
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

#define rep(i, x) for (int i = 0; i < x; i++)

int main() {
  while (1) {
    int n;
    cin >> n;
    int k[1010];
    rep(i, n) cin >> k[i];

    bool t = false;
    int cnt = 0;

    rep(i, n) {
      if (k[i] >= 2)
        t = true;
      if (k[i] >= 1)
        cnt++;
    }

    if (t)
      cout << cnt + 1 << endl;
    else
      cout << "NA\\n";
  }
}
Problem p00274 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int cnt = 0;
  int f[114514];
  int t[114514];
  while (true) {
    int N;
    int a[11451];
    cin >> N;
    if (N == 0) {
      break;
    }
    t[cnt] = N;
    f[cnt] = 0;
    for (int i = 0; i < N; i++) {
      cin >> a[i];
      if (a[i] == 0) {
        t[cnt]--;
      }
      if (a[i] >= 2) {
        f[cnt] = 1;
      }
    }

    cnt++;
  }

  for (int i = 0; i < cnt; i++) {
    if (f[i] == 0) {
      cout << "NA" << endl;
    } else {
      cout << t[i] + 1 << endl;
    }
  }
}

Error: -11

Fixed submission:

#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int k = 0;
  int N[1919];
  int a[1145][1919];
  while (1) {
    cin >> N[k];
    if (N[k] == 0) {
      break;
    }
    int t = N[k];
    int f = 0;
    for (int i = 0; i < N[k]; i++) {
      cin >> a[i][k];
      if (a[i][k] == 0) {
        t--;
      }
      if (a[i][k] >= 2) {
        f = 1;
      }
    }

    if (f == 0) {
      cout << "NA" << endl;
    } else {
      cout << t << endl;
    }
    k++;
  }
}
Problem p00274 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  while (cin >> N) {
    if (N == 0) {
      break;
    }
    vector<int> k(N);
    int result = 0;
    bool flag = false;
    for (int i = 0; i < N; ++i) {
      cin >> k[i];
    }
    for (int i = 0; i < N; ++i) {
      if (k[i] == 1) {
        result++;
      } else if (k[i] >= 2) {
        flag = true;
        result++;
      }
    }
    if (result == 0 || !flag) {
      cout << "NA" << endl;
    } else {
      cout << result + 1 << endl;
    }
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  while (cin >> N) {
    if (N == 0) {
      break;
    }
    vector<int> k(N);
    int result = 0;
    bool flag = false;
    for (int i = 0; i < N; ++i) {
      cin >> k[N];
    }
    for (int i = 0; i < N; ++i) {
      if (k[N] == 1) {
        result++;
      } else if (k[N] >= 2) {
        flag = true;
        result++;
      }
    }
    if (result == 0 || !flag) {
      cout << "NA" << endl;
    } else {
      cout << result + 1 << endl;
    }
  }

  return 0;
}
Problem p00274 (C++) — buggy submission, verdict: Runtime Error

// AOJ0279

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int N;
    cin >> N;

    if (N == 0)
      break;

    int cnt0 = 0;
    int cnt1 = 0;

    for (int i = 0; i < N; i++) {
      int k;
      cin >> k;

      if (k == 0) {
        cnt0++;
      } else if (k == 1) {
        cnt1++;
      }
    }

    if (cnt0 + cnt1 == N) {
      cout << "NA" << endl;
    } else {
      cout << N - cnt0 + 1 << endl;
    }
  }

  return 0;
}

Error: -8

Fixed submission:

// AOJ0297.cpp

#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;

  for (int i = 0; i < N; i++) {
    int K, P;
    cin >> K >> P;

    int W = K % P;

    if (W == 0) {
      cout << P << endl;
    } else {
      cout << W << endl;
    }
  }

  return 0;
}
Problem p00275 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, i, j;
  char c;
  while (cin >> N, N) {
    int ba = 0;
    vector<int> player(100, 0);
    for (j = 0; j < 100;) {
      for (i = 0; i < N; i++, j++) {
        if (j == 100)
          break;
        cin >> c;
        if (c == 'S') {
          ba += player[i] + 1;
          player[i] = 0;
        } else if (c == 'L') {
          player[i] += ba + 1;
          ba = 0;
        } else if (c == 'M')
          player[i]++;
      }
    }
    sort(player.begin(), player.begin() + N);
    for (i = 0; i < N; i++)
      cout << player[i] << ' ';
    cout << ba << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int N, i, j;
  char c;
  while (cin >> N, N) {
    int ba = 0;
    vector<int> player;
    for (j = 0; j < 100;) {
      for (i = 0; i < N; i++, j++) {
        if (j == 100)
          break;
        cin >> c;
        if (c == 'S') {
          ba += player[i] + 1;
          player[i] = 0;
        } else if (c == 'L') {
          player[i] += ba + 1;
          ba = 0;
        } else if (c == 'M')
          player[i]++;
      }
    }
    sort(player.begin(), player.end());
    for (i = 0; i < N; i++)
      cout << player[i] << ' ';
    cout << ba << endl;
  }
  return 0;
}
Problem p00275 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    string st;
    cin >> st;
    int f = 0;
    vector<int> hs(N);
    int p = 0;
    for (int i = 0; i < 100; ++i) {
      if (st[i] == 'S') {
        f += 1 + hs[p];
        hs[p] = 0;
      } else if (st[i] == 'M') {
        hs[p]++;
      } else {
        hs[p] += 1 + f;
        f = 0;
      }
      p = (p + 1) % N;
    }
    sort(hs.begin(), hs.end());
    for (int i = 0; i < N; ++i) {
      cout << hs[i] << " ";
    }
    cout << f << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  while (1) {
    int N;
    cin >> N;
    string st;
    cin >> st;
    int f = 0;
    vector<int> hs(N);
    int p = 0;
    for (int i = 0; i < 100; ++i) {
      if (st[i] == 'S') {
        f += 1 + hs[p];
        hs[p] = 0;
      } else if (st[i] == 'M') {
        hs[p]++;
      } else {
        hs[p] += 1 + f;
        f = 0;
      }
      p = (p + 1) % N;
    }
    sort(hs.begin(), hs.end());
    for (int i = 0; i < N; ++i) {
      cout << hs[i] << " ";
    }
    cout << f << endl;
  }
  return 0;
}
Problem p00275 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int n, x[10000000], ba;
char s;
int main() {
  while (true) {
    cin >> n;
    ba = 0;
    memset(x, 0, sizeof(x));
    if (!n) {
      break;
    }
    for (int i = 0; i < 100; i++) {
      cin >> s;
      x[i % n]++;
      if (s == 'S') {
        ba += x[i % n];
        x[i % n] = 0;
      }
      if (s == 'L') {
        x[i % n] += ba;
        ba = 0;
      }
    }
    sort(x, x + n);
    for (int i = 0; i < n; i++) {
      cout << x[i];
      cout << ' ';
    }
    cout << ba << endl;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int n, x[20000000], ba;
char s;
int main() {
  while (true) {
    cin >> n;
    ba = 0;
    memset(x, 0, sizeof(x));
    if (!n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> s;
      if (s == 'M') {
        x[i % n]++;
      }
      if (s == 'S') {
        ba += x[i % n];
        x[i % n] = 0;
      }
      if (s == 'L') {
        x[i % n] += ba;
        ba = 0;
      }
    }
    sort(x, x + n);
    for (int i = 0; i < n; i++) {
      cout << x[i];
      cout << ' ';
    }
    cout << ba << endl;
  }
}
Problem p00275 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {

  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    string c;
    cin >> c;
    int maisu[10];
    for (int i = 0; i < N; i++) {
      maisu[i] = 0;
    }
    int ba = 0;
    int turn = 0;
    for (int i = 0; i < c.size(); i++) {
      if (c[i] == 'M') {
        maisu[turn]++;
      } else if (c[i] == 'S') {
        maisu[turn]++;
        ba += maisu[turn];
        maisu[turn] = 0;
      } else {
        maisu[turn]++;
        maisu[turn] += ba;
        ba = 0;
      }
      turn++;
      turn %= N;
    }
    sort(maisu, maisu + N);

    for (int i = 0; i < N; i++) {
      cout << maisu[i] << " ";
    }
    cout << ba << endl;
  }

  return 0;
}

Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {

  while (true) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    string c;
    cin >> c;
    int maisu[10];
    for (int i = 0; i < c.size(); i++) {
      maisu[i] = 0;
    }
    int ba = 0;
    int turn = 0;
    for (int i = 0; i < c.size(); i++) {
      if (c[i] == 'M') {
        maisu[turn]++;
      } else if (c[i] == 'S') {
        maisu[turn]++;
        ba += maisu[turn];
        maisu[turn] = 0;
      } else {
        maisu[turn]++;
        maisu[turn] += ba;
        ba = 0;
      }
      turn++;
      turn %= N;
    }
    sort(maisu, maisu + N);

    for (int i = 0; i < N; i++) {
      cout << maisu[i] << " ";
    }
    cout << ba << endl;
  }

  return 0;
}
Problem p00275 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
#include <algorithm>
#include <string>
#define REP(i, a) for (int i = 0; i < a; i++)
int A[100000];
int main() {

  string k;
  int a, b = 0, c = 0, n, j, x, y, p, N, M, BA = 0, fuda[101];
  cin >> n;
  while (n != 0) {
    REP(i, n) { fuda[i] = 0; }
    cin >> k;
    REP(i, 100) {
      if (k[i] == 'M') {
        fuda[c]++;
      } else if (k[i] == 'L') {
        fuda[c] = fuda[c] + BA + 1;
        BA = 0;
      } else if (k[i] == 'S') {
        BA = BA + fuda[c] + 1;
        fuda[c] = 0;
      }
      c++;
      if (c == n) {
        c = 0;
      }
    }
    sort(fuda, fuda + n);
    cout << fuda[0];
    REP(i, n - 1) { cout << " " << fuda[i + 1]; }
    c = 0;
    cout << " " << BA;
    cout << endl;
    cin >> n;
    BA = 0;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
#include <algorithm>
#include <string>
#define REP(i, a) for (int i = 0; i < a; i++)
int A[100000];
int main() {

  string k;
  int a, b = 0, c = 0, n, j, x, y, p, N, M, BA = 0, fuda[101];
  cin >> n;
  while (n != 0) {
    REP(i, n) { fuda[i] = 0; }
    cin >> k;
    REP(i, 100) {
      if (k[i] == 'M') {
        fuda[c]++;
      } else if (k[i] == 'L') {
        fuda[c] = fuda[c] + BA + 1;
        BA = 0;
      } else if (k[i] == 'S') {
        BA = BA + fuda[c] + 1;
        fuda[c] = 0;
      }
      c++;
      if (c == n) {
        c = 0;
      }
    }
    sort(fuda, fuda + n);
    cout << fuda[0];
    REP(i, n - 1) { cout << " " << fuda[i + 1]; }
    cout << " " << BA;
    cout << endl;
    cin >> n;
  }
  return 0;
}
Problem p00275 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  while (1) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    int person[N];
    for (int i = 0; i < N; i++)
      person[i] = 0;
    int mcount = 0;
    for (int i = 0; i < 100; i++) {
      char c;
      cin >> c;
      switch (c) {
      case 'M':
        person[i % N]++;
        break;
      case 'L':
        person[i % N] = mcount + person[i % N] + 1;
        mcount = 0;
        break;
      case 'S':
        mcount = person[i % N] + mcount + 1;
        person[i % N] = 0;
        break;
      }
    }
    sort(person, person + N);
    for (int i = 0; i < N; i++)
      cout << person[i] << ' ';
    cout << mcount << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  while (1) {
    int N;
    cin >> N;
    if (N == 0)
      break;
    int person[N];
    int mcount = 0;
    for (int i = 0; i < 100; i++) {
      int c;
      cin >> c;
      switch (c) {
      case 'M':
        person[i % N]++;
        break;
      case 'L':
        person[i % N] = mcount;
        mcount = 0;
        break;
      case 'S':
        mcount = person[i % N];
        person[i % N] = 0;
        break;
      }
    }
    sort(person, person + N);
  }
  return 0;
}
Problem p00276 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int A[12];
int main() {
  int i, a, b, c = 0, d = 0, n, e = 0, f = 0, l = -1, j;
  char S[102];
  scanf("%d", &d);
  for (i = 0; i < d; i++) {
    scanf("%d %d %d", &c, &a, &n);
    while (1) {
      if (c > 0 && a > 0 && n > 0) {
        e++;
        c--;
        a--;
        n--;
      } else if (c > 1 && a > 0) {
        c = c - 2;
        a--;
        e++;
      } else if (c > 2) {
        c = c - 3;
        e++;
      } else
        break;
    }
    printf("%d\\n", e);
    e = 0;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int A[12];
int main() {
  int i, a, b, c = 0, d = 0, n, e = 0, f = 0, l = -1, j;
  char S[102];
  scanf("%d", &d);
  for (i = 0; i < d; i++) {
    scanf("%d %d %d", &c, &a, &n);
    while (1) {
      if (c > 0 && a > 0 && n > 0) {
        e++;
        c--;
        a--;
        n--;
      } else if (c > 1 && a > 0) {
        c = c - 2;
        a--;
        e++;
      } else if (c > 2) {
        c = c - 3;
        e++;
      }
      if (a == 0 && n == 0 && c < 3 || c == 0)
        break;
    }
    printf("%d\\n", e);
    e = 0;
  }
  return 0;
}