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

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

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

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

    //ok
    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 l=0;l<n;l++) {
        cout << c[l] << " " << c2[l] << endl;
        }
        k++;
      */
      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;
  }
}

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

int main(){
	while(1){	
		int n, count=0;
		long before[13], after[13], c[13];
	
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i)scanf(" %ld", &before[i]);
				
		//loop
		while(1){
			
			for(int i=0; i<=120; ++i) c[i]=0;
			
			for(int i=0; i<n; ++i){
				for(int j=0; j<n; ++j){
					if(before[i] == before[j]) c[i]++;
				}
			}
				
			for(int i=0; i<n; ++i) after[i]=c[i];	
			
			bool flag=true;
			for(int i=0; i<n; ++i){
				if(before[i]!=after[i]){
					flag=false;
					break;	
				}
			}
			if(flag) break;
			
			/*
			for(int i=0; i<n; ++i){
				printf("%ld", after[i]);
				if(i<n-1) printf(" ");
			}
			printf("\n");
			*/
			
			count++;
			for(int i=0; i<n; ++i) before[i]=after[i];
		}
		
		printf("%d\n", count);
		for(int i=0; i<n; ++i){
			printf("%ld", after[i]);
			if(i<n-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

bool check(int *numl, int *newl, int n = 0){
  for (int i = 0; i < n; i++) {
    if(numl[i] != newl[i])return false;
  }
  return true;
}

void printline(int *line, int n){
  std::cout << "printline:" << std::endl;
  for (int i = 0; i < n; i++) {
    std::cout << line[i] << " ";
  }
  std::cout << std::endl;
}

int main(){
  int n;
  while(cin >> n, n){
    int numl[n], newl[n], ans = 0;
    int counter[1000] = {0};
    for (int i = 0; i < n; i++) {
      cin >> numl[i];
      counter[numl[i]]++;
    }
    
    while(!check(newl, numl, n)){
      ans++;
      for (int i = 0; i < n; i++) {
        newl[i] = numl[i];
        numl[i] = counter[numl[i]];
      }
      
      for (int i = 0; i < n; i++) {
        counter[i] = 0;
      }
      
      for (int i = 0; i < n; i++) {
        counter[numl[i]]++;
      }

      //printline(numl, n);
    }
    std::cout << ans - 1 << std::endl;
    for (int i = 0; i < n; i++) {
      std::cout << newl[i] << " ";
    }
    std::cout << std::endl;
  }
  return 0;
}

C++: #include<stdio.h>
int a[12];
int b[12];
int d[12];
int p[30];
int main(){
	int c;
	while(scanf("%d",&c),c){
		for(int i=0;i<c;i++){
			scanf("%d",a+i);
			b[i]=a[i];
		}
		int count=0;
		while(1){
			for(int i=0;i<30;i++)p[i]=0;
			for(int i=0;i<c;i++)p[b[i]]++;
			for(int i=0;i<c;i++)d[i]=p[b[i]];
			bool ok=true;
			for(int i=0;i<c;i++)if(d[i]-b[i])ok=false;
			if(ok)break;
			for(int i=0;i<c;i++)b[i]=d[i];
			count++;
		}
		printf("%d\n",count);
		for(int i=0;i<c;i++){
			if(i)printf(" ");
			printf("%d",d[i]);
		}
		printf("\n");
	}
}

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

using namespace std;

int main(){
	int n[12],N,p[12],pc[12],pp[12],t,c=0,flg;

	while(1){
		cin >> N;

		if(N==0)break;

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

		while(1){
			c++;
			flg=0;

			//initialize counter
			for(int j=0;j<N;j++){
				pc[j] = 0;
			}

			//count
			for(int i=0;i<N;i++){
				//pick up
				t = n[i];

				for(int j=0;j<N;j++){
					if(t==n[j]){
						pc[i]++;
					}
				}
			}

			//make p[]
			for(int i=0;i<N;i++){
				n[i] = pc[i];
			}

			//judge
			for(int i=0;i<N;i++){
				if(n[i]!=pp[i]){
					flg=1;
				}
			}

			//make pp[]
			for(int i=0;i<N;i++){
				pp[i] = n[i];
			}

			//if made p[]
			if(flg==0){
				break;
			}
		}

		c--;

		cout << c << endl;
		for(int i=0;i<N-1;i++){
			cout << pp[i] << " ";
		}
		cout << pp[N-1] << endl;
	}

	return 0;
}

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

using namespace std;

int main()
{
    int n;
    
    while (cin >> n, n) {
        vector<vector<int> > a(2, vector<int>(n));
        int cnt = 0;
        int f, t;

        f = 0;
        t = 1;
        for (int i = 0; i < n; i++)
            cin >> a[0][i];

        while (true) {
            for (int i = 0; i < n; i++) {
                int tmp = 0;
                for (int j = 0; j < n; j++)
                    if (a[f][i] == a[f][j])
                        tmp++;
                a[t][i] = tmp;
            }

            bool flag = true;
            for (int i = 0; i < n; i++)
                if (a[f][i] != a[t][i]) {
                    flag = false;
                    break;
                }
            if (flag)
                break;

            cnt++;
            f = 1 - f;
            t = 1 - t;
        }

        cout << cnt << endl;
        for (int i = 0; i < n - 1; i++)
            cout << a[t][i] << " ";
        cout << a[t][n - 1] << endl;
    }

    return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
vector<int> next(vector<int>v) {
	
	vector<int>res;
	rep(i, 0, v.size()) {
		res.push_back(count(all(v), v[i]));
	}
	return res;
}
signed main() {
	int n; 
	while (cin >> n, n) {
		vector<int>w, v(n); rep(i, 0, n)cin >> v[i];
		int cnt(0);
		while (1) {
			w = v;
			v = next(v);
			if (v == w)break;
			cnt++;
		}
		cout << cnt << endl;
		rep(i, 0, v.size()) cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');
	}
	return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {
		int N; cin >> N;
		if (!N)break;
		vector<int>vs(N);
		for (int i = 0; i < N; ++i) {
			cin >> vs[i];
		}
		int time = 0;
		while (1) {
			map<int, int>mp;
			for (int i = 0; i < N; ++i) {
				mp[vs[i]]++;
			}
			vector<int>nexvs(N);
			for (int i = 0; i < N; ++i) {
				nexvs[i] = mp[vs[i]];
			}
			if (vs == nexvs)break;
			vs = nexvs;
			time++;
		}
		cout << time << endl;
		for (int i = 0; i < N; ++i) {
			cout << vs[i];
			if (i != N - 1)cout << " ";
			else cout << endl;
		}
	}
	return 0;
}