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[10000]={};
			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 <iostream>
#include <stdio.h>

using namespace std;

int main() {
	int d[2][12],n,i,j,k,c,s;
	while(cin >> n) {
		if (n==0) break;
		for (i=0;i<n;i++) cin >> d[0][i];
		k=0; s=0;
		while(true) {
          for (i=0;i<n;i++) {
			 for (j=0,c=0;j<n;j++) if (d[k][i]==d[k][j]) c++;
			 d[1-k][i]=c;
		 }
         for (i=0,c=0;i<n;i++) if (d[0][i]==d[1][i]) c++;
		 if (c==n) break;
		 s++; k=1-k;
		}
		cout << s << endl;
        for (i=0;i<n;i++) if (i==0) cout << d[0][i]; else cout << ' ' << d[0][i];
		cout << endl;
	}
    return 0;
	}

C++: #include <cstdio>

int main(void)
{
	int n;
	int i, j;
	int count, ct, k;
	int num[2][15];
	
	while (scanf("%d", &n), n){
		count = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &num[0][i]);
		}
		k = 0;
		while (1){
			for (i = 0; i < n; i++){
				ct = 0;
				for (j = 0; j < n; j++){
					if (num[k][i] == num[k][j]) ct++;
				}
				num[1 - k][i] = ct;
			}
			ct = 0;
			for (i = 0; i < n; i++){
				if (num[0][i] == num[1][i]) ct++;
			}
			if (ct == n){
				break;
			}
			k = 1 - k;
			count++;
		}
		
		printf("%d\n%d", count, num[0][0]);
		for (i = 1; i < n; i++){
			printf(" %d", num[0][i]);
		}
		printf("\n");
	}
	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 n; cin >> n;
    while (n != 0) {
        int flag = 1;
        int p[n];
        rep(i, n) {
            cin >> p[i];
        }
        int count = 0;
        int q[101] = {0};
        fill(q, q+101, 0);
        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++;
        }
        cout << count-1 << endl;
        rep(i, n-1) cout << q[p[i]] << " ";
        cout << q[p[n-1]] << endl;
        cin >> n;
    }

    return 0;
}

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

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) 
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



int n;

vint op(vint vec) {
    map<int,int> ma;
    for (int i = 0; i < vec.size(); ++i) ma[vec[i]]++;
    vint res(vec.size());
    for (int i = 0; i < vec.size(); ++i) res[i] = ma[vec[i]];
    return res;
}

int main() {
    while (cin >> n) {
        if (n == 0) break;
        vint vec(n);
        for (int i = 0; i < n; ++i) cin >> vec[i];
        int res;
        for (res = 0; res < 1000000; ++res) {
            vint nvec = op(vec);
            if (nvec == vec) break;
            vec = nvec;
        }
        cout << res << endl;
        for (int i = 0; i < n; ++i) {
            cout << vec[i];
            if (i != n-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int a[n],b[n];
    r(i,n)cin>>a[i];
    r(o,114514){
      map<int,int>s;
      r(i,n)b[i]=a[i],s[a[i]]++;
      r(i,n)a[i]=s[a[i]];
      int c=0;
      r(i,n)if(b[i]!=a[i])c++;
      if(!c){
        cout<<o<<endl;
        r(i,n){
          if(i)cout<<' ';
          cout<<a[i];
        }
        cout<<endl;
        goto L;
      }
    }L:;
  }
}

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

int main() {
  int n;
  while(cin >> n) {
    int s[12] = {0},c[12] = {0},c2[12] = {0},k,check=1;
    if(n==0)break;

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

    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        if(c[i] == c[j]) {
          c2[i]++;
        }
      }
    }

    //ok
    k=0;//k=1;
    while(check){
      check = 0;

      int c2[10000] = {0};
      for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
          if(c[i] == c[j]) {
            c2[i]++;
          }
        }
      }
      for(int i=0;i<n;i++) {
        if(c2[i] != c[i]) {
          for(int j=0;j<n;j++) {
            c[j] = c2[j];
          }
          check = 1;
          k++;
        }
      }

    }
    cout << k << endl;
    for(int i=0;i<n;i++) {
      cout << c[i] << " ";
    }
    cout << "\b" << endl;
  }
}