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;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[12]={},kawa[12];
        for(int i=0;i<n;i++)cin>>kawa[i];
        for(int i=0;;i++){
            int num[100]={};
            for(int j=0;j<n;j++)num[kawa[j]]++;
            bool rever=1;
            for(int j=0;j<n;j++){
                kawa[j]=num[kawa[j]];
                if(kawa[j]!=ans[j])rever=0;
            }
            if(rever){
                cout<<i<<endl;
                for(int j=0;j<n-1;j++)cout<<kawa[j]<<" ";
                cout<<ans[n-1]<<endl;
                break;
            }
            for(int j=0;j<n;j++)ans[j]=kawa[j];
        }
    }
}

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);
		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];
		cout << endl;
	}
}

C++: #include <iostream>
using namespace std;
main(){
	int i,n;
	while(cin >> n, n){
		int p,s[3][14]={0};
		for(i=1;i<=n;i++) cin >> s[0][i]; 
		for(p=0;;p++){
			for(i=1;i<=n;i++) s[2][s[0][i]] ++;
			for(i=1;i<=n;i++) s[1][i] = s[2][s[0][i]];			
			for(i=1;i<=n;i++) if(s[0][i] != s[1][i]) break;
			if(i>n) break;
			for(i=1;i<=n;i++){s[0][i] = s[1][i];s[2][i] = 0;}
		}
		cout << p << '\n';
		for(i=1;i<=n;i++) cout << s[1][i] << ' ';
		cout << '\n';
	}
}

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

int n;
int ar1[20] = {};
int ar2[20] = {};


int func(int x){
	int val;
	int cnt = 0;;
	for(int i = 0; i < n; i++){
		if(ar1[i] == x){
			cnt++;
		}
	}
	val = cnt;
	return val;
}


int main(){
	while(cin >> n, n){
		for(int i = 0; i < n; i++){
			cin >> ar1[i]; 
		}
		int all_cnt = 0;
		while(1){
			for(int i = 0; i < n; i++){
				ar2[i] = func(ar1[i]);		
			}

			bool flag = true;
			for(int i = 0; i < n; i++){
				if(ar1[i] != ar2[i]){
					flag = false;
				}
			}
			if(flag == true) {
				cout << all_cnt << endl;
				for(int i = 0; i < n; i++){
					cout << ar2[i];
					if(i != n-1){
						cout << " ";
					}
				}
				cout << endl;
				break;
			}else{
				all_cnt++;
				for(int i = 0; i < n; i++){
					ar1[i] = ar2[i];
				}
				continue;
			}
		}
	}
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EPS (1e-8)

typedef pair<int, int> pii;
typedef vector<pii> vp;
typedef vector<int> vi;

int n;

vi solve(vi& a) {
	vp cnt; //num, count
	REP(i, n) {
		bool f = true;
		REP(j, cnt.size()) {
			if (a[i] == cnt[j].first) {
				cnt[j].second++;
				f = false;
			}
		}
		if (f) cnt.push_back(pii(a[i], 1));
	}
	
	vi res(n);
	REP(i, n) {
		REP(j, cnt.size()) if (a[i] == cnt[j].first)
			res[i] = cnt[j].second;
	}
	
	return res;
}

bool check(const vi& a, const vi& b) {
	bool f = true;
	REP(i, n) if (a[i] != b[i]) f = false;
	return f;
}

int main() {
	while (cin >> n, n) {
		vi s1(n), s2;
		REP(i, n) scanf("%d", &s1[i]);
		
		int ans = 0;
		while (true) {
			s2 = solve(s1);
			if (check(s1, s2)) break;
			s1 = s2;
			ans++;
		}
		cout << ans << endl;
		REP(i, n - 1) printf("%d ", s1[i]);
		printf("%d\n", s1[n - 1]);
	}
	return 0;
}

C++: #include <iostream>]
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
int main()
{
  int n;
  while(true){
    cin>>n;
    if(n==0){break;}
    int *a=new int[n];
    map<int,int>Map;
    rep(i,n){
      cin>>a[i];
    }
    for(int cnt=0;;cnt++)
    {
      rep(i,n){
        Map[a[i]]++;
      }
      int *s=new int[n];
      rep(i,n)
      {
        s[i]=Map[a[i]];
      }
      if(a==s)
      {
        cout<<cnt<<endl;
        rep(i,n){
          if(i!=0){
            cout<<" ";
          }
          cout<<a[i];
        }
        cout<<endl;
        break;
      }
      rep(i,n){
        s[i]=a[i];
      }
    }
  }
  return 0;
}

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

int main(){
  int n;
  while(cin>>n){
    if(!n)break;
    int a[n],b[n];
    int count = 0;
    for(int i=0;i<n;i++)
      cin>>a[i];
    while(true){
      for(int i=0;i<n;i++){
	int c = 0;
	for(int j=0;j<n;j++)
	  if(a[j] == a[i])
	    c++;
	b[i] = c;
      }
      bool bb = true;
      for(int i=0;i<n;i++){
	if(a[i] != b[i]) bb = false;
	a[i] = b[i];
      }
      if(bb)break;
      count++;
    }
    cout<<count<<endl;
    cout<<a[0];
    for(int i=1;i<n-1;i++)
      cout<<" "<<a[i];
    cout<<endl;
  }
  return 0;
}

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

int main(){
	int n;
	while(cin >> n, n){
		vector<vector<int>> vvi;
		vector<int> vi;
		for(int i = 0; i < n; i++){
			int k;
			cin >> k;
			vi.push_back(k);
		}
		vvi.push_back(vi);
		int cnt = 0;
		do{
			vi.clear();
			for(int i = 0; i < vvi[cnt].size(); i++){
				vi.push_back(count(vvi[cnt].begin(), vvi[cnt].end(), vvi[cnt][i]));
			}
			vvi.push_back(vi);
			cnt++;
		}while(vvi[cnt] != vvi[cnt-1]);

		cout << cnt-1 << endl;
		for(int i = 0; i < vvi[cnt].size(); i++){
			if(i){
				cout << ' ';
			}
			cout << vvi[cnt][i];
		}
		cout << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int x[32000][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>
using namespace std;
int n,a[33],cnt;
main()
{
    while(cin>>n,n)
    {
        cnt=0;
        for(int i=0;i<n;i++)cin>>a[i];
        int b[33];
        while(1)
        {
            for(int i=0;i<n;i++)
            {
                b[i]=0;
                for(int j=0;j<n;j++)b[i]+=a[i]==a[j];
            }
            bool f=1;
            for(int i=0;i<n;i++)f&=a[i]==b[i];
            if(f)
            {
                cout<<cnt<<endl;
                for(int i=0;i<n;i++)cout<<b[i]<<(i==n-1?"\n":" ");
                break;
            }
            cnt++;
            for(int i=0;i<n;i++)a[i]=b[i];
        }
    }
}