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 <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

void freqApp (vector <int> s, vector <int>& p )
{
	int size = s.size();
	map <int, int> count;
	int i;

	for (i = 0; i < size; ++i){
		++count[s[i]];
	} // end for

	for (i = 0; i < size; ++i){
		p[i] = count[s[i]];
	} // end for
}

bool isfixpoint (vector <int> s, vector <int> p )
{
	int size = s.size();
	int i;

	for (i = 0; i < size; ++i){
		if (s[i] == p[i] ){
			continue;
		}else{
			return false;
		} // end if
	} // end for

	return true;
}

void disp_array (vector <int> a )
{
	int size = a.size();
	int i;

	for (i = 0; i < size; ++i){
		cout << a[i];
		if (i != size - 1){
			cout << ' ';
		} // end if
	} // end for
	cout << endl;
}

int main()
{
//	cut here before submit 
//	freopen("testcase.ofa", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){
		int n;
		stringstream ssn(str);
		ssn >> n;
		
		if (n == 0 ){
			break;
		} // end if
		
		vector <int> s (n, 0 );
		vector <int> p (n, 0 );
		int count = 0;
		int i;

		getline (cin, str );
		stringstream ss (str );

		for (i = 0; i < n; ++i){
			ss >> s[i];
		} // end for

		while (1){
			freqApp (s, p ); 
//			cout << "s: "; disp_array (s );
//			cout << "p: "; disp_array (p );

			if (isfixpoint (s, p ) ){
				break;
			} // end if
			++count;
			s = p;
		} // end while
		
		cout << count << endl;
		for (i = 0; i < p.size(); ++i){
			cout << p[i];
			if (i != p.size() - 1){
				cout << ' ';
			} // end if
		} // end for
		cout << endl;
	} // end loop
		
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int a[100];
	int d[21];
	int n;
	cin >> n;
	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 <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

bool check(vector<int> &a,vector<int> &b)
{
	if(a.size()!=b.size())return true;
	for(int i=0;i<a.size();i++)if(a[i]!=b[i])return true;
	return false;
}

int main()
{
	int n;
	while(cin>>n&&n)
	{
		vector<int> a,b;
		for(int i=0;i<n;i++)
		{
			int x;
			cin>>x;
			a.push_back(x);
		}
		int ans;
		for(ans=-1;check(a,b);ans++)
		{
			b.clear();
			for(int i=0;i<a.size();i++)
			{
				b.push_back(count(a.begin(),a.end(),a[i]));
			}
			swap(a,b);
		}
		cout<<ans<<endl;
		for(int i=0;i<a.size();i++)
		{
			cout<<(i==0?"":" ")<<a[i];
		}
		cout<<endl;
	}
}

C++: #include <iostream>
#define MAX_N 15
using namespace std;
int n,m=0,cnt,flag,change=0;
int s[MAX_N],p[MAX_N];

int main(){
	while(1){
		cin >> n;
		if(n==0)break;
		m=0;
		while(m!=n){
			cin >> s[m];
			m++;
		}
		change=0;
		while(1){
			for(int i=0;i<n;i++){
				cnt=0;
				for(int j=0;j<n;j++){
					if(s[i]==s[j])cnt++;
				}
				p[i]=cnt;
			}
			flag=0;
			for(int i=0;i<n;i++){
				if(s[i]==p[i])flag++;
				s[i]=p[i];
			}
			if(flag==n)break;
			change++;
		}
		cout <<change <<endl;
		for(int i=0;i<n-1;i++){
			cout << s[i]<<" ";
		}
		cout <<s[n-1]<<endl;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int n,t,s[100],sa[100];
void angel(int turn){
    int cnt;
    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>
using namespace std;

int main(){
	int n, a[12], b[12], in, sum, kaisu;
	while(cin >> n){
		if (n == 0) { break; }
		for(int i = 0;i<12;i++){
			if (i < n) { cin >> a[i]; }
			else { a[i] = 0; }
		}
		kaisu = 0;
		while(true){
			sum = 0;
			for(int i = 0;i<n;i++){
				b[i] = 0;
				for(int j = 0;j<n;j++){
					if (a[i] == a[j]) { b[i]++; }
				}
				if (a[i] == b[i]) { sum++; }
			}
			for(int i = 0;i<n;i++){
				a[i] = b[i];
			}
			if (sum == n) { break; }
			kaisu++;
		}
		cout << kaisu << endl
			<< a[0];
		for(int i = 1;i<n;i++){
			cout << " " << a[i];
		}
		cout << endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int a[20],b[20];
int res;
int n;

void f(){
//for(i=0;i<n-1;i++)cout<<a[i]<<" ";
//cout<<a[n-1]<<endl;
	int i,j;
	bool ok=true;
	for(i=0;i<n;i++){
		b[i]=0;
		for(j=0;j<n;j++){
			if(a[i]==a[j])b[i]++;
		}
		if(a[i]!=b[i])ok=false;
	}
	if(ok){
		cout<<res<<endl;
		for(i=0;i<n-1;i++)cout<<a[i]<<" ";
		cout<<a[n-1]<<endl;
	}else{
		res++;
		for(i=0;i<n;i++)a[i]=b[i];
		f();
	}
}

int main() {
	while(n=in()){
		int i;
		for(i=0;i<n;i++){
			cin>>a[i];
		}
		res=0;
		f();
	}
	return 0;
}