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

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

int main() {
  while (1) {
    int n, count = 0;
    long before[13], after[13], c[13];

    scanf(" %d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; ++i)
      scanf(" %ld", &before[i]);

    // loop
    while (1) {

      for (int i = 0; i <= 12; ++i)
        c[i] = 0;

      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          if (before[i] == before[j])
            c[i]++;
        }
      }

      for (int i = 0; i < n; ++i)
        after[i] = c[i];

      bool flag = true;
      for (int i = 0; i < n; ++i) {
        if (before[i] != after[i]) {
          flag = false;
          break;
        }
      }
      if (flag)
        break;

      /*
      for(int i=0; i<n; ++i){
              printf("%ld", after[i]);
              if(i<n-1) printf(" ");
      }
      printf("\\n");
      */

      count++;
      for (int i = 0; i < n; ++i)
        before[i] = after[i];
    }

    printf("%d\\n", count);
    for (int i = 0; i < n; ++i) {
      printf("%ld", after[i]);
      if (i < n - 1)
        printf(" ");
    }
    printf("\\n");
  }
  return 0;
}

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


Fixed submission:

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

int main() {
  while (1) {
    int n, count = 0;
    long before[13], after[13], c[13];

    scanf(" %d", &n);
    if (n == 0)
      break;
    for (int i = 0; i < n; ++i)
      scanf(" %ld", &before[i]);

    // loop
    while (1) {

      for (int i = 0; i <= 120; ++i)
        c[i] = 0;

      for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
          if (before[i] == before[j])
            c[i]++;
        }
      }

      for (int i = 0; i < n; ++i)
        after[i] = c[i];

      bool flag = true;
      for (int i = 0; i < n; ++i) {
        if (before[i] != after[i]) {
          flag = false;
          break;
        }
      }
      if (flag)
        break;

      /*
      for(int i=0; i<n; ++i){
              printf("%ld", after[i]);
              if(i<n-1) printf(" ");
      }
      printf("\\n");
      */

      count++;
      for (int i = 0; i < n; ++i)
        before[i] = after[i];
    }

    printf("%d\\n", count);
    for (int i = 0; i < n; ++i) {
      printf("%ld", after[i]);
      if (i < n - 1)
        printf(" ");
    }
    printf("\\n");
  }
  return 0;
}
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: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n, c, i;
  int pre[12], now[12], cnt[12];
  while (cin >> n, n) {
    for (i = 0; i < n; i++) {
      cin >> pre[i];
      now[i] = 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: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int i, j, n;
  while (cin >> n, n) {
    int p, s[2][14] = {0};
    for (i = 1; i <= n; i++)
      cin >> s[0][i];
    for (p = 0;; p++) {
      for (i = 1; i <= n; i++) {
        s[1][i] = 0;
        for (j = 1; j <= n; j++)
          if (s[0][j] == s[0][i])
            s[1][i]++;
      }
      for (i = 1; i <= n; i++)
        if (s[0][i] != s[1][i])
          break;
      if (i > n)
        break;
      for (i = 1; i <= n; i++)
        s[0][i] = s[1][i];
    }
    cout << p << endl;
    for (i = 1; i <= n; i++)
      cout << s[1][i] << (i == n ? "" : " ");
    cout << endl;
  }
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int i, n;
  while (cin >> n, n) {
    int p, s[3][14] = {0};
    for (i = 1; i <= n; i++)
      cin >> s[0][i];
    for (p = 0;; p++) {
      for (i = 1; i <= n; i++)
        s[2][s[0][i]]++;
      for (i = 1; i <= n; i++)
        s[1][i] = s[2][s[0][i]];
      for (i = 1; i <= n; i++)
        if (s[0][i] != s[1][i])
          break;
      if (i > n)
        break;
      for (i = 1; i <= n; i++) {
        s[0][i] = s[1][i];
        s[2][i] = 0;
      }
    }
    cout << p << endl;
    for (i = 1; i <= n; i++)
      cout << s[1][i] << ' ';
    cout << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    vector<int> s;
    int b;
    for (int i = 0; i < n; i++) {
      cin >> b;
      s.push_back(b);
    }
    int c = 0;
    while (1) {
      vector<int> freq(1000, 0);
      for (int i = 0; i < n; i++)
        freq[s[i]]++;

      vector<int> ss = s;
      for (int i = 0; i < n; i++)
        ss[i] = freq[ss[i]];

      if (ss == s) {
        cout << c << endl;
        for (int i = 0; i < s.size(); i++)
          printf("%d%c", s[i], (i == s.size() - 1) ? '\\n' : ' ');
        break;
      }

      s = ss;
      c++;
    }
  }
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  while (1) {
    cin >> n;
    if (n == 0)
      break;
    vector<int> s;
    int b;
    for (int i = 0; i < n; i++) {
      cin >> b;
      s.push_back(b);
    }
    int c = 0;
    while (1) {
      vector<int> freq(13, 0);
      for (int i = 0; i < n; i++)
        freq[s[i]]++;

      vector<int> ss = s;
      for (int i = 0; i < n; i++)
        ss[i] = freq[ss[i]];

      if (ss == s) {
        cout << c << endl;
        for (int i = 0; i < s.size(); i++)
          printf("%d%c", s[i], (i == s.size() - 1) ? '\\n' : ' ');
        break;
      }

      s = ss;
      c++;
    }
  }
}
Problem p00108 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstring>
#include <iostream>
using namespace std;
int x[32000][500], n;
int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> x[0][i];
    }
    for (int i = 1; i < 30000; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (x[i - 1][k] == x[i - 1][j]) {
            x[i][j]++;
          }
        }
      }
    }
    for (int i = 1; i < 30000; i++) {
      for (int j = 0; j < n; j++) {
        if (x[i - 1][j] != x[i][j]) {
          goto E;
        }
      }
      cout << i - 1 << endl;
      for (int j = 0; j < n; j++) {
        if (j) {
          cout << ' ';
        }
        cout << x[i][j];
      }
      cout << endl;
      goto owata;
    E:;
    }
  owata:;
  }
}

