Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	for stdin.Scan() {
		n, _ := strconv.Atoi(stdin.Text())
		if n == 0 {
			break
		}
		stdin.Scan()
		res := stdin.Text()
		prev := ""
		c := 0
		for ; res != prev; c++ {
			elm := strings.Split(res, " ")
			cnt := make(map[string]int)
			nxt := make([]string, n)
			for _, v := range elm {
				cnt[v]++
			}
			for i, v := range elm {
				nxt[i] = strconv.Itoa(cnt[v])
			}
			prev = res
			res = strings.Join(nxt, " ")
		}
		if res == prev {
			fmt.Println(c - 1)
			fmt.Println(res)
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    auto f = [](vector<int> v){
        map<int, int> m;
        for (auto &&i : v) m[i]++;
        for (auto &&i : v) i = m[i];
        return v;
    };
    int n;
    while(cin >> n, n){
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        int ans = 0;
        while(true){
            auto u = f(v);
            if(u == v) break;
            v = u;
            ans++;
        }
        cout << ans << "\n";
        for (int i = 0; i < n; ++i) {
            if(i) printf(" ");
            printf("%d", v[i]);
        }
        puts("");
    }
    return 0;
}

C++: #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;
	}
}

C++: #include <iostream>
using namespace std;

int main() {
  int n;
  while(cin >> n) {
    int s[10000] = {0},c[10000] = {0},c2[10000] = {0},k,check=1;
    if(n==0)break;

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

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

    //ok
    k=0;
    while(check){
      check = 0;
      k++;
      int c2[10000] = {0};
      for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
          if(c[i] == c[j]) {
            c2[i]++;
          }
        }
      }
      /*
        for(int l=0;l<n;l++) {
        cout << c[l] << " " << c2[l] << endl;
        }
        k++;
      */
      for(int i=0;i<n;i++) {
        if(c2[i] != c[i]) {
          for(int j=0;j<n;j++) {
            c[j] = c2[j];
          }
          check = 1;

        }
      }

    }

    cout << k << endl;
    for(int i=0;i<n;i++) {
      cout << c[i] << " ";
    }
    cout << "\b" << endl;
  }
}

C++: #include <iostream>
#include <vector>
using namespace std;

int n = 0;
int counter = 0;

vector<int> operation_of_fa(const vector<int> num_seq);

int main()
{
	int num = 0;
	while (true) {
		cin >> n;
		if(n==0) break;
		vector<int> first_num_seq;
		for(int i=0;i<n;i++) {
			cin >> num;
			first_num_seq.push_back(num);
		}

		vector<int> operated_seq = operation_of_fa(first_num_seq);

		cout << counter << endl;
		for(int i=0; i<n; i++) 
			cout << operated_seq[i] << ' ';
		cout << endl;
	}
	return 0;
}


vector<int> operation_of_fa(const vector<int> num_seq)
{
	int frequency = 0;
	vector<int> operated_seq;
	for (int i=0;i<n;i++) {
		frequency = 0;
		for (int j=0;j<n;j++) 
			if (num_seq[i] == num_seq[j])
				frequency++;
		operated_seq.push_back(frequency);
	}
	
	if (num_seq != operated_seq) {
		counter++;
		return operation_of_fa(operated_seq);
	}
	else
		return operated_seq;
}

C++: #include<bits//stdc++.h>
#include<iostream>
#include<string>
using namespace std;
int main() {
 int n;
 while (cin >> n&&n != 0) {
  int a[105];
  int d[21];
  string b[2] = { "","" }, e;
  for (int i = 0; i < n; i++) {
   cin >> a[i];
   e = to_string(a[i]);
   b[1] += e;
  }
  int sum = 0;
  while (b[0] != b[1]) {
   int y = 0;
   int x = 1;
   for (int i = 0; i < 20; i++)
    d[i] = 0;
   for (int i = 0; i < n; i++)
    d[a[i]]++;
   b[y] = "";
   for (int i = 0; i < n; i++) {
    a[i] = d[a[i]];
    e = to_string(a[i]);
    b[y] += e;
   }
   sum++;
   swap(b[0], b[1]);
  }
  cout << sum - 1 << endl;
  for (int i = 0; i < n; i++) {
   if (i == 0)
    cout << a[i];
   else
    cout << " " << a[i];
  }
  cout << endl;
 }
}

C++: #include<stdio.h>
#include<math.h>
#include<string.h>

void sha(char *a, char *b, int k){
  int i;
  char w[101];
  for(i=0;i<101;i++)
    w[i]=0;
  for(i=0;i<k;i++){
    w[a[i]]++;
  }
  for(i=0;i<k;i++){
    b[i]=w[a[i]];
    //printf("%d ", b[i]);
  }
  //printf("\n");
}

int main(){
  int n;
  char ans[12];
  int an;
  while(1){
    char s[12];
    char p[12];
    char q[12];
    scanf("%d", &n);//printf("%d\n\n",n);
    char c;scanf("%c", &c);//printf("c:%c",c);
    if(n!=0){
      int i;
      for(i=0;i<n;i++){
	scanf("%d", &s[i]);
      }
      char v;scanf("%c", &v);//printf("v:%c",v);
    }
    else
      //{ printf("aa\n");break;}
      {break;}

    strcpy(p, s);
    int h=0;
    while(1){
      sha(p, q, n);
      if(strcmp(p, q)==0){
       	  strcpy(ans,p);
	  an=h;
	  printf("%d\n",an);
	  int d;
	  for(d=0;d<n;d++)
	    printf("%d ", ans[d]);
	  printf("\n");
	  break;}
      strcpy(p, q);
      h++;
    }
  }
  
  //printf("%d\n",an);
  //int i;
  //for(i=0;i<n;i++){
  //  printf("%d ", ans[i]);
  //}
  //printf("\n");
  
  /*int t;
  for(t=0;t<n-1;t++){
    printf("%d ", p[t]);
  }
  printf("%d\n", p[n-1]);*/

  
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;

int main(void){
    for(int n, cnt; cnt = -1, cin >> n, n; cout << endl){
        vi p(n); rep(i, n) cin >> p[i];
        vi pre;

        do{
            pre = p;
            rep(i, n) p[i] = count(ALL(pre), pre[i]);
            cnt ++;
        }
        while(p != pre);

        cout << cnt << endl;
        rep(i, n) cout << (i ? " ":"") << p[i];
    }
 
    return 0;
}