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 <bits/stdc++.h>
#define MAX_N 15
using namespace std;

int data[MAX_N];
int n;

void print() {
    for(int r = 0; r < n; r++) {
        printf("%d", data[r]);
        if(r == n - 1) putchar('\n');
        else putchar(' ');
    }
    putchar('\n');
}

bool judge() {
    for(int r = 0; r < n; r++) {
        if(count(data, data+n, data[r]) != data[r]) return(false);
    }
    return(true);
}

void convert() {
    int tmp[n];
    for(int r = 0; r < n; r++) {
        tmp[r] = (int)count(data,data+n,data[r]);
    }
    memcpy(data, tmp, sizeof(tmp));
}

int solve() {
    int res = 0;
    do {
        convert();
        res++;
    }while(!judge());
    return(res);
}

int main(void) {
    while(cin >> n, n != 0) {
        for(int r = 0; r < n; r++) {
            cin >> data[r];
        }
        printf("%d\n", solve());
        print();
    }
    return(0);
}

C++: #include <bits/stdc++.h>
#define MAX_N 15
using namespace std;

int data[MAX_N];
int n;

//出力
void print() {
    for(int r = 0; r < n; r++) {
        printf("%d", data[r]);
        if(r == n - 1) putchar('\n');
        else putchar(' ');
    }
}

//不動点であるか判定
bool judge() {
    for(int r = 0; r < n; r++) {
        if(count(data, data+n, data[r]) != data[r]) return(false);
    }
    return(true);
}

//数列を変換
void convert() {
    int tmp[n];
    for(int r = 0; r < n; r++) {
        tmp[r] = (int)count(data,data+n,data[r]);
    }
    memcpy(data, tmp, sizeof(tmp));
}

int solve() {
    int res = 0;
    while(!judge()) {
        convert();
        res++;
    }
    return(res);
}

int main(void) {
    while(cin >> n, n != 0) {
        for(int r = 0; r < n; r++) {
            cin >> data[r];
        }
        printf("%d\n", solve());
        print();
    }
    return(0);
}

C++: #include<iostream>
#include<map>
using namespace std;
int main(void){

    int n;

    while(cin>>n){
        if(n==0)break;
        int a[13];
        map<int,int> b;
        int c[13];
        for(int i=0;i<n;i++){
            cin>>a[i];
            b[a[i]]++;
        }
        int j=0;
        while(1){

            bool flg = false;
            for(int i=0;i<n;i++){
                c[i] = b[a[i]];
                if(c[i]!=a[i])flg = true;
                //cout<<c[i]<<" ";
            }
            //cout<<endl;
            if(!flg)break;
            b.clear();
            for(int k=0;k<n;k++){
                a[k] = c[k];
                b[a[k]]++;
            }
            j++;
        }
        cout<<j<<endl;
        bool f = false;
        for(int i=0;i<n;i++){
            if(f)cout<<" ";
            cout<<c[i];
            f = true;
        }
        cout<<endl;

    }

    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;cin>>n,n;){
		vi a(n),b(n);
		rep(i,n)
			cin>>a[i];
		for(int i=0;;i++,a=b){
			map<int,int> c;
			rep(j,n)
				c[a[j]]++;
			rep(j,n)
				b[j]=c[a[j]];
			if(a==b){
				cout<<i<<endl;
				rep(j,n)
					cout<<b[j]<<(j==n-1?'\n':' ');
				break;
			}
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int main(){
long n,a[13],b[13],i,j,k,m;
while(cin>>n){
if(n==0)break;
m=0;
for(i=0;i<n;i++)cin>>a[i];
for(;;){
for(i=0;i<n;i++){
for(k=0,j=0;j<n;j++)if(a[i]==a[j])k++;
b[i]=k;
}
for(i=0;i<n;i++)if(a[i]!=b[i])break;
if(i!=n)m++;else break;
for(i=0;i<n;i++)a[i]=b[i];
}
cout<<m<<endl;
cout<<b[0];
for(i=1;i<n;i++)cout<<" "<<b[i];
cout<<endl;
}
return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

bool isSame(int n,int a[],int b[]){
	bool ans = true;
	for(int i=0;i<n;i++) if(a[i]!=b[i]) ans = false;
	return ans;
}

int main(){
	int N;
	while(cin>>N,N){
		int S[12];
		for(int i=0;i<N;i++) cin>>S[i];
		for(int i=0;;i++){
			int S_[12];
			for(int j=0;j<N;j++){
				int n = S[j], cnt = 0;
				for(int k=0;k<N;k++){
					if(n==S[k]) cnt++;
				}
				S_[j] = cnt;
			}
			if(isSame(N,S,S_)){
				printf("%d\n%d",i,S[0]);
				for(int j=1;j<N;j++) printf(" %d",S[j]); puts("");
				break;
			}
			memcpy(S,S_,sizeof(S));
		}
	}
}

C++: #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 30;

int a[2][12];

bool check(int n){
	rep(i,n)
		if(a[0][i]!=a[1][i])
			return true;
	return false;
}

int main(void){
	int n;
	while(cin >> n,n){
		rep(i,n)
			cin >> a[1][i];
		int ans=-1;
		while(check(n)){
			rep(i,n)
				a[0][i]=a[1][i];
			vi tmp;
			rep(i,n)
				tmp.pb(a[0][i]);
			sort( tmp.begin(),tmp.end());
			rep(i,n)
				a[1][i]=upper_bound(tmp.begin(),tmp.end(),a[0][i])-lower_bound(tmp.begin(),tmp.end(),a[0][i]);
			ans++;
		}
		cout << ans << endl;
		rep(i,n)
			cout << (i?" ":"") << a[1][i];
		cout << endl;
	}
	return 0;
}