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

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

int ans[114][2]
       [12]; // 二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter = 0, flag = 0;

void solve() {
  int n;
  cin >> n;
  if (n == 0) {
    flag = 1;
    return;
  }
  ans[counter][0][0] = n;

  int S[12]; // 数列
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  bool check = false; // 操作の有無のフラグ
  int time = 0;       // 操作回数
  do {
    map<int, int> marker;
    for (int i = 0; i < n; i++) {
      marker[S[i]];
      marker[S[i]]++;
    }
    check = false;
    for (int i = 0; i < n; i++) {
      if (S[i] != marker[S[i]]) {
        check = true;
        S[i] = marker[S[i]];
      }
    }
    if (check)
      time++;
  } while (check);

  ans[counter][0][1] = time;
  for (int i = 0; i < n; i++) {
    ans[counter][1][i] = S[i];
  }
  counter++;
}

int main() {
  while (flag == 0)
    solve();
  for (int i = 0; i < counter; i++) {
    cout << ans[i][0][1] << endl;
    for (int j = 0; j < ans[i][0][0] - 1; j++) {
      cout << ans[i][1][j] << " ";
    }
    cout << ans[i][1][ans[i][0][0] - 1] << endl;
  }
}


Error: 0

Fixed submission:

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

int ans[113][2]
       [12]; // 二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter = 0, flag = 0;

void solve() {
  int n;
  cin >> n;
  if (n == 0) {
    flag = 1;
    return;
  }
  ans[counter][0][0] = n;

  int S[12]; // 数列
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  bool check = false; // 操作の有無のフラグ
  int time = 0;       // 操作回数
  do {
    map<int, int> marker;
    for (int i = 0; i < n; i++) {
      marker[S[i]];
      marker[S[i]]++;
    }
    check = false;
    for (int i = 0; i < n; i++) {
      if (S[i] != marker[S[i]]) {
        check = true;
        S[i] = marker[S[i]];
      }
    }
    if (check)
      time++;
  } while (check);

  ans[counter][0][1] = time;
  for (int i = 0; i < n; i++) {
    ans[counter][1][i] = S[i];
  }
  counter++;
}

