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

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

int s = 99999999;

void kakerukamosirenai(int total, int left, int a, int b, int c, int f) {
  if (left > 0) {
    if (f == 0) {
      kakerukamosirenai(total + 380, left - 200, a + 200, b, c, 0); // a toru
      kakerukamosirenai(total, left, a, b, c, 1);                   // a toranai
    } else if (f == 1) {
      kakerukamosirenai(total + 550, left - 300, a, b + 300, c, 1); // b toru
      kakerukamosirenai(total, left, a, b, c, 2);                   // b toranai
    } else if (f == 2) {
      kakerukamosirenai(total + 850, left - 500, a, b, c + 500, 2); // c
    }
  } else if (left == 0) {
    int cnt = 0;
    while (a >= 1000) {
      a -= 1000;
      //			total -= 380;
      cnt++;
    }
    total -= (1900 * cnt) * 20 / 100;
    cnt = 0;

    while (b >= 1200) {
      b -= 1200;
      //			total -= 330;
      cnt++;
    }
    total -= (2200 * cnt) * 15 / 100;
    cnt = 0;

    while (c >= 1500) {
      c -= 1500;
      //			total -= 306;
      cnt++;
    }
    total -= (2550 * cnt) * 12 / 100;

    if (s > total) {
      s = total;
    }
  } else {
    //		cout << "erratta" <<endl;
  }
}

