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 <algorithm>
#include <cstring>

using namespace std;

bool debug = false;
int v[2][12];

bool isFinished(int n){
  for(int i=0;i<n;i++){
	if(v[0][i] != v[1][i]) return false;
  }
  return true;
}

int main(void){
  int n;
  while(cin >> n && n){
	int prv = 0, cur = 1;
	int tmp;
	int times = 0;
	
	memset(v, -1, sizeof(v));
	for(int i=0;i<n;i++){
	  cin >> tmp;
	  v[prv][i] = tmp;
	}

	while(!isFinished(n)){
	  for(int i=0;i<n;i++){
		int app=0;
		tmp = v[prv][i];
		for(int j=0;j<n;j++){
		  if(v[prv][j] == tmp) app++;
		}
		v[cur][i] = app;
		if(debug) cout << v[cur][i] << " ";
	  }
	  if(debug) cout << endl;
	  cur = 1 - cur;
	  prv = 1 - prv;
	  times++;
	}
	cout << times - 1 << endl;
	for(int i=0;i<n-1;i++){
	  cout << v[cur][i] << " ";
	}
	cout << v[cur][n-1] << endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin>>n){
    if(n==0) break;
    int s[n],mems[n];
    for(int i=0;i<n;i++){
      cin >> s[i];
      mems[i] = 0;
    }
    int count = 0;
    bool ok = false;
    while(!ok){
      count++;
      for(int i=0;i<n;i++){
	int cou = 0;
	for(int j=0;j<n;j++){
	  if(s[i]==s[j]) cou++;
	}
	mems[i] = cou;
      }
      ok = true;
      for(int i=0;i<n;i++){
	if(s[i]!=mems[i]) ok = false;
	s[i] = mems[i];
      }
    }
    cout << count-1 << endl;
    for(int i=0;i<n;i++){
      if(i!=n-1) cout << s[i] << ' ';
      else cout << s[i] << endl;;
    }
  }
  return 0;
}

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

vector<int> calc(vector<int> a) {
  map<int,int> m;
  for(int i = 0; i < a.size(); ++i) {
    m[a[i]] += 1;
  }
  for(int i = 0; i < a.size(); ++i) {
    a[i] = m[a[i]];
  }
  return a;
}

int n;
vector<int> a;

int main() {
  while(cin >> n && n) {
    a.resize(n);
    for(int i = 0; i < n; ++i) cin >> a[i];
    int res = 0;
    while(1) {
      vector<int> b = calc(a);
      if(a == b) break;
      a = b;
      ++res;
    }
    cout << res << endl;
    for(int i = 0; i < n; ++i) {
      if(i) cout << " ";
      cout << a[i];
    }
    cout << 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 >> c[i];
    }

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

    //ok
    k=0;//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 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 <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int n,v;
	map<int,int> mp;
	while(1){
		vector<int>  b ;
		cin >> n ;
		if(n==0){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> v;
			b.push_back(v);
		}
		for(int j=0;;j++){
			vector<int>  a ;
			for(int i=0;i<=12;i++){
				mp[i]=0;
			}
			for(int i=0;i<n;i++){
			mp[b[i]] ++;
		}
			for(int i=0;i<n;i++){
				a.push_back(mp[b[i]]);
			}
			if(a == b){
				cout << j << "\n";
				for(int i=0;i<n;i++){
					cout << a[i] << " ";
				}
				cout << "\n";
				break;
			}
			else{
				b = a;
			}
		}
	}
}

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

using namespace std;

int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a[n];
		int e = 0;
		for(int i=0;i<n;i++) cin >> a[i];
		while(1){
			int b[n],c[n];
			for(int i=0;i<n;i++) b[i] = 0;
			for(int i=0;i<n;i++) b[a[i]-1]++;
			for(int i=0;i<n;i++) c[i] = b[a[i]-1];
			int d = 0;
			for(int i=0;i<n;i++) if(a[i]==c[i]) d++;
			if(d==n) break;
			e++;
			for(int i=0;i<n;i++) a[i] = c[i];
		}
		cout << e << endl;
		cout << a[0];
		for(int i=1;i<n;i++) cout << " " << a[i];
		cout << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n,t,a[12],b[12],s[12];

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

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

#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)

int main() {
	int n;
	while(cin >> n && n) {
		int a[15];
		rep(i,n) {
			cin >> a[i];
		}
		int p[15], cnt = 0;
		while(1) {
			rep(i,n) {
				p[i] = 1;
			}
			rep(i,n) {
				rep2(j,i+1,n) {
					if(a[i] == a[j]) {
						p[i]++, p[j]++;
					}
				}
			}
			bool f = 1;
			rep(i,n) {
				if(a[i] != p[i]) {
					f = 0;
					break;
				}
			}
			if(f) break;
			cnt++;
			rep(i,n) {
				a[i] = p[i];
			}		
		}
		cout << cnt << endl;
		rep(i,n-1) {
			cout << p[i] << " ";
		}
		cout << p[n-1] << endl;
	}
	return 0;
}

C++: #include <iostream>

int main(){
  //nªzñ·³,countªvZñÌÂàè
  int n,count;
  while(std::cin >> n){
    //std::cout << n << std::endl;
    if(!n) {
      break;
    }
    int s[n];
    bool flag;
    int cnt[n];
    int cnt_of[n];
    int new_s[n];
    int old_s[n];
    
    //üÍtF[Y
    for(int i=0;i<n;i++){
      std::cin >> s[i];
    }

    for(int ans=0;;ans++){
      //½Â é©ð¦é
      cnt[0]=s[0];
      cnt_of[0]=1;
      int count=0;
      
      //iÔÚª¡ÜÅÉoÄ«½©mF
      for(int i=1;i<n;i++){
	for(int j=0;;j++){
	  if(cnt[j]==s[i]){
	    cnt_of[j]++;
	    break;
	  }
	  if(j==count){
	    count++;
	    cnt[count]=s[i];
	    cnt_of[count]=1;
	    //	    std::cout << count <<"count+" << i << std::endl;
	    break;
	  }
	}
      }//iÔÚ[v
      
      flag = true;
      //eiÉlðãü
      for(int i=0;i<n;i++){
	for(int j=0;j<=count;j++){
	  if(cnt[j]==s[i]){
	    new_s[i]=cnt_of[j];
	    break;
	  }
	}
	if(new_s[i]!=s[i]){
	  flag = false;
	  s[i]=new_s[i];
	}
      }
      
      //mFpoÍ

      /*      for(int i=0;i<n;i++){
	std::cout << new_s[i] << " ";
      }
      std::cout << std::endl;
      */

      if(flag){
	std::cout << ans << std::endl;
	//mFpoÍ
	for(int i=0;i<n;i++){
	  std::cout << new_s[i] << " ";
	}
	std::cout << std::endl;
	break;
      }
    }
  }//while
}