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 pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n&&n){
    vary(int,v,n,0);
    vary(int,v2,n,0);
    rep(i,n){
      cin >> v[i];
    }
    int ans = 0;
    while(1){
      map<int,int> m;
      v2 = v;
      rep(i,n){
        m[v[i]]++;
      }
      rep(i,n){
        v[i] = m[v[i]];
      }
      if(v == v2){
        cout << ans << endl;
        rep(i,n-1){
          cout << v2[i] << " ";
        }
        cout << endl;
        break;
      }
      ++ans;
    }
  }
  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[1000000] = {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 <iostream>
using namespace std;

int main() {
  int n;
  while(cin >> n) {
    int s[10000] = {0},c[10000] = {0},c2[10000] = {0},k,check=1;
    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>
using namespace std;
bool jug(int* s1, int* s2, int len){
    for(int i = 0; i < len; ++i) {
        if (s1[i] != s2[i]) return false;
    }
    return true;
}
int main(){
    int n,count,tmp,x;
    int* s = new int[12];
    int* ans = new int[12];
    while(true) {
        cin >> n;
        if (n ==  0) {
            break;
        }
        for(int i = 0; i < n; ++i) {
            cin >> s[i];
        }
        x = 0;
        while(true){
            for(int i = 0; i < n; ++i) {
                count = 0;
                for(int j = 0; j < n; ++j) {
                    if (s[i] == s[j]) {
                        ++count;
                    }
                }
                ans[i] = count;
            }

            if (jug(s, ans, n)) break;
            x++;

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

    }
    delete s;
    delete ans;
}

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

int main(){
    int n;
    while (1){
	cin >> n;
	if (n == 0) break;
	vector<int> s;
	int b;
	for (int i = 0; i < n; i++){
	    cin >> b;
	    s.push_back(b);
	}
	int c = 0;
	while (1){
	    vector<int> freq(13, 0);
	    for (int i = 0; i < n; i++)
		freq[s[i]]++;

	    vector<int> ss = s;
	    for (int i = 0; i < n; i++)
		ss[i] = freq[ss[i]];

	    if (ss == s){
		cout << c << endl;
		for (int i = 0; i < s.size(); i++)
		    printf("%d%c", s[i], (i == s.size()-1)? '\n':' ');
		break;
	    }

	    s = ss;
	    c++;
	}
    }
}

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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> input(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> input[i];
		}
		vector<int> output(n);
		int ans = 0;
		bool flag = true;
		while(flag)
		{
			flag = false;
			map<int, int> data;
			for(int i = 0; i < n; ++i)
			{
				++data[input[i]]; 
			}
			for(int i = 0; i < n; ++i)
			{
				output[i] = data[input[i]];
			}
			for(int i = 0; i < n; ++i)
			{
				if(input[i] != output[i])
				{
					flag = true;
					break;
				}
			}
			for(int i = 0; i < n; ++i)
			{
				input[i] = output[i];
			}
			++ans;
		}
		cout << ans - 1 << endl;
		for(int i = 0; i < n - 1; ++i)
		{
			cout << output[i] << " ";
		}
		cout << output[n - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}