Error: MLE

Fixed submission:

#include <cstring>
#include <iostream>
using namespace std;
int x[100000][500], n;
int main() {
  while (true) {
    memset(x, 0, sizeof(x));
    cin >> n;
    if (!n) {
      break;
    }
    for (int i = 0; i < n; i++) {
      cin >> x[0][i];
    }
    for (int i = 1; i < 30000; i++) {
      for (int j = 0; j < n; j++) {
        for (int k = 0; k < n; k++) {
          if (x[i - 1][k] == x[i - 1][j]) {
            x[i][j]++;
          }
        }
      }
    }
    for (int i = 1; i < 30000; i++) {
      for (int j = 0; j < n; j++) {
        if (x[i - 1][j] != x[i][j]) {
          goto E;
        }
      }
      cout << i - 1 << endl;
      for (int j = 0; j < n; j++) {
        if (j) {
          cout << ' ';
        }
        cout << x[i][j];
      }
      cout << endl;
      goto owata;
    E:;
    }
  owata:;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

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

using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<int> s(n);
    map<int, int> table;
    for (int i = 0; i < n; ++i) {
      cin >> s[i];
      if (table.find(s[i]) == table.end()) {
        table.insert(pair<int, int>(s[i], table.size() + 1));
      }
      s[i] = table[s[i]];
    }
    int answer = 0;
    vector<int> prev = s;
    while (true) {
      vector<int> b(n + 1, 0);
      for (int i = 0; i < n; ++i) {
        ++b[s[i]];
      }
      for (int i = 0; i < n; ++i) {
        s[i] = b[s[i]];
      }
      if (prev == s) {
        break;
      }
      prev = s;
      ++answer;
    }
    cout << answer << endl;
    for (int i = 0; i < n; ++i) {
      cout << s[i] << (i == n - 1 ? '\\n' : ' ');
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    vector<int> s(n);
    map<int, int> table;
    for (int i = 0; i < n; ++i) {
      cin >> s[i];
      if (table.find(s[i]) == table.end()) {
        s[i] = table[s[i]] = table.size() + 1;
      } else {
        s[i] = table[s[i]];
      }
    }
    int answer = 0;
    vector<int> prev = s;
    while (true) {
      vector<int> b(n, 0);
      for (int i = 0; i < n; ++i) {
        ++b[s[i]];
      }
      for (int i = 0; i < n; ++i) {
        s[i] = b[s[i]];
      }
      if (prev == s) {
        break;
      }
      prev = s;
      ++answer;
    }
    cout << answer << endl;
    for (int i = 0; i < n; ++i) {
      cout << s[i] << (i == n - 1 ? '\\n' : ' ');
    }
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>
void cpy(int src[], int dst[], int n) {
  for (int i = 0; i < n; i++)
    dst[i] = src[i];
}
void OFA(int S[], int n) {
  int num[100];
  memset(num, 0, sizeof(num));
  for (int i = 0; i < n; i++)
    num[S[i]]++;
  for (int i = 0; i < n; i++)
    S[i] = num[S[i]];
}

bool check(int S[], int tmp[], int n) {
  for (int i = 0; i < n; i++)
    if (S[i] != tmp[i])
      return false;
  return true;
}

int main() {
  int S[12], tmp[12], n, count;
  while (1) {
    scanf("%d", &n);
    if (!n)
      break;
    count = -1;
    for (int i = 0; i < n; i++)
      scanf("%d", &S[i]);
    cpy(S, tmp, n);
    do {
      cpy(tmp, S, n);
      OFA(tmp, n);
      // for(int i=0;i<n;i++) printf("%d ",tmp[i]);
      count++;
    } while (!check(S, tmp, n));
    printf("%d\\n", count);
    for (int i = 0; i < n - 1; i++)
      printf("%d ", S[i]);
    printf("%d\\n", S[n - 1]);
  }
  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>
#include <string.h>
void cpy(int src[], int dst[], int n) {
  for (int i = 0; i < n; i++)
    dst[i] = src[i];
}
void OFA(int S[], int n) {
  int num[13];
  memset(num, 0, sizeof(num));
  for (int i = 0; i < n; i++)
    num[S[i]]++;
  for (int i = 0; i < n; i++)
    S[i] = num[S[i]];
}

bool check(int S[], int tmp[], int n) {
  for (int i = 0; i < n; i++)
    if (S[i] != tmp[i])
      return false;
  return true;
}

int main() {
  int S[12], tmp[12], n, count;
  while (1) {
    scanf("%d", &n);
    if (!n)
      break;
    count = -1;
    for (int i = 0; i < n; i++)
      scanf("%d", &S[i]);
    cpy(S, tmp, n);
    do {
      cpy(tmp, S, n);
      OFA(tmp, n);
      // for(int i=0;i<n;i++) printf("%d ",tmp[i]);
      count++;
    } while (!check(S, tmp, n));
    printf("%d\\n", count);
    for (int i = 0; i < n; i++)
      printf("%d ", S[i]);
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <iostream>
#include <map>
using namespace std;
typedef map<int, int> mii;

bool check(int *numl, int *newl, int n = 0) {
  for (int i = 0; i < n; i++) {
    if (numl[i] != newl[i])
      return false;
  }
  return true;
}

void printline(int *line, int n) {
  std::cout << "printline:" << std::endl;
  for (int i = 0; i < n; i++) {
    std::cout << line[i] << " ";
  }
  std::cout << std::endl;
}

int main() {
  int n;
  while (cin >> n, n) {
    int numl[n], newl[n], ans = 0;
    mii counter;

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

      if (counter.find(numl[i]) == counter.end()) {
        counter[numl[i]] = 1;
      } else {
        counter[numl[i]]++;
      }
    }

    while (!check(newl, numl, n)) {
      ans++;
      for (int i = 0; i < n; i++) {
        newl[i] = numl[i];
        numl[i] = counter[numl[i]];
      }

      counter.clear();

      for (int i = 0; i < n; i++) {
        if (counter.find(numl[i]) == counter.end()) {
          counter[numl[i]] = 1;
        } else {
          counter[numl[i]]++;
        }
      }

      // printline(numl, n);
    }
    std::cout << ans - 1 << std::endl;
    for (int i = 0; i < n - 1; i++) {
      std::cout << newl[i] << " ";
    }
    std::cout << newl[n - 1] << std::endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <iostream>
#include <map>
using namespace std;
typedef map<int, int> mii;
bool check(int *numl, int *newl, int n = 0) {
  for (int i = 0; i < n; i++) {
    if (numl[i] != newl[i])
      return false;
  }
  return true;
}

void printline(int *line, int n) {
  std::cout << "printline:" << std::endl;
  for (int i = 0; i < n; i++) {
    std::cout << line[i] << " ";
  }
  std::cout << std::endl;
}

int main() {
  int n;
  while (cin >> n, n) {
    int numl[n], newl[n], ans = 0;
    mii counter;

    for (int i = 0; i < n; i++) {
      cin >> numl[i];
      if (counter.find(numl[i]) == counter.end()) {
        counter[numl[i]] = 1;
      } else {
        counter[numl[i]]++;
      }
    }

    while (!check(newl, numl, n)) {
      ans++;
      for (int i = 0; i < n; i++) {
        newl[i] = numl[i];
        numl[i] = counter[numl[i]];
      }

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

      for (int i = 0; i < n; i++) {
        counter[numl[i]]++;
      }

      // printline(numl, n);
    }
    std::cout << ans - 1 << std::endl;
    for (int i = 0; i < n; i++) {
      std::cout << newl[i] << " ";
    }
    std::cout << std::endl;
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;

bool mani(int a[12], int n) {
  int b[12];
  fill(b, b + 12, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i] == a[j])
        b[i]++;
  bool f = true;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      f = false;
      break;
    }
  }
  for (int i = 0; i < n; i++)
    a[i] = b[i];
  return f;
}

int main() {
  int n, a[12];
  while (cin >> n && n != 0) {
    int c = 0;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    while (true) {
      if (mani(a, n))
        break;
      c++;
    }
    cout << c << endl;
    cout << a[0];
    for (int i = 1; i < n; i++)
      cout << " " << a[i];
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;

bool mani(int a[12], int n) {
  int b[12];
  fill(b, b + 12, 0);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++)
      if (a[i] == a[j])
        b[i]++;
  bool f = true;
  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      f = false;
      break;
    }
  }
  for (int i = 0; i < n; i++)
    a[i] = b[i];
  return f;
}

int main() {
  int n, a[12];
  cin >> n;
  while (true) {
    int c = 0;
    a[1] = -1;
    for (int i = 0; i < n; i++)
      cin >> a[i];
    if (a[0] == 0 && a[1] == -1)
      break;
    while (true) {
      if (mani(a, n))
        break;
      c++;
    }
    cout << c << endl;
    cout << a[0];
    for (int i = 1; i < n; i++)
      cout << " " << a[i];
    cout << endl;
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Runtime Error

//	created : 15/12/27
// 	autor   : Rp7rf
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>

using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, a, b) for (int i = 0; i < a; i++)
#define vi vector<int>

int main(void) {
  int n;
  while (cin >> n, n) {
    vi in(n), l(n);
    int ret = 0;
    rep(i, n) cin >> in[i];
    while (true) {
      // rep(i,n)cout<<in[i]<<" ";cout<<endl;
      /*
      int cnt[13];
      rep(i,13)cnt[i]=0;
      rep(i,n)cnt[in[i]]++;
      rep(i,n)in[i] = cnt[in[i]];
      */
      rep(i, n) {
        l[i] = 0;
        rep(j, n) l[i] += (in[i] == in[j]);
      }
      if (in == l)
        break;
      ret++;
      in = l;
    }
    cout << ret << endl;
    rep(i, n - 1) cout << in[i] << " ";
    cout << in[n - 1] << endl;
  }
}

Error: 0

Fixed submission:

//	created : 15/12/27
// 	autor   : Rp7rf
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <vector>

using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
#define loop(i, a, b) for (int i = 0; i < a; i++)
#define vi vector<int>

int main(void) {
  int n;
  while (cin >> n, n) {
    vi in(n), l(n);
    int ret = 0;
    rep(i, n) cin >> in[i];
    while (true) {
      // rep(i,n)cout<<in[i]<<" ";cout<<endl;
      int cnt[13];
      rep(i, 13) cnt[i] = 0;
      rep(i, n) cnt[in[i]]++;
      rep(i, n) in[i] = cnt[in[i]];
      if (in == l)
        break;
      ret++;
      l = in;
    }
    cout << ret << endl;
    rep(i, n - 1) cout << in[i] << " ";
    cout << in[n - 1] << endl;
  }
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  vector<int> vi, vi2;
  while (cin >> n) {
    vi.clear();
    vi2.clear();
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      int j;
      cin >> j;
      vi.push_back(j);
    }
    int counter = -1;
    do {
      vi2.clear();
      copy(vi.begin(), vi.end(), back_inserter(vi2));
      for (int i = 0; i < n; i++) {
        vi[i] = count(vi2.begin(), vi2.end(), vi[i]);
      }
      counter++;
    } while (!equal(vi.begin(), vi.end(), vi2.begin()));
    cout << counter << endl;
    for (int i = 0; i < vi.size(); i++) {
      if (i != 0)
        cout << " ";
      cout << vi[i];
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  vector<int> vi, vi2;
  while (cin >> n) {
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      int j;
      cin >> j;
      vi.push_back(j);
    }
    int counter = -1;
    do {
      vi2.clear();
      copy(vi.begin(), vi.end(), back_inserter(vi2));
      for (int i = 0; i < n; i++) {
        vi[i] = count(vi2.begin(), vi2.end(), vi[i]);
      }
      counter++;
    } while (!equal(vi.begin(), vi.end(), vi2.begin()));
    cout << counter << endl;
    for (int i = 0; i < vi.size(); i++) {
      if (i != 0)
        cout << " ";
      cout << vi[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00108 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>

using namespace std;

bool check(int a[12], int b[12], int n) {
  bool f = true;

  for (int i = 0; i < n; i++) {
    if (a[i] != b[i]) {
      f = false;
      break;
    }
  }

  return f;
}

int main() {
  int n;

  while (cin >> n && n) {
    int a[12], b[10000], c[12], t = 0, s;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    fill(c, c + n, -1);
    while (1) {
      fill(b, b + 10000, 0);
      for (int i = 0; i < n; i++) {
        b[a[i]]++;
      }
      s = 1;
      for (int i = 1; i <= n; i++) {
        s = max(b[s], b[i]);
      }
      if (check(a, c, n)) {
        break;
      }

      for (int i = 0; i < n; i++) {
        c[i] = a[i];
        a[i] = b[a[i]];
      }
      t++;
    }

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

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

bool check(int a[13], int n) {
  for (int i = 1; i < n; i++) {
    if (a[i] != a[0]) {
      return true;
    }
  }

  return false;
}

int main() {
  int a[13], b[13], d[13], n;
  bool c[13];

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

    int s = 0, t;
    while (check(a, n)) {
      fill(b, b + 13, 0);
      fill(c, c + 13, false);
      for (int i = 0; i < n; i++) {
        if (!c[a[i]]) {
          for (int j = 0; j < n; j++) {
            if (a[i] == a[j]) {
              b[a[i]]++;
            }
          }
        }
        d[i] = b[a[i]];
        c[a[i]] = true;
      }

      for (int i = 0; i < n; i++) {
        t = a[i];
        a[i] = d[i];
        d[i] = t;
      }
      s++;
    }
    cout << s << endl;
    cout << d[0];
    for (int i = 1; i < n; i++) {
      cout << " " << d[i];
    }
    cout << endl;
  }

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

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

void f(std::vector<int> &vector, const int &count = 0) {
  bool flag = true;
  std::map<int, int> freq;
  for (const auto &i : vector) {
    if (freq.find(i) == freq.end()) {
      freq[i] = 1;
    } else {
      ++freq.at(i);
    }
  }
  for (auto &i : vector) {
    flag = (i == freq.at(i)) && flag;
    i = freq.at(i);
  }
  if (flag) {
    std::cout << count << "\\n";
    for (auto i = 0; i < vector.size() - 1; ++i) {
      std::cout << vector.at(i) << " ";
    }
    std::cout << vector.back() << "\\n";
  } else {
    f(vector, count + 1);
  }
}
int main() {
  int n;
  std::cin >> n;
  while (n != 0) {
    std::vector<int> vec(n);
    for (auto &i : vec) {
      int temp;
      std::cin >> temp;
      i = temp;
    }
    f(vec);
    std::cin >> n;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

void f(std::vector<int> &vector, const int &count = 0) {
  bool flag = true;
  std::vector<int> freq(12, 0);
  for (const auto &i : vector) {
    ++freq.at(i - 1);
  }
  for (auto &i : vector) {
    flag = (i == freq.at(i - 1)) && flag;
    i = freq.at(i - 1);
  }
  if (flag) {
    std::cout << count << "\\n";
    for (auto i = 0; i < vector.size() - 1; ++i) {
      std::cout << vector.at(i) << " ";
    }
    std::cout << vector.back() << "\\n";
  } else {
    f(vector, count + 1);
  }
}
int main() {
  int n;
  std::cin >> n;
  while (n != 0) {
    std::vector<int> vec(n);
    for (auto &i : vec) {
      int temp;
      std::cin >> temp;
      i = temp;
    }
    f(vec);
    std::cin >> n;
  }
  return 0;
}