int main() {
  while (flag == 0)
    solve();
  for (int i = 0; i < counter; i++) {
    cout << ans[i][0][1] << endl;
    for (int j = 0; j < ans[i][0][0] - 1; j++) {
      cout << ans[i][1][j] << " ";
    }
    cout << ans[i][1][ans[i][0][0] - 1] << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

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

int ans[120][2]
       [12]; // 二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter = 0, flag = 0;

void solve() {
  int n;
  cin >> n;
  if (n == 0) {
    flag = 1;
    return;
  }
  ans[counter][0][0] = n;

  int S[12]; // 数列
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  bool check = false; // 操作の有無のフラグ
  int time = 0;       // 操作回数
  do {
    map<int, int> marker;
    for (int i = 0; i < n; i++) {
      marker[S[i]];
      marker[S[i]]++;
    }
    check = false;
    for (int i = 0; i < n; i++) {
      if (S[i] != marker[S[i]]) {
        check = true;
        S[i] = marker[S[i]];
      }
    }
    if (check)
      time++;
  } while (check);

  ans[counter][0][1] = time;
  for (int i = 0; i < n; i++) {
    ans[counter][1][i] = S[i];
  }
  counter++;
}

int main() {
  while (flag == 0)
    solve();
  for (int i = 0; i < counter; i++) {
    cout << ans[i][0][1] << endl;
    for (int j = 0; j < ans[i][0][0] - 1; j++) {
      cout << ans[i][1][j] << " ";
    }
    cout << ans[i][1][ans[i][0][0] - 1] << endl;
  }
}


Error: 0

Fixed submission:

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

int ans[110][2]
       [12]; // 二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter = 0, flag = 0;

void solve() {
  int n;
  cin >> n;
  if (n == 0) {
    flag = 1;
    return;
  }
  ans[counter][0][0] = n;

  int S[12]; // 数列
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  bool check = false; // 操作の有無のフラグ
  int time = 0;       // 操作回数
  do {
    map<int, int> marker;
    for (int i = 0; i < n; i++) {
      marker[S[i]];
      marker[S[i]]++;
    }
    check = false;
    for (int i = 0; i < n; i++) {
      if (S[i] != marker[S[i]]) {
        check = true;
        S[i] = marker[S[i]];
      }
    }
    if (check)
      time++;
  } while (check);

  ans[counter][0][1] = time;
  for (int i = 0; i < n; i++) {
    ans[counter][1][i] = S[i];
  }
  counter++;
}

int main() {
  while (flag == 0)
    solve();
  for (int i = 0; i < counter; i++) {
    cout << ans[i][0][1] << endl;
    for (int j = 0; j < ans[i][0][0] - 1; j++) {
      cout << ans[i][1][j] << " ";
    }
    cout << ans[i][1][ans[i][0][0] - 1] << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

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

int ans[1000][2]
       [12]; // 二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter = 0, flag = 0;

void solve() {
  int n;
  cin >> n;
  if (n == 0) {
    flag = 1;
    return;
  }
  ans[counter][0][0] = n;

  int S[12]; // 数列
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  bool check = false; // 操作の有無のフラグ
  int time = 0;       // 操作回数
  do {
    map<int, int> marker;
    for (int i = 0; i < n; i++) {
      marker[S[i]];
      marker[S[i]]++;
    }
    check = false;
    for (int i = 0; i < n; i++) {
      if (S[i] != marker[S[i]]) {
        check = true;
        S[i] = marker[S[i]];
      }
    }
    if (check)
      time++;
  } while (check);

  ans[counter][0][1] = time;
  for (int i = 0; i < n; i++) {
    ans[counter][1][i] = S[i];
  }
  counter++;
}

int main() {
  while (flag == 0)
    solve();
  for (int i = 0; i < counter; i++) {
    cout << ans[i][0][1] << endl;
    for (int j = 0; j < ans[i][0][0] - 1; j++) {
      cout << ans[i][1][j] << " ";
    }
    cout << ans[i][1][ans[i][0][0] - 1] << endl;
  }
}


Error: 0

Fixed submission:

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

int ans[100][2]
       [12]; // 二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter = 0, flag = 0;

void solve() {
  int n;
  cin >> n;
  if (n == 0) {
    flag = 1;
    return;
  }
  ans[counter][0][0] = n;

  int S[12]; // 数列
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  bool check = false; // 操作の有無のフラグ
  int time = 0;       // 操作回数
  do {
    map<int, int> marker;
    for (int i = 0; i < n; i++) {
      marker[S[i]];
      marker[S[i]]++;
    }
    check = false;
    for (int i = 0; i < n; i++) {
      if (S[i] != marker[S[i]]) {
        check = true;
        S[i] = marker[S[i]];
      }
    }
    if (check)
      time++;
  } while (check);

  ans[counter][0][1] = time;
  for (int i = 0; i < n; i++) {
    ans[counter][1][i] = S[i];
  }
  counter++;
}

int main() {
  while (flag == 0)
    solve();
  for (int i = 0; i < counter; i++) {
    cout << ans[i][0][1] << endl;
    for (int j = 0; j < ans[i][0][0] - 1; j++) {
      cout << ans[i][1][j] << " ";
    }
    cout << ans[i][1][ans[i][0][0] - 1] << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  int n;
  while (cin >> n, n != 0) {
    int s[2][n];
    for (int i = 0; i < n; i++) {
      cin >> s[0][i];
    }
    bool fixed = false;
    int src_index = 0;
    int operation_count = 0;
    while (!fixed) {
      map<int, int> appearance_map;
      for (int i = 0; i < n; i++) {
        ++appearance_map[s[src_index][i]];
      }
      fixed = true;
      for (int i = 0; i < n; i++) {
        s[1 - src_index][i] = appearance_map[s[src_index][i]];
        if (s[0][i] != s[1][i]) {
          fixed = false;
        }
      }
      if (fixed)
        break;
      src_index = 1 - src_index;
      ++operation_count;
    }
    cout << operation_count << endl;
    for (int i = 0; i < n; i++) {
      cout << s[0][i];
      if (i < n - 1)
        cout << " ";
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  int s[2][n];
  while ((cin >> s[0][0]), s[0][0] != 0) {
    for (int i = 1; i < n; i++) {
      cin >> s[0][i];
    }
    bool fixed = false;
    int src_index = 0;
    int operation_count = 0;
    while (!fixed) {
      map<int, int> appearance_map;
      for (int i = 0; i < n; i++) {
        ++appearance_map[s[src_index][i]];
      }
      fixed = true;
      for (int i = 0; i < n; i++) {
        s[1 - src_index][i] = appearance_map[s[src_index][i]];
        if (s[0][i] != s[1][i]) {
          fixed = false;
        }
      }
      if (fixed)
        break;
      src_index = 1 - src_index;
      ++operation_count;
    }
    cout << operation_count << endl;
    for (int i = 0; i < n; i++) {
      cout << s[0][i] << " ";
    }
    cout << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int i = 0, s[15], ap[1024] = {0};
    rep(j, n) {
      cin >> s[j];
      ap[s[j]]++;
    }
    int sub[15], ans = 0;
    ;
    while (true) {
      rep(j, n) { sub[j] = ap[s[j]]; }
      bool c = true;
      rep(j, 1024) ap[j] = 0;
      rep(j, n) {
        if (s[j] != sub[j])
          c = false;
        s[j] = sub[j];
        ap[s[j]]++;
      }
      if (c)
        break;
      ans++;
    }
    cout << ans << endl;
    rep(j, n) {
      if (j)
        cout << ' ';
      cout << s[j];
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int n, ans = 0;

void solve(int l1[], int count[]) {
  int l2[12], sum = 0;
  int subcount[13] = {0};
  rep(i, n) {
    l2[i] = count[l1[i]];
    subcount[l2[i]]++;
  }
  rep(i, n) {
    l1[i] = l2[i];
    count[i] = subcount[i];
    sum += count[l1[i]] - l1[i];
  }
  ans++;
  if (sum)
    solve(l1, count);
}

int main() {
  int l1[13], l2[13];
  while (cin >> n, n) {
    int count[13] = {0};
    rep(i, n) {
      cin >> l1[i];
      count[l1[i]]++;
    }
    ans = 0;
    solve(l1, count);
    cout << ans - 1 << endl;
    rep(i, n) {
      if (i == 0)
        ;
      else if (i == 1)
        cout << l1[i];
      else
        cout << ' ' << l1[i];
    }
    cout << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>]
#include <map>
#include <math.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n;
  int a[12];
  int s[12];
  while (true) {
    map<int, int> Map;
    cin >> n;
    if (n == 0) {
      break;
    }
    rep(i, n) { cin >> a[i]; }
    for (int cnt = 0; cnt < n * 3; cnt++) {
      Map.clear();
      rep(i, n) { Map[a[i]]++; }
      bool flag = true;
      rep(i, n) {
        flag = flag && (Map[a[i]] == a[i]);
        s[i] = Map[a[i]];
      }
      if (flag) {
        cout << cnt << endl;
        rep(i, n) {
          if (i != 0) {
            cout << " ";
          }
          cout << a[i];
        }
        cout << endl;
        break;
      }
      rep(i, n) { a[i] = s[i]; }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>]
#include <map>
#include <math.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
  int n;
  map<int, int> Map;
  int a[12];
  int s[12];
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    rep(i, n) { cin >> a[i]; }
    for (int cnt = 0;; cnt++) {
      rep(i, n) { Map[a[i]]++; }
      rep(i, n) { s[i] = Map[a[i]]; }
      if (a == s) {
        cout << cnt << endl;
        rep(i, n) {
          if (i != 0) {
            cout << " ";
          }
          cout << a[i];
        }
        cout << endl;
        break;
      }
      rep(i, n) { s[i] = a[i]; }
    }
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int a[n];
    int e = 0;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    while (1) {
      int b[n];
      for (int i = 0; i < n; i++)
        b[i] = 0;
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          if (a[i] == a[j])
            b[i]++;
      int d = 0;
      for (int i = 0; i < n; i++)
        if (a[i] == b[i])
          d++;
      if (d == n)
        break;
      e++;
      for (int i = 0; i < n; i++)
        a[i] = b[i];
    }
    cout << e << endl;
    cout << a[0];
    for (int i = 1; i < n; i++)
      cout << " " << a[i];
    cout << endl;
  }
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    int a[n];
    int e = 0;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    while (1) {
      int b[100000], c[n];
      for (int i = 0; i < n; i++)
        b[i] = 0;
      for (int i = 0; i < n; i++)
        b[a[i]]++;
      for (int i = 0; i < n; i++)
        c[i] = b[a[i]];
      int d = 0;
      for (int i = 0; i < n; i++)
        if (a[i] == c[i])
          d++;
      if (d == n)
        break;
      e++;
      for (int i = 0; i < n; i++)
        a[i] = c[i];
    }
    cout << e << endl;
    cout << a[0];
    for (int i = 1; i < n; i++)
      cout << " " << a[i];
    cout << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  int n;
  int number[12];
  int hantei;
  int count;

  while (cin >> n) {
    if (n == 0) {
      break;
    }
    int counter[100] = {0};
    for (int i = 0; i < n; i++) {
      cin >> number[i];
      counter[number[i] - 1]++;
    }
    hantei = 0;
    count = 0;
    while (1) {
      for (int i = 0; i < n; i++) {
        if (number[i] == counter[number[i] - 1]) {
          if (i == n - 1) {
            hantei = 1;
            break;
          }
          continue;
        } else {
          break;
        }
      }
      if (hantei == 1) {
        break;
      }
      for (int i = 0; i < n; i++) {
        number[i] = counter[number[i] - 1];
      }
      for (int i = 0; i < 100; i++) {
        counter[i] = 0;
      }
      for (int i = 0; i < n; i++) {
        counter[number[i] - 1]++;
      }
      count++;
    }
    cout << count << endl;
    cout << number[0];
    for (int i = 1; i < n; i++) {
      cout << " " << number[i];
    }
    cout << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

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

using namespace std;

int main() {
  int n;
  int number[12];
  int hantei;
  int count;

  while (cin >> n) {
    if (n == 0) {
      break;
    }
    int counter[12] = {0};
    for (int i = 0; i < n; i++) {
      cin >> number[i];
      counter[number[i] - 1]++;
    }
    hantei = 0;
    count = 0;
    while (1) {
      for (int i = 0; i < n; i++) {
        if (number[i] == counter[number[i] - 1]) {
          if (i == n - 1) {
            hantei = 1;
            break;
          }
          continue;
        } else {
          break;
        }
      }
      if (hantei == 1) {
        break;
      }
      for (int i = 0; i < n; i++) {
        number[i] = counter[number[i] - 1];
      }
      for (int i = 0; i < 12; i++) {
        counter[i] = 0;
      }
      for (int i = 0; i < n; i++) {
        counter[number[i] - 1]++;
      }
      count++;
    }
    cout << count << endl;
    for (int i = 0; i < n; i++) {
      cout << number[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

bool isChanged(int *S, int *prevS, int n);

int main() {
  int n;
  int S[12], freq[101], prevS[12];

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

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

    int cont = -1;
    for (int i = 0; i < 12; i++)
      prevS[i] = -1;

    while (isChanged(S, prevS, n)) {
      for (int i = 0; i < 101; i++)
        freq[i] = 0;

      for (int i = 0; i < n; i++) {
        freq[S[i]]++;
        prevS[i] = S[i];
      }

      for (int i = 0; i < n; i++) {
        S[i] = freq[S[i]];
      }

      cont++;
    }

    cout << cont << endl;
    for (int i = 0; i < n - 1; i++) {
      cout << S[i] << " ";
    }
    cout << S[n - 1] << endl;
  }

  return 0;
}

bool isChanged(int *S, int *prevS, int n) {
  for (int i = 0; i < n; i++) {
    if (S[i] != prevS[i])
      return true;
  }

  return false;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n, m;
int S[12], oldS[12], memo[2][12];

void init(void);
void ope(void);
void change(void);
int check(void);
int search(int num);

int main() {
  int ans;

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

    for (int i = 0; i < n; i++)
      cin >> oldS[i];

    init();
    ope();
    ans = 0;
    m = 0;
    while (check()) {
      change();
      ope();
      ans++;
    }

    cout << ans << endl;
    for (int i = 0; i < n; i++) {
      cout << S[i];
      if (i < n - 1)
        cout << " ";
    }
    cout << endl;
  }
}

void init(void) {
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 12; j++) {
      memo[i][j] = -1;
    }
  }
}

void ope(void) {
  int num, cont;
  for (int i = 0; i < n; i++) {
    num = oldS[i];
    cont = 0;
    if (search(num)) {
      cont = search(num);
    } else {
      for (int j = 0; j < n; j++) {
        if (oldS[j] == num)
          cont++;
      }
      memo[0][m] = num;
      memo[1][m] = cont;
    }
    S[i] = cont;
  }
}

void change(void) {
  for (int i = 0; i < n; i++) {
    oldS[i] = S[i];
  }
}

int check(void) {
  for (int i = 0; i < n; i++) {
    if (oldS[i] != S[i])
      return 1;
  }

  return 0;
}

int search(int num) {
  for (int i = 0; i < 12; i++) {
    if (memo[0][i] == num) {
      return memo[1][i];
    }
  }

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

#include <algorithm>
#include <stdio.h>
#include <vector>
int main() {
  int n, i, j, s, r;
  while (scanf("%d", &n), n) {
    std::vector<int> v[2];
    v[0].resize(n);
    v[1].resize(n);
    for (s = r = i = 0; i < n; ++i)
      scanf("%d", &v[0][i]);
    for (;;) {
      for (i = 0; i < n; ++i)
        v[!s][i] = std::count(v[s].begin(), v[s].end(), v[s][i]);
      if (v[!s] == v[s])
        break;
      ++r;
      s = !s;
    }
    printf("%d\\n", r);
    for (i = 0; i < n; ++i)
      printf("%d%c", v[0][i], i + 1 - n ? ' ' : '\\n');
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
using namespace std;
int main() {
  const int N = 12;
  int n, i, c;
  int a[N], b[N], (*pre)[N], (*next)[N];
  for (;;) {
    scanf("%d", &n);
    if (!n)
      break;
    for (i = 0; i < n; ++i)
      scanf("%d", &a[i]);

    c = 0;
    pre = &a;
    next = &b;
    for (;;) {
      for (i = 0; i < n; ++i) {
        (*next)[i] = count(*pre, *pre + N, (*pre)[i]);
      }
      {
        bool b = true;
        for (i = 0; i < n; ++i)
          if ((*pre)[i] != (*next)[i])
            b = false;
        if (b)
          break;
      }
      // if(equal(*pre, *pre+N, *next))
      //	break;
      swap(next, pre);
      c++;
    }
    printf("%d\\n", c);
    for (i = 0; i < n; ++i)
      printf("%s%d", (i ? " " : ""), (*pre)[i]);
    putchar('\\n');
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int in;

  while (cin >> in) {
    int rev = 0, max = 0;

    if (in == 0)
      break;

    int data[in];

    for (int i = 0; i < in; i++) {
      cin >> data[i];
      if (data[i] > max)
        max = data[i];
    }

    while (1) {

      int sum[max + 1];

      for (int i = 0; i <= max; i++) {
        sum[i] = 0;
      }

      for (int i = 0; i < in; i++) {
        sum[data[i]]++;
      }

      int status = 0;

      for (int i = 0; i < in; i++) {
        if (data[i] != sum[data[i]])
          status = 1;
      }

      /*for(int i = 0; i < in; i++) cout << data[i] << " ";
      cout << endl;*/

      if (status == 0) {
        cout << rev << endl;
        for (int i = 0; i < in; i++) {
          if (i != 0)
            cout << " ";
          cout << data[i];
        }
        cout << endl;
        break;
      }

      for (int i = 0; i < in; i++) {
        data[i] = sum[data[i]];
      }
      rev++;
      max = in;
    }
  }

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int in;

  while (cin >> in) {
    int rev = 0, max = 0;

    if (in == 0)
      break;

    int data[in];

    for (int i = 0; i < in; i++) {
      cin >> data[i];
      if (data[i] < max)
        max = data[i];
    }

    int sum[max];

    while (1) {

      for (int i = 0; i < max; i++) {
        sum[i] = 0;
      }

      for (int i = 0; i < in; i++) {
        sum[data[i]]++;
      }
      for (int i = 0; i < in; i++) {
        data[i] = sum[data[i]];
      }
      int status = 0;

      for (int i = 0; i < in; i++) {
        if (data[i] != sum[data[i]])
          status = 1;
      }

      if (status == 0) {
        cout << rev << endl;
        for (int i = 0; i < in; i++) {
          cout << data[i] << " ";
        }
        cout << endl;
        break;
      }
      rev++;
    }
  }

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

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

int p;
string exp;

int term();
int expression();
int factor();

int expression() {
  int value;
  value = term();
  while (exp[p] == '+' || exp[p] == '-') {
    if (exp[p] == '+') {
      p++;
      value += term();
    } else {
      p++;
      value -= term();
    }
  }
  return value;
}

int term() {
  int value;
  value = factor();
  while (exp[p] == '*' || exp[p] == '/') {
    if (exp[p] == '*') {
      p++;
      value *= factor();
    } else {
      p++;
      value /= factor();
    }
  }

  return value;
}

int factor() {
  int value = 0;
  if (exp[p] == '(') {
    p++;
    value = expression();
    p++;
  } else {
    while (isdigit(exp[p])) {
      value = value * 10 + exp[p++] - '0';
    }
  }
  return value;
}

int main() {
  int i, c;
  cin >> c;
  for (i = 0; i < c; i++) {
    cin >> exp;
    p = 0;
    cout << expression() << "\\n";
  }
  return 0;
}

Error: -11

Fixed submission:

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

int p;
string exp;

int term();
int expression();
int factor();

int expression() {
  int value;
  value = term();
  while (exp[p] == '+' || exp[p] == '-') {
    if (exp[p] == '+') {
      p++;
      value += term();
    } else {
      p++;
      value -= term();
    }
  }
  return value;
}

int term() {
  int value;
  value = factor();
  while (exp[p] == '*' || exp[p] == '/') {
    if (exp[p] == '*') {
      p++;
      value *= factor();
    } else {
      p++;
      value /= factor();
    }
  }

  return value;
}

int factor() {
  int value = 0;
  if (exp[p] == '(') {
    value = expression();
    p++;
  } else {
    while (isdigit(exp[p])) {
      value = value * 10 + exp[p++] - '0';
    }
  }
  return value;
}

int main() {
  int i, c;
  cin >> c;
  for (i = 0; i < c; i++) {
    cin >> exp;
    p = 0;
    cout << expression() << "\\n";
  }
  cout << "\\n";
  return 0;
}