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<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int  n;
    while(cin >> n, n){
        int i = 0, s[15], ap[1024] = {0};
        rep(j,n){
            cin >> s[j];
            ap[s[j]]++;
        }
        int sub[15], ans = 0;;
        while(true){
            rep(j,n){
                sub[j] = ap[s[j]];
            }
            bool c = true;
            rep(j,1024) ap[j] = 0;
            rep(j,n){
                if(s[j] != sub[j]) c = false;
                s[j] = sub[j];
                ap[s[j]]++;
            }
            if(c) break;
            ans++;
        }
        cout << ans << endl;
        rep(j,n){
            if(j) cout << ' ';
            cout << s[j];
        }cout << endl;
    }
    
}

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

int n = 0;
int counter = 0;

vector<int> operation_of_fa(const vector<int> num_seq);

int main()
{
	int num = 0;
	while (true) {
		cin >> n;
		if(n==0) break;
		vector<int> first_num_seq;
		for(int i=0;i<n;i++) {
			cin >> num;
			first_num_seq.push_back(num);
		}

		vector<int> operated_seq = operation_of_fa(first_num_seq);

		cout << counter << endl;
		for(int i=0; i<n; i++) 
			cout << operated_seq[i] << ' ';
	}
	return 0;
}


vector<int> operation_of_fa(const vector<int> num_seq)
{
	int frequency = 0;
	vector<int> operated_seq;
	for (int i=0;i<n;i++) {
		frequency = 0;
		for (int j=0;j<n;j++) 
			if (num_seq[i] == num_seq[j])
				frequency++;
		operated_seq.push_back(frequency);
	}
	
	if (num_seq != operated_seq) {
		counter++;
		return operation_of_fa(operated_seq);
	}
	else
		return operated_seq;
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	int n;
	cin >> n;
	vi S(n);
	REP(i, n) {
		cin >> S[i];
	}

	int count = 0;
	while(true) {
		vi C(n, 1);
		REP(i, n) {
			FOR(j, i+1, n-1) {
				if(S[i] == S[j]) {
					C[i]++;
					C[j]++;
				}
			}
		}

		if(S == C) {
			break;
		} else {
			S = C;
			count++;
		}
	}

	cout << count << endl;
	REP(i, n) {
		cout << S[i];
		if(i != n-1) {
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

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

int main()
{
    int input_num;
    
    while (std::cin >> input_num) {
        
        /*終了条件*/
        if (input_num == 0) break;
    
        std::vector<int> num_array(input_num, 0);

        for (int i = 0; i < input_num; ++i) {
            std::cin >> num_array[i];
        }
        
        bool is_end = false;
        int ans_num = 0;

        while (!is_end) {
            std::map<int, int> array_cnt;
            int i = 0;
            std::vector<int> copy_array(num_array);

            while (i < input_num) {
                array_cnt[copy_array[i]] += 1;
                i++;
            }

            for (int i = 0; i < input_num; ++i) {
                copy_array[i] = array_cnt[copy_array[i]];
            }
            
            if (copy_array == num_array) {
                is_end = true;
            } else {
                ans_num++;
                num_array = copy_array;
            }
        }

        std::cout << ans_num << std::endl;
        
        for (int i = 0; i < input_num; ++i) {
            std::cout << num_array[i] << (i < input_num - 1 ? " ": "\n");
        }

    }

    return 0;
}

C++: #include <iostream>

using namespace std;

int main(void){

  int n,cnt;
  int s[12];
  int copys[12];
  while( cin >> n , n ){

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

    int ans = 0;
    while(1){

      for( int i = 0 ; i < n ; i++ ){
	cnt = 0;
	for( int j = 0 ; j < n ; j++ ){
	  // cout << "s[i] = " << s[i] << " ";
	  //cout << "s[j] = " << s[j] << " " << endl;;
	  if( s[i] == s[j] ){
	    //cout << "cnt" << endl;
	    cnt++;
	  }
	}
	copys[i] = cnt;
	cnt = 0;
      }

      cnt = 0;
      for( int i = 0 ; i < n ; i++ ){
	if( copys[i] == s[i] ){
	  cnt++;
	}
	s[i] = copys[i];
      }   
      if( cnt == n ) break;
      ans++;
    }

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

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

int main(){
	int n, x;
	while(cin >> n, n){
		if(n > 12){
			cerr << n << endl;
		}
		for(int i = 0; i < n; ++i){
			cin >> x;
		}
	}
}

C++: #include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int 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 count=0;;count++){
		rep(i,n){
			Map[a[i]]++;
		}
		int *s=new int[n];
		rep(i,n){
			s[i]=Map[a[i]];
		}
		if(a==s){cout<<count<<endl;break;}
		rep(i,n){	
			s[i]=a[0];
		}
		  
	}
	for(int i=0;i<n;i++){
		if(i!=0){
		cout<<" ";
		}
		cout<<a[i];
	}
	cout<<endl;
	return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int in;

	while(cin >> in){
		int rev = 0, max = 0;

		if(in == 0) break;

		int data[in];

		for(int i = 0; i < in; i++){
			cin >> data[i];
			if(data[i] > max) max = data[i];
		}

		while(1){

			int sum[max+1];

			for(int	i = 0; i <= max; i++){
				sum[i] = 0;
			}
		
			for(int i = 0; i < in; i++){
				sum[data[i]]++;
			}
			for(int i = 0; i < in; i++){
				data[i] = sum[data[i]];
			}
			int status = 0;

			for(int i = 0; i < in; i++){
				if(data[i] != sum[data[i]]) status = 1;
			}

			if(status == 0){
				cout << rev << endl;
				for(int i = 0; i < in; i++){
					cout << data[i] << " ";
				}
				cout << endl;
				break;
			}
			rev++;
			max = in+1;
		}
	}

	return 0;
}