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 <cstdlib>
#include <map>
#include <vector>

using namespace std;

int main () {
  while( 1 ) {
    int n;
    cin >> n;
    if( !n ) { return EXIT_SUCCESS; }
    
    vector<int> seq;
    
    seq.reserve( n );
    for( int i = 0; i < n; i++ ) {
      cin >> seq[ i ];
    }
    
    int ct;
    for( ct = 0; ; ct++ ) {
      map<int, int> m;
      for( int i = 0; i < n; i++ ) {
        if( m.find( seq[ i ] ) == m.end() ) {
          m[ seq[ i ] ] = 1;
        } else {
          m[ seq[ i ] ]++;
        }
      }

      bool changed = false;
      for( int i = 0; i < n; i++ ) {
        if( seq[ i ] != m[ seq[ i ] ] ) { changed = true; }
        seq[ i ] = m[ seq[ i ] ];
      }
      /*
      // <for-debug>
      for( int i = 0; i < n; i++ ) {
        cout << seq[ i ] << flush;
        if( i == n - 1 ) { cout << endl; }
        else { cout << " " << flush; }
      }
      // </for-debug>
      */
      if( !changed ) { break; }
    }

    cout << ct << endl;
    for( int i = 0; i < n; i++ ) {
      cout << seq[ i ] << flush;
      if( i == n - 1 ) { cout << endl; }
      else { cout << " " << flush; }
    }
  }
}

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

using namespace std;

int main(void) {
	map<int, int> m;
	int n, in[12], res;
	bool flg;
	int i;

	while(true) {
		cin >> n;
		if(n == 0) { break; }
		for(i = 0; i < n; i++) {
			cin >> in[i];
		}
		
		res = -1;
		do {
			flg = false;
			m.clear();
			res++;
			for(i = 0; i < n; i++) {
				if(m.count(in[i]) == 0) {
					m.insert(map<int, int>::value_type(in[i], 1));
				} else {
					m[in[i]]++;
				}
			}
			for(i = 0; i < n; i++) {
				if(in[i] != m[in[i]]) {
					flg = true;
					in[i] = m[in[i]];
				}
			}
		} while(flg);

		cout << res << endl;
		for(i = 0; i < n; i++) {
			cout << in[i];
			if(i != n-1) { cout << " "; }
		}
		cout << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int x[100000][500], n;
int main() {
	while (true) {
		memset(x, 0, sizeof(x));
		cin >> n;
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> x[0][i];
		}
		for (int i = 1; i < 30000; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					if (x[i - 1][k] == x[i - 1][j]) {
						x[i][j]++;
					}
				}
			}
		}
		for (int i = 1; i < 30000; i++) {
			for (int j = 0; j < n; j++) {
				if (x[i - 1][j] != x[i][j]) { goto E; }
			}
			cout << i - 1 << endl; 
			for (int j = 0; j < n; j++) {
				if (j) { cout << ' '; } cout << x[i][j];
			}
			cout << endl;
			goto owata;
		E:;
		}
	owata:;
	}
}

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

int main()
{

	int n, cnt, flg;
	int s[12], cs[12];

	while (cin >> n)
	{
		if (n == 0) break;
		cnt = 0;
		flg = 1;

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

		for (int i = 0; i < 12; i++)
		{
			cs[i] = 0;
		}

		while (1)
		{
			flg = 0;
			for (int i = 0; i < n; i++)
			{
				for (int j = 0; j < n; j++)
				{
					if (s[i] == s[j])       // cs[i] = s[i]???????????????
					{
						cs[i]++;
					}
				}
			}
			cnt++;
			for (int i = 0; i < n; i++)
			{
				if (s[i] != cs[i])        // s = cs ?????????????????¨??????cs?????????????????°???P
				{
					flg++;
				}
			}
			if (flg==0)
			{
				cnt--;
				break;
			}
			else
			{
				for (int i = 0; i < n; i++)
				{
					s[i] = cs[i];
					cs[i] = 0;
				}
			}
		}
		
		cout << cnt << endl;
		for (int i = 0; i < n-1; i++)
		{
			cout << cs[i] << " ";
		}
		cout << cs[n-1] << endl;
	}

	return 0;
}

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

