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<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
using namespace std;

int a,c[20],d[20];
int main(){
  while(true){
    for(int i=0;i<20;i++) 
      {c[i]=0;d[i]=0;}
    cin>>a;
    if(a==0){break;}
    for (int i=0;i<a;i++){
      cin>>c[i];
    }
    int meta=0;
    while(true){
      for(int i=0;i<a;i++){
	for(int j=0;j<a;j++){ 
	  if(c[i]==c[j]){
	    d[i]++;
	  }
	}
      }
      int k=0;
      for(int i=0;i<a;i++){
	if(c[i]==d[i]){
	  k++;
	}
	c[i]=d[i];
	d[i]=0;
      }
 
      if(k>a-1){break;}
      meta++;
    }
    printf("%d\n",meta);
    for(int i=0;i<a;i++){
      printf("%d",c[i]);
      if(i!=a-1){printf(" ");}
    }
    printf("\n");
    
  }
}

C++: #include <iostream>
#include <cstring>

using namespace std;

int main(int argc, char *argv[]) {
  int *num, *hoge, n;
  num = new int[12];
  hoge = new int[12];
  while (true) {
    cin >> n;
    if (!n)
      break;
    for (int i = 0; i < n; i++)
      cin >> num[i];

    int time = 0;
    while (true) {
      memset(hoge, 0, sizeof(int) * 12);
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          if (num[i] == num[j])
            hoge[i]++;
      if (!memcmp(num, hoge, sizeof(int) * 12))
        break;
      int *tmp = hoge;
      hoge = num;
      num = tmp;
      time++;
    }

    cout << time << endl;
    for (int i = 0; i < n; i++) {
      if (i)
        cout << ' ';
      cout << num[i];
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int n;
  while(cin >> n && n) {
    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int cnt=0;
    while(1) {
      map<int,int> m;
      for(int i=0; i<n; i++) {
	m[a[i]]++;
      }
      bool ck=true;
      for(int i=0; i<n; i++) {
	if(a[i]!=m[a[i]]) ck=false;
	a[i]=m[a[i]];
      }
      if(ck) break;
      cnt++;
    }
    cout << cnt << endl;
    for(int i=0; i<n; i++) {
      if(i!=0) cout << " ";
      cout << a[i];
    }
    cout << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n;
	while(true){
	cin>>n;
	if(n==0){break;}
	int *a=new int[n];
	map<int,int>Map;
	rep(i,n){
		cin>>a[i];
	}
	for(int count=0;;count++){
		rep(i,n){
			Map[a[i]]++;
		}
		int *s=new int[n];
		rep(i,n){
			s[i]=Map[a[i]];
		}
		if(a==s){cout<<count<<endl;break;}
		rep(i,n){	
			s[i]=a[0];
		}
		  
	}
	for(int i=0;i<n;i++){
		if(i!=0){
		cout<<" ";
		}
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>

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[13], 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+13, 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;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
signed main(){
   int a;
   while(cin>>a,a){
       int c[100];
       for(int b=0;b<a;b++)cin>>c[b];
       int s=0;
       while(1){
	  int d[100];
	  map<int,int>e;
	  for(int f=0;f<a;f++)e[c[f]]++;
	  for(int f=0;f<a;f++)d[f]=e[c[f]];
	  for(int f=0;f<a;f++){if(c[f]!=d[f])break;if(a-f==1)goto l;}
	  for(int f=0;f<a;f++)c[f]=d[f];
	  s++;
	   }
	l:; 
	cout<<s<<endl;
	for(int f=0;f<a-1;f++)cout<<c[f]<<" ";
	 cout<<c[a-1]<<endl;
       }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[1000]={},kawa[1000];
        for(int i=0;i<n;i++)cin>>kawa[i];
        for(int i=0;;i++){
            int num[1000]={};
            for(int j=0;j<n;j++)num[kawa[j]]++;
            bool rever=0;
            for(int j=0;j<n;j++){
                kawa[j]=num[kawa[j]];
                if(kawa[j]!=ans[j])rever=1;
            }
            if(!rever){
                cout<<i<<endl<<kawa[0];
                for(int j=0;j<n;j++)cout<<" "<<kawa[j];
                cout<<endl;
                break;
            }
            else for(int j=0;j<n;j++)ans[j]=kawa[j];
        }
    }
}

C++: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    int ans = 0;
    while (true) {
      int cnt[110] = {};
      vector<int> ns(n);
      for (int i = 0; i < n; i++) {
        cnt[s[i]]++;
      }
      for (int i = 0; i < n; i++) {
        ns[i] = cnt[s[i]];
      }
      if (s == ns) break;
      ans++;
      swap(s, ns);
    }
    cout << ans << endl;
    for (int i = 0; i < n; i++) {
      cout << s[i] << " \n"[i + 1 == n];
    }
  }

  return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)

int main() {
  for (int N; cin >> N && N; ) {
      vector<int> a(N);
      REP(i, N) cin >> a[i];

      int ans = 0;
      map<int, int> count;
      for (;;) {
          count.clear();
          REP(i, N) ++count[a[i]];
          vector<int> b(N);
          REP(i, N) b[i] = count[a[i]];

          if (a == b) break;
          ans++;
          a = b;
      }
      cout << ans << endl;
      cout << a[0];
      for (int i = 1; i < N; i++) cout << " " << a[i]; cout << endl;

  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n){
    int a[n],b[n];
    r(i,n)cin>>a[i];
    r(o,114514){
      multiset<int>s;
      r(i,n)b[i]=a[i],s.insert(a[i]);
      r(i,n)a[i]=s.count(a[i]);
      int c=0;
      r(i,n)if(b[i]!=a[i])c++;
      if(!c){
        cout<<o<<endl;
        r(i,n){
          if(i)cout<<' ';
          cout<<a[i];
        }
        cout<<endl;
        goto L;
      }
    }L:;
  }
}