int main() {

  vector<int> p;
  int n, c = 0, a, t;

  while (1) {
    cin >> n;
    p.push_back(n);
    if (p[c] == 0)
      break;
    c++;
  }

  for (int i = 0; i < c; i++) {
    kakerukamosirenai(0, p[i], 0, 0, 0, 0);
    cout << s << endl;
    s = 999999999;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

int s = 99999999;

void kakerukamosirenai(int total, int left, int a, int b, int c) {
  if (left > 0) {
    kakerukamosirenai(total + 380, left - 200, a + 200, b, c); // a
    kakerukamosirenai(total + 550, left - 300, a, b + 300, c); // b
    kakerukamosirenai(total + 850, left - 500, a, b, c + 500); // c
  } else if (left == 0) {
    int cnt = 0;
    while (a >= 1000) {
      a -= 1000;
      //			total -= 380;
      cnt++;
    }
    total -= (1900 * cnt) * 20 / 100;
    cnt = 0;

    while (b >= 1200) {
      b -= 1200;
      //			total -= 330;
      cnt++;
    }
    total -= (2200 * cnt) * 15 / 100;
    cnt = 0;

    while (c >= 1500) {
      c -= 1500;
      //			total -= 306;
      cnt++;
    }
    total -= (2550 * cnt) * 12 / 100;

    if (s > total) {
      s = total;
    }
  } else {
    //		cout << "erratta" <<endl;
  }
}

int main() {

  vector<int> p;
  int n, c = 0, a, t;

  while (1) {
    cin >> n;
    p.push_back(n);
    if (p[c] == 0)
      break;
    c++;
  }

  for (int i = 0; i < c; i++) {
    kakerukamosirenai(0, p[i], 0, 0, 0);
    cout << s << endl;
    s = 999999999;
  }

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

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int dp[5001];
  int g[] = {200, 300, 500, 1000, 1200, 1500};
  int value[] = {380, 550, 850, 1520, 1870, 2244};

  fill(dp, dp + 5001, 1 << 29);

  dp[0] = 0;

  for (int i = 0; i < 6; i++) {
    for (int j = 0; j + g[i] <= 5000; j += 100) {
      dp[j + g[i]] = min(dp[j + g[i]], dp[j] + value[i]);
    }
  }

  int n;
  while (cin >> n, n) {
    cout << dp[n] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
  int g;

  /*
  cout << 380*5*0.80 << endl;
  cout << 550*4*0.85 << endl;
  cout << 850*3*0.88 << endl;

  cout << 380*15 << endl;
  cout << 550*10 << endl;
  cout << 850*6 << endl;*/

  int ans;

  while (cin >> g, g) {
    ans = 0;
    while (g != 0) {

      if (g >= 2700) {
        ans += 4014;
        g -= 2700;
      }

      else if (g >= 2500) {
        ans += 3764;
        g -= 2500;
      }

      else if (g >= 2200) {
        ans += 3390;
        g -= 2200;
      }

      else if (g >= 1500) {
        ans += 2244;
        g -= 1500;
      } else if (g >= 1200) {
        ans += 1870;
        g -= 1200;
      } else if (g >= 1000) {
        ans += 1520;
        g -= 1000;
      } else if (g >= 500) {
        ans += 850;
        g -= 500;
      } else if (g >= 300) {
        ans += 550;
        g -= 300;
      } else if (g >= 200) {
        ans += 380;
        g -= 200;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00106 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <deque>
#include <iostream>

using namespace std;

int ret;
int w;

void solve(int tmpw, int c) {
  // cout << "tmpw = " << tmpw << endl;
  if (c >= ret)
    return;
  if (tmpw == 0) {
    ret = min(ret, c);
    return;
  }
  if (c + 850 * 3 * 0.88 < ret && tmpw - 1500 >= 0) {
    solve(tmpw - 1500, c + 850 * 3 * 0.88);
  }
  if (c + 380 * 5 * 0.8 < ret && tmpw - 1000 >= 0) {
    solve(tmpw - 1000, c + 380 * 5 * 0.8);
  }
  if (c + 550 * 4 * 0.85 < ret && tmpw - 1200 >= 0) {
    solve(tmpw - 1200, c + 550 * 4 * 0.85);
  }
  if (c + 850 < ret && tmpw - 500 >= 0) {
    solve(tmpw - 500, c + 850);
  }
  if (c + 550 < ret && tmpw - 300 >= 0) {
    solve(tmpw - 300, c + 550);
  }
  if (c + 300 < ret && tmpw - 200 >= 0) {
    solve(tmpw - 200, c + 380);
  }

  return;
}

int main(void) {
  while (cin >> w && w) {
    ret = 1 << 30;
    solve(w, 0);
    cout << ret << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>

using namespace std;

int ret;
int w;

void solve(int tmpw, int c) {
  // cout << "tmpw = " << tmpw << endl;
  if (c >= ret)
    return;
  if (tmpw <= 0) {
    ret = min(ret, c);
    return;
  }
  solve(tmpw - 1500, c + 850 * 3 * 0.88);
  solve(tmpw - 1000, c + 380 * 5 * 0.8);
  solve(tmpw - 1200, c + 550 * 4 * 0.85);
  solve(tmpw - 500, c + 850);
  solve(tmpw - 300, c + 550);
  solve(tmpw - 200, c + 380);

  return;
}

int main(void) {
  while (cin >> w && w) {
    ret = 1 << 30;
    solve(w, 0);
    cout << ret << endl;
  }
}
Problem p00106 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define INF 1000000000

using namespace std;

int p[] = {380, 550, 850, 1870, 1520, 2244};
int w[] = {200, 300, 500, 1200, 1000, 1500};

int main(void) {

  int dp[5001];
  int g;

  for (int i = 0; i < 5001; i++) {
    dp[i] = INF;
  }
  dp[0] = 0;
  for (int i = 0; i < 5000; i++) {
    for (int j = 0; j < 6; j++) {
      if (w[j] + i < 5001) {
        if (dp[i] + p[j] < dp[i + w[j]]) {
          dp[i + w[j]] = dp[i] + p[j];
        }
      }
    }
  }

  while (scanf("%d", &g) && g != 0) {
    printf("%d\\n", dp[g]);
  }

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>

using namespace std;

int weight[6] = {200, 300, 500, 1000, 1200, 1500};
int price[6] = {380, 550, 850, 1520, 1870, 2244};

int main(void) {
  int n;
  while (scanf("%d", &n) && n) {
    int dp[5000001] = {0};
    dp[0] = 0;

    for (int i = 1;; i++) {
      for (int j = 0; j < 6; j++) {
        if (i - price[j] < 0)
          continue;
        dp[i] = max(dp[i - price[j]] + weight[j], dp[i]);
      }
      if (dp[i] >= n) {
        printf("%d\\n", i);
        break;
      }
    }
  }
  return 0;
}
Problem p00107 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <math.h>
#include <stdio.h>

int main() {
  while (1) {
    int d, w, h;
    scanf("%d %d %d", &d, &w, &h);
    if (d == 0 && w == 0 && h == 0)
      break;
    int n;
    scanf("%d", &n);

    int max = (int)fmax((double)d, fmax((double)w, (double)h));
    double a = sqrt(d * d + w * w + h * h - max * max) / 2;

    int i;
    for (i = 0; i < n; i++) {
      int b;
      scanf("%d", &b);
      // printf("a:%lf b:%d", a, b);
      if ((double)b <= a)
        printf("NA\\n");
      else
        printf("OK\\n");
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <math.h>
#include <stdio.h>

int main() {
  while (1) {
    int d, w, h;
    scanf("%d %d %d", &d, &w, &h);
    if (d == 0 && w == 0 && h == 0)
      break;
    int n;
    scanf("%d", &n);

    int max = (int)fmax((double)d, fmax((double)w, (double)h));
    double a = sqrt(d * d + w * w + h * h - max * max) / 2;

    int i;
    for (i = 0; i < 5; i++) {
      int b;
      scanf("%d", &b);
      // printf("a:%lf b:%d", a, b);
      if ((double)b <= a)
        printf("NA\\n");
      else
        printf("OK\\n");
    }
  }
  return 0;
}
Problem p00107 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int tate, yoko, takasa, mn, md;
  int n;
  while (cin >> tate >> yoko >> takasa, tate || yoko || takasa) {
    cin >> n;
    int *r = new int[n];
    mn = min(min(tate, yoko), takasa);
    if (tate >= yoko) {
      if (yoko >= takasa) {
        md = yoko;
      } else if (yoko < takasa) {
        if (tate >= takasa)
          md = takasa;
        else if (tate < takasa)
          md = tate;
      }

    } else if (tate < yoko) {
      if (tate >= takasa) {
        md = tate;
      } else if (tate < takasa) {
        if (yoko >= takasa)
          md = takasa;
        else if (yoko < takasa)
          md = yoko;
      }
    }
    for (int i = 0; i < n; ++i) {
      cin >> r[i];
      cout << ((r[i] * r[i] * 4 > mn * mn + md * md) ? "OK" : "NA") << endl;
    }
    delete[] r;
  }
  return 0;
}

Error: -6
free(): double free detected in tcache 2


Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int tate, yoko, takasa, mn, md;
  int n;
  while (cin >> tate >> yoko >> takasa, tate || yoko || takasa) {
    cin >> n;
    int *r = new int[n];
    mn = min(min(tate, yoko), takasa);
    if (tate >= yoko) {
      if (yoko >= takasa) {
        md = yoko;
      } else if (yoko < takasa) {
        if (tate >= takasa)
          md = takasa;
        else if (tate < takasa)
          md = tate;
      }

    } else if (tate < yoko) {
      if (tate >= takasa) {
        md = tate;
      } else if (tate < takasa) {
        if (yoko >= takasa)
          md = takasa;
        else if (yoko < takasa)
          md = yoko;
      }
    }
    for (int i = 0; i < n; ++i) {
      cin >> r[i];
      cout << ((r[i] * r[i] * 4 > mn * mn + md * md) ? "OK" : "NA") << endl;
      delete[] r;
    }
  }
  return 0;
}
Problem p00107 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <cmath>
#include <iostream>
using namespace std;
int main() {
  double w, h, d, r;
  double pi = 3.141592653, s;
  int n;
  while (1) {
    cin >> w >> h >> d;
    if (w + h + d == 0)
      break;
    cin >> n;
    while (n--) {
      cin >> r;
      r *= 2;
      double dw, dh, dd;
      dw = sqrt(w * w + h * h);
      dh = sqrt(h * h + d * d);
      dd = sqrt(d * d + w * w);
      if (dw < r || dh < r || dd < r)
        cout << "OK" << endl;
      else
        cout << "NA" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:



#include <iostream>

using namespace std;
int main() {
  double w, h, d, r;
  double pi = 3.141592653, s;
  int n;
  while (cin >> w >> h >> d) {
    cin >> n;
    while (n--) {
      cin >> r;
      s = r * r * pi;
      if (w * h < s || h * d < s || d * w < r)
        cout << "OK" << endl;
      else
        cout << "NA" << endl;
    }
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int s[1000];
    for (int i = 0; i < n; i++)
      cin >> s[i];
    bool endFlag = false;
    int c = 0;
    while (!endFlag) {
      endFlag = true;
      int cnt[1000] = {0};
      for (int i = 0; i < n; i++)
        cnt[s[i]]++;
      for (int i = 0; i < n; i++) {
        if (s[i] != cnt[s[i]]) {
          s[i] = cnt[s[i]];
          endFlag = false;
        }
      }
      if (!endFlag)
        c++;
    }
    cout << c << endl;
    for (int i = 0; i < n; i++) {
      if (i != 0)
        cout << " ";
      cout << s[i];
    }
    cout << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int s[12];
    for (int i = 0; i < n; i++)
      cin >> s[i];
    bool endFlag = false;
    while (!endFlag) {
      endFlag = true;
      int cnt[15] = {0};
      for (int i = 0; i < n; i++)
        cnt[s[i]]++;
      for (int i = 0; i < n; i++) {
        if (s[i] != cnt[s[i]]) {
          s[i] = cnt[s[i]];
          endFlag = false;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (i != 0)
        cout << " ";
      cout << s[i];
    }
    cout << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, c, i;
  int pre[12], now[12], cnt[12];
  while (cin >> n, n) {
    map<int, int> m;
    for (i = 0; i < n; i++) {
      cin >> pre[i];
      m[pre[i]] = i + 1;
    }
    for (i = 0; i < n; i++)
      now[i] = m[pre[i]];

    for (c = 0;; c++) {
      for (i = 0; i < n; i++)
        cnt[i] = 0;

      for (i = 0; i < n; i++)
        cnt[now[i] - 1]++;

      for (i = 0; i < n; i++)
        now[i] = cnt[now[i] - 1];

      for (i = 0; i < n; i++)
        if (now[i] != pre[i])
          break;

      if (i == n)
        break;

      for (i = 0; i < n; i++)
        pre[i] = now[i];
    }

    cout << c << endl << now[0];
    for (i = 1; i < n; i++)
      cout << " " << now[i];
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, c, i;
  int pre[12], now[12], cnt[12];
  while (cin >> n, n) {
    map<int, int> m;
    for (i = 0; i < n; i++) {
      cin >> pre[i];
      m[pre[i]] = i;
    }
    for (i = 0; i < n; i++)
      now[i] = m[pre[i]];

    for (c = 0;; c++) {
      for (i = 0; i < n; i++)
        cnt[i] = 0;

      for (i = 0; i < n; i++)
        cnt[now[i] - 1]++;

      for (i = 0; i < n; i++)
        now[i] = cnt[now[i] - 1];

      for (i = 0; i < n; i++)
        if (now[i] != pre[i])
          break;

      if (i == n)
        break;

      for (i = 0; i < n; i++)
        pre[i] = now[i];
    }

    cout << c << endl << now[0];
    for (i = 1; i < n; i++)
      cout << " " << now[i];
    cout << endl;
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> a(n, 0), b(n, 0);
    for (int i = 0; i < n; i++)
      cin >> b[i];
    int ans = 0;
    while (1) {
      for (int i = 0; i < n; i++)
        a[i] = count(b.begin(), b.end(), b[i]);
      if (a == b)
        break;
      b = a;
      ans++;
    }
    cout << ans << endl;
    for (int i = 0; i < n; i++)
      cout << b[i] << (i == n - 1 ? "\\n" : " ");
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  vector<int> a(12), b(12);
  while (cin >> n, n) {
    for (int i = 0; i < n; i++)
      cin >> b[i];
    int ans = 0;
    while (1) {
      for (int i = 0; i < n; i++)
        a[i] = count(b.begin(), b.end(), b[i]);
      if (a == b)
        break;
      b = a;
      ans++;
    }
    cout << ans << endl;
    for (int i = 0; i < n; i++)
      cout << b[i] << (i == n - 1 ? "\\n" : " ");
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

  int n;

  while (cin >> n) {
    if (n == 0)
      break;
    int a[13];
    map<int, int> b;
    int c[13];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[a[i]]++;
    }
    int j = 0;
    while (1) {

      bool flg = false;
      for (int i = 0; i < n; i++) {
        c[i] = b[a[i]];
        if (c[i] != a[i])
          flg = true;
        // cout<<c[i]<<" ";
      }
      // cout<<endl;
      if (!flg)
        break;
      b.clear();
      for (int k = 0; k < n; k++) {
        a[k] = c[k];
        b[a[k]]++;
      }
      j++;
    }
    cout << j << endl;
    bool f = false;
    for (int i = 0; i < n; i++) {
      if (f)
        cout << " ";
      cout << c[i];
      f = true;
    }
    cout << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

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

  int n;

  while (cin >> n) {
    if (n == 0)
      break;
    int a[13];
    map<int, int> b;
    int c[13];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[a[i]]++;
    }
    int j = 0;
    while (1) {

      bool flg = false;
      for (int i = 0; i < n; i++) {
        c[i] = b[a[i]];
        if (c[i] != a[i])
          flg = true;
        // cout<<c[i]<<" ";
      }
      // cout<<endl;
      if (!flg)
        break;
      for (int k = 0; k < n; k++)
        b[k] = 0;
      for (int k = 0; k < n; k++) {
        a[k] = c[k];
        b[a[k]]++;
      }
      j++;
    }
    cout << j << endl;
    for (int i = 0; i < n; i++) {
      cout << c[i] << " ";
    }
    cout << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    short hudou[1000][101];
    for (int i = 0; i < 1000; i++)
      for (int j = 0; j < 101; j++)
        hudou[i][j] = 0;
    short num[1000][n];
    for (int i = 0; i < n; i++) {
      cin >> num[0][i];
    }
    int cnt = 0;
    while (1) {
      for (int i = 0; i < n; i++)
        hudou[cnt][num[cnt][i]]++;
      for (int i = 0; i < n; i++)
        num[cnt + 1][i] = hudou[cnt][num[cnt][i]];
      int i, flag = 1;
      for (i = 0; i < n; i++) {
        if (num[cnt][i] != num[cnt + 1][i]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        cout << cnt << endl;
        for (int j = 0; j < n; j++) {
          cout << num[cnt][j];
          if (j != n - 1)
            cout << " ";
        }
        cout << endl;
        break;
      } else
        cnt++;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int hudou[10000][n + 1];
    for (int i = 0; i < 10000; i++)
      for (int j = 0; j < 13; j++)
        hudou[i][j] = 0;
    int num[10000][n];
    for (int i = 0; i < n; i++) {
      cin >> num[0][i];
    }
    int cnt = 0;
    while (1) {
      for (int i = 0; i < n; i++)
        hudou[cnt][num[cnt][i]]++;
      for (int i = 0; i < n; i++)
        num[cnt + 1][i] = hudou[cnt][num[cnt][i]];
      int i, flag = 1;
      for (i = 0; i < n; i++) {
        if (num[cnt][i] != num[cnt + 1][i]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        cout << cnt - 1 << endl;
        for (int j = 0; j < n; j++) {
          cout << num[cnt][j];
          if (j != n - 1)
            cout << " ";
        }
        cout << endl;
        break;
      } else
        cnt++;
    }
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;
int main() {
  int n, c;
  int r = 0;
  while (cin >> n && n) {
    c = 0;
    vector<int> one(n);
    vector<int> two(n);
    for (int i = 0; i < n; i++) {
      cin >> one[i];
    }
    while (one != two) {
      for (int k = 0; k < one.size(); k++) {
        r = 0;
        for (int i = 0; i < one.size(); i++)
          if (one[k] == one[i])
            r++;
        two[k] = r;
      }
      c++;
      swap(one, two);
    }
    cout << c - 1 << endl;
    for (int i = 0; i < n; i++) {
      if (i)
        cout << " ";
      cout << one[i];
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <utility>
#include <vector>

using namespace std;

int main(void) {
  int n;
  int a;
  int ans2;
  int s[13], S[13];
  int ans = 1;
  while (1) {
    ans2 = 0;
    cin >> n;
    if (n == 0)
      break;
    for (a = 0; a < n; a++) {
      cin >> s[a];
    }
    map<int, int> sc;
    for (a = 0; a < n; a++) {
      sc[s[a]]++;
    }
    while (1) {
      ans = 1;
      for (a = 0; a < n; a++) {
        S[a] = sc[s[a]];
      }
      for (a = 0; a < n; a++) {
        if (s[a] != S[a])
          ans = 0;
        s[a] = S[a];
      }
      for (a = 0; a < n; a++)
        sc[a] = 0;
      for (a = 0; a < n; a++)
        sc[s[a]]++;
      if (ans == 1)
        break;
      else
        ans2++;
    }
    cout << ans2 << endl;
    for (a = 0; a < n - 1; a++)
      cout << s[a] << ' ';
    cout << s[n - 1] << endl;
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define rep(i, l, n) for (lint i = l; i < n; i++)
#define rer(i, l, n) for (lint i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    lint ct = 0;
    int s[13] = {};
    rep(i, 0, n) { cin >> s[i]; }
    int ans[13] = {};
    for (ct = 0;; ct++) {
      rep(i, 0, 13) { ans[i] = 0; }
      int d[10000] = {};
      rep(i, 0, n) { d[s[i]]++; }
      rep(i, 0, n) { ans[i] = d[s[i]]; }
      int c = 0;
      rep(i, 0, n) {
        if (ans[i] == s[i])
          c++;
      }
      if (c == n)
        break;
      rep(i, 0, n) { s[i] = ans[i]; }
    }
    o(ct);
    rep(i, 0, n) {
      if (i == 0)
        cout << ans[i];
      else
        cout << " " << ans[i];
    }
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long int lint;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  int n;
  string s;
  while (cin >> n) {
    if (n == 0)
      break;
    lint ct = 0;
    int s[13] = {};
    rep(i, 0, n) { cin >> s[i]; }
    int ans[13] = {};
    for (ct = 0;; ct++) {
      rep(i, 0, 13) { ans[i] = 0; }
      int d[13] = {};
      rep(i, 0, n) { d[s[i]]++; }
      rep(i, 0, n) { ans[i] = d[s[i]]; }
      int c = 0;
      rep(i, 0, n) {
        if (ans[i] == s[i])
          c++;
      }
      if (c == n)
        break;
      rep(i, 0, n) { s[i] = ans[i]; }
    }
    o(ct);
    rep(i, 0, n) {
      if (i == 0)
        cout << ans[i];
      else
        cout << " " << ans[i];
    }
    cout << endl;
  }
}