void solve(vector<int> cur, vector<int> prev, int turn) {
    if(cur == prev) {
        cout << turn-1 << endl;
        for(int i=0; i<N; i++) cout << (i!=0 ? " " : "") << cur[i];
        cout << endl;
        return;
    }

    map<int, int> m;
    for(int i=0; i<N; i++) m[ cur[i] ]++;
    vector<int> nx(N);
    for(int i=0; i<N; i++) nx[i] = m[ cur[i] ];
    solve(nx, cur, turn+1);
}

int main() {
    while(cin >> N, N) {
        vector<int> v(N);
        for(int i=0; i<N; i++) cin >> v[i];
        solve(v, vector<int>(N, 0), 0);
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
	int n,s[12],c[12];
	while(true){
	cin>>n;
	if(n==0)
		break;
	for(int i=0;i<n;i++)
		c[i]=1;
	for(int i=0;i<n;i++){
		cin>>s[i];
		for(int j=0;j<i;j++){
			if(s[i]==s[j])
				c[i]++,c[j]++;
		}
	}
	int ans=0;
	while(true){
		bool t=true;
		for(int i=0;i<n;i++){
			if(s[i]!=c[i])
				t=false;
			s[i]=c[i];
			c[i]=1;
		}
		if(t==true)
			break;
		for(int i=0;i<n;i++){
		    for(int j=0;j<i;j++){
			    if(s[i]==s[j])
				    c[i]++,c[j]++;
		    }
	    }
		ans++;
	}
	cout<<ans<<endl;
	cout<<s[0];
	for(int i=1;i<n;i++)
		cout<<" "<<s[i];
	cout<<endl;
	}
	return 0;
}

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

using namespace std;
typedef map<int, int> mii;

bool check(mii mp) {
    mii::iterator it;
    for (it = mp.begin(); it != mp.end(); it++)
        if ((*it).first != (*it).second) return false;
    return true;
}

int main(void) {
    int n, s[110];
    while (cin >> n, n) {
        int ans = 0;
        mii mp, pre;
        for (int i = 0; i < n; i++) {
            cin >> s[i];
            mp[s[i]]++;
        }
        
        while (!check(mp)) {
            ans++;
            pre = mp;
            mp.clear();
            for (int i = 0; i < n; i++) {
                s[i] = pre[s[i]];
                mp[s[i]]++;
            }
        }

        cout << ans << endl;
        for (int i = 0; i < n; i++) {
            if (i) cout << " ";
            cout << s[i];
        }
        cout << endl;
    }
}

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

int main(){
    while (1){
        int n; cin>>n;
        if (n==0)
            break;
        int buf,cnt=0,f;
        vector <int> a;
        vector <int> c;
        for(int i=0; i<n; i++){
            cin>>buf;
            a.push_back(buf);
            c.push_back(1);
        }
        do{
            f=0;
            for(int i=1; i<n; i++){
                for(int j=0; j<i; j++){
                    if(a[i]==a[j]){
                        c[i]++;
                        c[j]++;
                    }
                }
            }
            cnt++;
            for(int i=0; i<n; i++){
                if(a[i]!=c[i]){
                    a[i]=c[i];
                    f=1;
                }
                c[i]=1;
            }
        }while (f);
        cout<<cnt-1<<endl;
        for(int i=0; i<n; i++)
            cout<<a[i]<<" ";
        cout<<endl;
    }
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define all(a) (a).begin(), (a).end()

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

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

		int ret = 0;
		vector<int> m(n), t(n);
		while(true){
			rep(i, v.size()){
				int count = 0;
				rep(j, v.size()) if(v[i] == v[j]) count++;
				m[i] = count;
			}

			bool p = true;
			rep(i, v.size()) if(m[i] != v[i]){p = false; break;}
			if(p) break;
			rep(i, v.size()) v[i] = m[i];
			ret++;
		}
		cout << ret << endl;
		rep(i, v.size()) cout << (i == 0 ? "" : " ") << v[i];
	}
}