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

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

int main(){
  int n;
  while(std::cin>>n&&n){
    std::vector<int> s(n);
    std::vector<int> news(n);
    for(int &x:s) std::cin>>x;
    int count;
    for(count=0;;++count){
      for(int i=0;i<n;++i)
        news[i]=std::count(s.cbegin(),s.cend(),s[i]);
      if(news==s)break;
      s=news;
    }
    std::cout<<count<<std::endl;
    for(int i=0;i<n;++i)
      std::cout<<news[i]<<((i!=n-1)?' ':'\n');
  }
  return 0;
}

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

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

int main(){
  while(true){
    int n;
    cin>>n;
    if(!n)break;
    vi a(n);
    REP(i,n)cin>>a[i];
    int cnt = 0;
    vi b = a;
    while(true){
      REP(i,n) a[i] = count(ALL(b),b[i]);
      if(b==a)break;
      b=a;
      ++cnt;
    }
    cout<<cnt<<endl;
    cout<<b[0];
    REPR(i,n)cout<<" "<<b[i];
    cout<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

vector<int> solve(vector<int> v){
  map<int,int> cnt;
  rep(i,v.size()) cnt[v[i]]++;

  vector<int> res;
  rep(i,v.size()) res.push_back(cnt[v[i]]);
  return res;
}

int main(){
  int n;

  while(cin>>n,n){
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    int cnt = 0;

    while(1){
      vector<int> next = solve(v);
      if(next == v){
        break;
      }
      v = next;
      cnt++;
    }

    cout<<cnt<<endl;
    rep(i,n){
      if(i != 0) cout<<" ";
      cout<<v[i];
    }
    cout<<endl;
  }
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int n, p[16], t[16], ans;

	while(cin >> n, n){
		for(int i = 0;i < n; i++)
			cin >> p[i];

		for(ans = 0; ; ans++){
			for(int i = 0;i < n; i++){
				int cnt = 0;
				for(int j = 0;j < n; j++){
					//if(i == j) continue;
					if(p[i] == p[j]) cnt++;
				}
				//cout << cnt << endl;
				t[i] = cnt;
			}
			bool f = false;
			for(int i = 0;i < n; i++)
				if(p[i] != t[i]) f = true;
			if(!f) break;
			memcpy(p, t, sizeof(p));
		}
		cout << ans << endl;
		cout << p[0];
		for(int i = 1;i < n; i++) cout << ' ' << p[i];
		cout << '\n';
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, -1, 0, 1 , 1,  1, -1, -1 };

VI _array;
int n;

int main() {
	while ( ~scanf( "%d", &n ) && n ) {
		_array.resize( n );
		for ( int i = 0; i < n; i++ ) {
			scanf( "%d", &_array[ i ] );
		}
		int ans = 0;
		while ( true ) {
			VI _array_copy = _array, _array_copy2 = _array;
			sort( _array_copy.begin(), _array_copy.end() );
			for ( int i = 0; i < n; i++ ) {
				_array[ i ] = upper_bound( _array_copy.begin(), _array_copy.end(), _array[ i ] ) - lower_bound( _array_copy.begin(), _array_copy.end(), _array[ i ] );
			}
			if ( _array == _array_copy2 ) {
				break;
			}
			ans++;
		}
		printf( "%d\n", ans );
		for ( int i = 0; i < n - 1; i++ ) {
			printf( "%d ", _array[ i ] );
		}
		printf( "%d\n", _array[ n - 1 ] );
	}
	return 0;
}

C++: #include<stdio.h>
#include<vector>
#include<algorithm>
int main()
{
	int n,i,j,s,r;
	while(scanf("%d",&n),n)
	{
		std::vector<int>v[2];
		v[0].resize(n);v[1].resize(n);
		for(s=r=i=0;i<n;++i)scanf("%d",&v[0][i]);
		for(;;)
		{
			for(i=0;i<n;++i)v[!s][i]=std::count(v[s].begin(),v[s].end(),v[s][i]);
			if(v[!s]==v[s])break;
			++r;
			s=!s;
		}
		printf("%d\n",r);
		for(i=0;i<n;++i)printf("%d%c",v[0][i],i+1-n?' ':'\n');
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		rep(i,n)cin>>in[i];
		while(1){
			map<int,int>a;
			rep(i,n)a[in[i]]++;
			bool h=true;
			rep(i,n){
				if(in[i]!=a[in[i]])h=false;
				in[i]=a[in[i]];
			}
			if(h)break;
		}
		rep(i,9)cout<<in[i]<<" ";
		cout<<in[9]<<endl;
	}
}