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 n, m;
int S[12], oldS[12], memo[2][12];

void init(void);
void ope(void);
void change(void);
int check(void);
int search(int num);

int main() {
	int ans;

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

		for (int i = 0; i < n; i++)
			cin >> oldS[i];
		
		init();
		ope();
		ans = 0;
		m = 0;
		while (check()) {
			change();
			ope();
			ans++;
		}

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

void init(void) {
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 12; j++) {
			memo[i][j] = -1;
		}
	}
}

void ope(void) {
	int num, cont;
	for (int i = 0; i < n; i++) {
		num = oldS[i];
		cont = 0;
		if (search(num)) {
			cont = search(num);
		}
		else {
			for (int j = 0; j < n; j++) {
				if (oldS[j] == num)
					cont++;
			}
			memo[0][m] = num;
			memo[1][m] = cont;
		}
		S[i] = cont;
	}
}

void change(void) {
	for (int i = 0; i < n; i++) {
		oldS[i] = S[i];
	}
}

int check(void) {
	for (int i = 0; i < n; i++) {
		if (oldS[i] != S[i])
			return 1;
	}

	return 0;
}

int search(int num) {
	for (int i = 0; i < 12; i++) {
		if (memo[0][i] == num) {
			return memo[1][i];
		}
	}

	return 0;
}

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

int main(void){

  int S[12] , P[12] ,n ,c = 0,kaisu = 0,stop = 0;

  

  while(1){


  for( int i = 0 ; i < 12 ; i ++){

    
    S[i] = 0;
    P[i] = 0;



  }


  kaisu = 0;
  stop = 0;
  c = 0;


  cin >> n ;

  if( n == 0 )break;



  for( int i = 0 ; i < n ; i ++){


    cin >> S[i] ;
    
    P[i] = S[i] ;

  }



  while(1){

  for( int i = 0 ; i < n ; i++){

    for( int j = 0 ; j < n ; j++){

      if( S[i] == S[j]) c++  ;
         
          
    }

    P[i] = c ;
    
    c = 0;
  }




  for( int  j = 0 ; j < n ; j++){





    if(  S[j] == P[j] ) stop++  ;
    else continue ; 

   
  
  }

  
   

  if( stop == n  )break;

  stop = 0;

  for( int  j = 0 ; j < n ; j++){

      S[j] = P[j] ;
     
  
  }

 
 
   kaisu++;

 




  }

  cout << kaisu << endl;

  kaisu = 0 ;
  

  for( int i = 0 ; i < n ; i ++){


    cout << P[i] << ' ';


  }

  cout << endl;


  }
  

  return 0;

}

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

int main(void){

  int S[12] , P[12] ,n ,c = 0,kaisu = 0,stop = 0;

  

  while(1){


  for( int i = 0 ; i < 12 ; i ++){

    
    S[i] = 0;
    P[i] = 0;



  }


  kaisu = 0;
  stop = 0;
  c = 0;


  cin >> n ;

  if( n == 0 )break;



  for( int i = 0 ; i < n ; i ++){


    cin >> S[i] ;
    
    P[i] = S[i] ;

  }



  while(1){

  for( int i = 0 ; i < n ; i++){

    for( int j = 0 ; j < n ; j++){

      if( S[i] == S[j]) c++  ;
         
          
    }

    P[i] = c ;
    
    c = 0;
  }




  for( int  j = 0 ; j < n ; j++){





    if(  S[j] == P[j] ) stop++  ;
    else continue ; 

   
  
  }

  
   

  if( stop == n  )break;

  stop = 0;

  for( int  j = 0 ; j < n ; j++){

      S[j] = P[j] ;
     
  
  }

 
 
   kaisu++;

 




  }

  cout << kaisu << endl;

  kaisu = 0 ;
  

  for( int i = 0 ; i < n ; i ++){


    cout << P[i] << ' ';


  }

  cout << endl;


  }
  

  return 0;

}

C++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(_Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,_Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif


bool solve(vector<int> &v){
    int n = v.size();
    map<int,int> m;
    REP(i,n) m[v[i]]++;
    bool ret = false;
    REP(i,n){
        if(m[v[i]] != v[i]){
            v[i] = m[v[i]];
            ret = true;
        }
    }
    return ret;
}

int main(){
    int n;
    vector<int> v;
    while(cin >> n && n){
        dbgchk(n > 12);
        v.resize(n);
        REP(i,n) cin >> v[i];
        int count = 0;
        while(solve(v)) count++;
        cout << count << endl;
        cout << join(v) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

using namespace std;

typedef vector<int> vi;

int main(){
    int n;
    while (cin >> n && n){
        vi v(n);
        int c = 0;
        rep(i, n) cin >> v[i];
        while(1){
            vi next(n);
            map<int, int> m;
            rep(i, n) m[v[i]]++;
            rep(i, n) next[i] = m[v[i]];
            if (next == v) break;
            c++;
            v = next;
        }

        cout << c << endl;
        rep(i, n - 1){
            cout << v[i] << " ";
        }
        cout << v.back() << endl;
    }
}