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>
using namespace std;
int n,t,s[100],sa[100];
void angel(int turn){
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int o=0;o<n;o++){
            if(sa[i]==sa[o]){
                cnt++;
            }
        }
        s[i]=cnt;
        cnt=0;
    }
    int check=0;
    for(int i=0;i<n;i++){
        if(s[i]!=sa[i]){
            check=1;
        }
    }
    if(check==0){
        t=turn;
    }
    else{
        for(int i=0;i<n;i++){
            sa[i]=s[i];
        }
        angel(turn+1);
    }
}
int main(void){
    cin>>n;
    while(n!=0){
        for(int i=0;i<n;i++){
            cin>>s[i];
            sa[i]=s[i];
        }
        angel(0);
        cout<<t<<endl;
        for(int i=0;i<n;i++){
            cout<<s[i]<<' ';
        }
        cout<<endl;
        cin>>n;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>

using namespace std;

int ans;
vector<int> ANS;

void func(vector<int> s,int N){
	vector<int> copy;
	for(int i = 0; i < s.size(); i++){
		copy.push_back(0);
	}
	for(int i = 0; i < s.size(); i++){
		for(int j = 0; j < s.size(); j++){
			if(s[i] == s[j]){
				copy[i]++;
			}
		}
	}
	if(copy==s){
		ans = N;
		ANS = copy;
		return;
	}
	func(copy,N+1);
}
				


int main(){
	int n;
	
	while(scanf("%d", &n) && n){
		vector<int> S;
		int temp;
		
		for(int i = 0 ; i < n ;i++){
			scanf("%d", &temp);
			S.push_back(temp);
		}
		func(S,0);
		printf("%d\n",ans);
		for(int i = 0; i < S.size(); i++){
			printf("%d",ANS[i]);
			if(i != S.size()-1)printf(" ");
		}puts("");
		
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    //*/
    int flag = 1;
    int n; cin >> n;
    while (n != 0) {
        int count = 0;
        int p[n];
        int q[101] = {0};
        rep(i, n) {
            cin >> p[i];
        }

        while (flag == 1){
            flag = 0;
            fill(q, q+101, 0);
            rep(i, n) q[p[i]]++;
            //rep(i, n) cout << q[p[i]] << " ";
            for (int i = 0; i < n-1; i++) {
                if (p[i] != q[p[i]]) flag = 1;
            }
            rep(i ,n) p[i] = q[p[i]];
            count++;
        }
        rep(i, n-1) cout << q[p[i]] << " ";
        cout << q[p[n-1]] << endl;
        cout << count-1 << endl;
        cin >> n;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>

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;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    while(cin >> n){
        if(!n) break;

        vector<int> s(n),t(n);
        map<int,int> memo;
        rep(i,n) cin >> s[i];

        int cnt = 0;
        bool ok = true;
        while(ok){
            memo.clear();
            rep(i,n) memo[ s[i] ]++;
            rep(i,n) t[i] = memo[ s[i] ]; 
            if(s == t) break;
            s = t; cnt++;
        }
        cout << cnt << endl;
        rep(i,n-1) cout << t[i] << " ";
        cout << t[n-1] << endl;
    }

    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int a,n,i,j;
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		int array[20]={0};
		int array2[20]={0};
		int num[20]={0};
		int conv[20]={0};
		
		for(i=1;i<n+1;i++)
		{
			cin >> a ;
			array[a]++;
			num[i]=array2[i]=a;
		}
		
		for(j=0;;j++)
		{
			for(i=0;i<13;i++)
				conv[i]=0;
				
			for(i=1;i<13;i++)
			{
/*////////////////////////////////////////////////////////
			for(int ci=1;ci<13;ci++)
			{
				cout << num[ci] << " " ;
			}
				cout << endl;
			for(int ki=1;ki<13;ki++)
			{
				cout << array[ki] << " " ;
			}
				cout << endl;
				cout << endl;
////////////////////////////////////////////////////////*/
				if(array[i]!=0)
				{
					for(int k=1;k<13;k++)
					{
						if(num[k]==i && conv[k]==0)
						{
							num[k]=array[i];
							conv[k]=1;
						}
					}
					array[i]=0;
				}
			}
			for(i=1;i<13;i++)
			{
				array[num[i]]++;
			}
			
			for(i=1;i<13;i++)
			{
				if(array2[i]!=num[i])
					break;
			}
			if(i==13)
				break;
			
			for(i=1;i<13;i++)
				array2[i]=num[i];
			
		}
		cout << j << endl;
		
		int first=1;
		
		for(i=0;i<13;i++)
		{
			
			if(num[i]!=0 && first==1)
			{
				cout << num[i] ;
				first=0;
			}
			else if(num[i]!=0)
				cout << " " << num[i] ;
		}
		cout << endl;
	}
}

/*
12
2 7 1 8 2 8 1 8 2 7 9 9
*/

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


int main(){
  while(true){
    int n;
    cin >> n; 
    if(n == 0)break;
    int s[2][n];
    for(int i=0;i<n;i++)cin >> s[0][i];
    int cnt = 0;
    while(true){
      for(int i=0;i<n;i++)s[1][i] = count(s[0],s[0]+n,s[0][i]);
      bool fin = true;
      for(int i=0;i<n;i++){
	if(s[1][i] != s[0][i])fin = false;
	s[0][i] = s[1][i];
      }
      if(fin)break;
      cnt++;
    }
    cout << cnt << endl;
    for(int i=0;i<n;i++){
      cout << s[0][i];
      i==n-1?cout << endl:cout << ' ';
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#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;
	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;
	}
}