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>
using namespace std;

#define rep(i,n) for(long long i=0;i<n;i++)
#define REP(i,s,n) for(long long i=(s);i<=(n);i++)
#define repr(i,n) for(long long i=n-1;i>=0;i--)
#define REPR(i,s,n) for(long long i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define sz(s) (long long)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n
#define endl '\n'

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const ll mod=1000000007;
//const ll mod=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

void out(){cout << "\n";}
template<class T,class... Args>
void out(const T &x,const Args &... args){
	cout << x << " ";
	out(args...);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
	for(T& e: vec) is >> e;
	return is;
}

template<typename T>
string join(vector<T>& vec, string sep=" "){
	stringstream ss;
	for(int i=0;i<(int)vec.size();i++){
		ss << vec[i] << (i+1==(int)vec.size()?"\n":sep);
	}
	return ss.str();
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll invmod(ll a){ return powmod(a,mod-2); }
ll nCrmod(ll n,ll r){ll x=1,y=1; for(ll i=0;i<r;i++) {x=x*(n-i)%mod; y=y*(i+1)%mod; } return x*powmod(y,mod-2)%mod;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	while(1){
		cin >> n;
		if(!n) break;
		vll a(n);
		cin >> a;
		ll cnt=0;
		while(1){
			map<ll,ll> m;
			auto b=a;
			for(auto&& e:a) m[e]++;
			rep(i,n) a[i]=m[a[i]];
			if(a==b) break;
			else cnt++;
		}
		cout << cnt << endl;
		cout << join(a);
	}
	return 0;
}

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

using namespace std;

int main() {
	int n;
	int number[12];
	int hantei;
	int count;

	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int counter[12] = {0};
		for (int i = 0; i < n; i++) {
			cin >> number[i];
			counter[number[i]-1]++;
		}
		hantei = 0;
		count = 0;
		while (1) {
			for (int i = 0; i < n; i++) {
				if (number[i] == counter[number[i]-1]) {
					if (i == n-1) {
						hantei = 1;
						break;
					}
					continue;
				} else {
					break;
				}
			}
			if (hantei == 1) {
				break;
			}
			for (int i = 0; i < n; i++) {
				number[i] = counter[number[i]-1];
			}
			for (int i = 0; i < 12; i++) {
				counter[i] = 0;
			}
			for (int i = 0; i < n; i++) {
				counter[number[i]-1]++;
			}
			count++;
		}
		cout << count << endl;
		for (int i = 0; i < n; i++) {
			cout << number[i] << " ";
		}
		cout << endl;
	}
	return 0;
}

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

int ans[113][2][12];//二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter=0,flag=0;

void solve(){
	int n;
	cin >> n;
	if(n==0){flag=1;return;}
	ans[counter][0][0]=n;
	
	int S[12];//数列
	for(int i=0;i<n;i++){
		cin >> S[i];
	}
	
	bool check=false;//操作の有無のフラグ
	int time=0;//操作回数
	do{
		map<int,int> marker;
		for(int i=0;i<n;i++){
			marker[S[i]];
			marker[S[i]]++;
		}
		check=false;
		for(int i=0;i<n;i++){
			if(S[i]!=marker[S[i]]){
				check=true;
				S[i]=marker[S[i]];
			}
		}
		if(check) time++;
	}while(check);
	
	ans[counter][0][1]=time;
	for(int i=0;i<n;i++){
		ans[counter][1][i]=S[i];
	}
	counter++;
}

int main(){
	while(flag==0)solve();
	for(int i=0;i<counter;i++){
		cout << ans[i][0][1] << endl;
		for(int j=0;j<ans[i][0][0]-1;j++){
			cout << ans[i][1][j]<<" ";
		}
		cout << ans[i][1][ans[i][0][0]-1] << endl;
	}
}

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

int main(){
	int n;
	vector<int> vi , vi2;
	while(cin >> n){
		vi.clear();
		vi2.clear();
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			int j;
			cin >> j;
			vi.push_back(j);
		}
		int counter = -1;
		do{
			vi2.clear();
			copy(vi.begin(), vi.end(), back_inserter(vi2));
			for(int i = 0; i < n; i++){
				vi[i] = count(vi2.begin(), vi2.end(), vi[i]);
			}
			counter++;
		}while(!equal(vi.begin(), vi.end(), vi2.begin()));
		cout << counter << endl;
		for(int i = 0; i < vi.size(); i++){
			if(i != 0) cout << " ";
			cout << vi[i];
		}
		cout << endl;
	}
	return 0;
}

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

void pr(vector<int> &v1) {
  for(int j = 0; j < (int)v1.size(); ++j) {
	cout << v1[j];
	cout << (j < (int)v1.size() - 1 ? " " : "\n");
  }
}
int loop_cnt = 0;
void op(vector<int> &v1) {
  vector<int> v2 = v1;
  for(int i = 0; i < (int)v1.size(); ++i) {
	int cnt = 0;
	for(int j = 0; j < (int)v1.size(); ++j) {
	  if(v1[j] == v1[i]) {
		cnt++;
		v2[j] = -1;
	  }
	}
	for(int j = 0; j < (int)v2.size(); ++j) {
	  if(v2[j] == -1) {
		v2[j] = cnt;
	  }
	}
  }
  if(v2 != v1) {
	loop_cnt++;
	op(v2);
  }
  else {
	cout << loop_cnt << endl;
	pr(v1);
  }
}

int main() {
  int n;
  while(cin >> n && n) {
	vector<int> v(n);
	for(int i = 0; i < n; ++i) {
	  cin >> v[i];
	}
	op(v);
  }
  return 0;
}