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++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
vector<int> next(vector<int>v) {
	vector<int>c(101, 0);
	rep(i, 0, v.size()) {
		c[v[i]]++;
	}
	vector<int>res;
	rep(i, 0, v.size()) {
		res.push_back(c[v[i]]);
	}
	return res;
}
signed main() {
	int n; cin >> n; vector<int>v(n); rep(i, 0, n)cin >> v[i];
	vector<int>c(101, 0);
	rep(i, 0, n) c[v[i]]++;
	set<vector<int>>S; S.insert(v);
	int cnt(0);
	while (1) {
		v = next(v);
		if (S.find(v) != S.end()) {
			break;
		}
		else S.insert(v);
		cnt++;
	}
	cout << cnt << endl;
	rep(i, 0, v.size()) cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');

	return 0;
}

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

int n ;
int m[13] , ans[13] ;

void f( int p ){
	int t ;
	
	for( int i=0 ; i<n ; i++ ){
		t=0 ;
		for( int j=0 ; j<n ; j++ ){
			if( m[i] == m[j] ){
				t++ ;
			}
		}
		ans[i] = t ;
	}
	
	int q=0 ;
	for( int i=0 ; i<n ; i++ ){
		if( m[i] == ans[i] ) q++ ;
	}
	
	if( q == n ){
		cout << p << endl ;
		for( int i=0 ; i<n ; i++ ){
			if( i != 0 ) cout << ' ' ;
			cout << ans[i] ;
		}
		cout << endl ;
	}else {
		swap( m , ans ) ;
		f(p+1) ;
	}
}

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

C++: #include <iostream>
#include <stdio.h>

using namespace std;

int main(){
	int n[12],N,p[12],pc[12],pp[12],t,c=0,flg;

	while(1){
		cin >> N;

		if(N==0)break;

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

		while(1){
			c++;
			flg=0;

			if(c==10)break;

			//initialize counter
			for(int j=0;j<N;j++){
				pc[j] = 0;
			}

			//count
			for(int i=0;i<N;i++){
				//pick up
				t = n[i];

				for(int j=0;j<N;j++){
					if(t==n[j]){
						pc[i]++;
					}
				}
			}

			//judge
			for(int i=0;i<N;i++){
				if(n[i]!=pc[i]){
					flg=1;
				}
			}

			//if made p[]
			if(flg==0){
				break;
			}

			for(int i=0;i<N;i++){
				n[i] = pc[i];
			}
		}

		c--;

		cout << c << endl;
		for(int i=0;i<N-1;i++){
			cout << pc[i] << " ";
		}
		cout << pc[N-1] << endl;

		c=0;
	}

	return 0;
}

C++: #include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)


int main(){
	int n,cnt,f;
	int d[12];
	map<int,int> s;
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		cnt=0;
		rep(i,n)scanf("%d",d+i);
		for(;;cnt++){
			s.clear();
			rep(i,n)s[d[i]]++;
			f=1;
			rep(i,n)if(s[d[i]]!=d[i])f=0;
			if(f)break;
			rep(i,n)d[i]=s[d[i]];
			//break;
		}
		printf("%d\n",cnt);
		rep(i,n)printf("%d%c",d[i],i==n-1?'\n':' ');
	}
	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n&&n){
    vary(int,v,n,0);
    vary(int,v2,n,0);
    rep(i,n){
      cin >> v[i];
    }
    int ans = 0;
    while(1){
      map<int,int> m;
      v2 = v;
      rep(i,n){
        m[v[i]]++;
      }
      rep(i,n){
        v[i] = m[v[i]];
      }
      if(v == v2){
        cout << ans << endl;
        rep(i,n-1){
          cout << v2[i] << " ";
        }
        cout << v[n-1]<< endl;
        break;
      }
      ++ans;
    }
  }
  return 0;
}

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

using namespace std;

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

int main(int argc, char **argv)
{
	int n, *a, *b, *c, s;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (int *)calloc(n+1, sizeof(int));
		b = (int *)calloc(n+1, sizeof(int));
		c = (int *)calloc(13, sizeof(int));
		for(int i = 0; i < n; i++){
			cin >> a[i];
			c[a[i]]++;
		}
		for(int i = 0; i < n; i++){
			b[i] = a[i];
			a[i] = c[a[i]];
		}
		s = 0;
		while(func(a, b, n)){
			for(int i = 0; i < n; i++){
				b[i] = a[i];
				a[i] = c[a[i]];
			}
			for(int i = 0; i < n; i++){
				c[i] = 0;
			}
			for(int i = 0; i < n; i++){
				c[a[i]]++;
			}
			s++;
		}
		s--;
		cout << s << endl;
		for(int i = 0; i < n-1; i++){
			cout << a[i] << " ";
		}
		cout << a[n-1] << endl;
		
		free(c);
		free(b);
		free(a);
	}
	
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>

vector<int> check(int n, vector<int> v){
  vector<int> ret(n);
  REP(i, n){
    int cnt = 0;
    REP(j, n) if(v[i] == v[j]) cnt++;
    ret[i] = cnt;
  }
  return ret;
}

int main() {
  int n;
  while(cin >> n && n){
    vector<int> v(n);
    REP(i, n) cin >>v[i];
    int cnt = 0;
    vector<int> next = check(n, v);
    while(v != next){
      cnt++;
      v = next;
      next = check(n, v);
    }
    cout <<cnt <<endl;
    stringstream ss;
    ss << v[0];
    FOR(i, 1, v.size()) ss <<" " <<v[i];
    cout <<ss.str() <<endl;
  }
  return 0;
}