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<vector>
#include<list>
#include<algorithm>
#include<iostream>
#define rep(i,a,b) for(i=a;i<(b);i++)
using namespace std;
int main(){
  int g,h,i,j;
  int n;
  vector<int> a,b,c;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    a.clear();
    rep(i,0,n){
      int tmp;
      cin>>tmp;
      a.push_back(tmp);
    }
    g=0;
    do{
      b.clear();
      c.clear();
      rep(i,0,a.size()){
	rep(j,0,i){
	  if(a[i]==a[j])
	    break;
	}
	if(j==i)
	  b.push_back(a[i]);
      }
      rep(i,0,b.size())
	c.push_back(0);
      rep(i,0,c.size()){
	rep(j,0,n){
	  if(b[i]==a[j])
	    c[i]++;
	}
      }
      h=0;
      rep(i,0,n){
	rep(j,0,c.size()){
	  if(a[i]==b[j]){
	    if(a[i]!=c[j])
	      h=1;
	    a[i]=c[j];
	    break;
	  }
	}
      }
      if(h)
	g++;
    }while(h);
    cout<<g<<endl;
    rep(i,0,n-1)
      cout<<a[i]<<" ";
    cout<<a[i]<<endl;
  }
  return 0;
}

C++: #include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
// #include <boost/foreach.hpp>
// #include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
//#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
// int dx[]={0,1,0,-1};
// int dy[]={1,0,-1,0};
//typedef pair<int,int> P;

const long long MOD=1000000007LL;
bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)||islower(c));}
template<typename T> 
void print(vector<T> v){
    for(int i=0;i<v.size();i++){
        if(i)cout<<" ";
        cout<<v[i];
    }
    cout<<endl;
}
int INF=1e18;

template<typename T>
void printendl(vector<T> v){
    for(auto date:v)cout<<date<<endl;
}

template<typename T>
void printvv(vector<vector<T>> v){
    for(int i=0;i<v.size();i++){
        for(int j=0;j<v[i].size();j++){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    else return gcd(b,a%b);
}

struct Edge{
    int to,cost;
};
struct S{
    int n;
    char c;
};

map<int,int> prime_factor(int n){
    map<int,int> ret;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            ret[i]++;
            n/=i;
        }
    }
    if(n!=1)ret[n]=1;
    return ret;
}

bool alleq(vector<int>& v){
    map<int,int> mp;
    rep(i,0,v.size())mp[v[i]]++;
    for(auto x:mp)if(x.first!=x.second)return false;
    return true;
}

signed main (){
    int n;
    while(cin>>n){
        if(n==0)break;
        vector<int> v(n);
        rep(i,0,n)cin>>v[i];
        int i;
        for(i=0;!alleq(v);i++){
            map<int,int> mp;
            rep(i,0,n)mp[v[i]]++;
            rep(i,0,n)v[i]=mp[v[i]];
            //print(v);
        }
        cout<<i<<endl;
        print(v);


        
    }
    

}


/*
001
010
011

*/

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

int main(){
  int i,j,n,a[2][12],c,f,aa;
  while(1){
    cin >> n;
    if(n == 0) break;
    for(i=0;i<n;i++){
      scanf("%d",&a[0][i]); 
      a[1][i] = 0;
    }

    c = 0;
    f = 0;
    while(1){
      for(i=0;i<n;i++){
	aa = a[c%2][i];
	for(j=0;j<n;j++){
	  if(aa == a[c%2][j] && c%2 == 0) a[1][i]++;
	  else if(aa == a[c%2][j] && c%2 == 1) a[0][i]++;
	}
      }

      f = 1;
      for(i=0;i<n;i++){
	if(a[0][i] != a[1][i]){
	  f=0;
	  break;
	}
      }
      if(f == 1) break;
      for(i=0;i<n;i++) a[c%2][i] = 0;
      c++;
    }

    cout << c << endl;
    cout << a[0][0];
    for(i=1;i<n;i++) cout << " " << a[0][i];
    cout << endl;

  }
  return 0;
}

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

int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a[n];
		int e = 0;
		for(int i=0;i<n;i++) cin >> a[i];
		while(1){
			int b[n];
			for(int i=0;i<n;i++) b[i] = 0;
			for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(a[i]==a[j]) b[i]++;
			int d = 0;
			for(int i=0;i<n;i++) if(a[i]==b[i]) d++;
			if(d==n) break;
			e++;
			for(int i=0;i<n;i++) a[i] = b[i];
		}
		cout << e << endl;
		cout << a[0];
		for(int i=1;i<n;i++) cout << " " << a[i];
		cout << endl;
	}
}

C++: //	created : 15/12/27
// 	autor   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>

using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = 0 ; i < a ; i ++)
#define vi vector<int>


int main(void){
	int n;
	while(cin>>n,n){
		vi in(n),l(n);
		int ret = 0;
		rep(i,n)cin>>in[i];
		while(true){
			//rep(i,n)cout<<in[i]<<" ";cout<<endl;
			int cnt[13];
			rep(i,13)cnt[i]=0;
			rep(i,n)cnt[in[i]]++;
			rep(i,n)in[i] = cnt[in[i]];
			if(in == l)break;
			ret ++;
			l = in;
		}
		cout<<ret<<endl;
		rep(i,n-1)cout<<in[i]<<" ";
		cout<<in[n-1]<<endl;
	}
}

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

int ary[12];
int tmp[12];

int sumup(int k,int n) {
  int res = 0;
  int tar = ary[k];
  for(int i=0; i<n; ++i)
    if(ary[i] == tar) res++;
  return res;
}
int main() {
  int n,t;
  while(cin>>n, n) {
    for(int i=0; i<n; ++i) {
      cin>>t;
      ary[i] = t;
    }

    int count = 0;
    while(1) {
      for(int i=0; i<n; ++i)
	tmp[i] = sumup(i,n);

      count++;
      for(int i=0; i<n; ++i) {
	if(ary[i] != tmp[i]) goto NEXT;
      }

      cout<<count-1<<endl;
      for(int i=0; i<n-1; ++i)
	cout<<ary[i]<<" ";
      cout<<ary[n-1]<<endl;
      break;
    NEXT:
      for(int i=0; i<n; ++i)
	ary[i] = tmp[i];
    }
  }
}