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 n;
    while(cin >> n, n != 0){
        int v[n];
        int cnt = 0;
        for(int i=0; i<n; ++i){
            cin >> v[i];
        }
        while(1){
            int tmp[n];
            bool flug = true;
            for(int i=0; i<n; ++i){
                tmp[i] = 0;
                for(int j=0; j<n; ++j)
                    if(v[i] == v[j]) ++tmp[i];
                if(v[i] != tmp[i]) flug = false;
            }
            if(flug) break;
            cnt++;
            for(int i=0; i<n; ++i)
                v[i] = tmp[i];
        }
        cout << cnt << endl;
        for(int i=0; i<n; ++i)
            cout << ((i!=0)?" ":"") << v[i];
        cout << endl;
    }
    return 0;
}

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

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] << " ";
        }

        std::cout << std::endl;
    }

    return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef pair<pint, int> ppint;
typedef pair<int, pint> pintp;
typedef unsigned int uint;
typedef long long llint;
typedef unsigned long long int ullint;

//container util
//------------------------------------------
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define EXIST(v,i) (find((v).begin(), (v).end(), i) != (v).end())
#define ERASE(v,i) (v).erase(remove((v).begin(),(v).end(),i),(v).end())
#define me (*this)

//repetition
//------------------------------------------
#define rep(i,s) for(int i=0; i<(int)(s); i++)

//constant
//--------------------------------------------
const int INF = 100000000;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLEAR(a) memset((a), 0 ,sizeof(a))

//debug
#define debug(x)  cerr << #x << " = " << (x) << endl

struct POS {
	int x, y;
};

POS vec[4] = {
	{1, 0}, // ツ右
	{0, -1}, // ツ湘」
	{-1, 0}, // ツ債カ
	{0, 1} // ツ可コ
};

vint nextAry(vint prev) {
	vint ret;
	rep(i,prev.size()) {
		ret.push_back(count(all(prev), prev[i]));
	}
	return ret;
}

int main() {
	while(1) {
		static int n;
		cin >> n;
		if(!n)
			break;
		vint ary(n);
		rep(i,n) {
			cin >> ary[i];
		}
		int ans = 0;
		bool f = true;
		while(f) {
			ans++;
			vint next = nextAry(ary);
			if(next == ary) {
				f = false;
			}
			ary = next;
		}
		cout << ans - 1 << endl;
		rep(i,ary.size()) {
			printf("%d ", ary[i]);
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool OperationFA( int *an , int n ){
	bool ret = true;
	int *cn = new int[n];
	
	for(int i = 0; i < n; i++){
		int mode = 0;
		for(int j = 0; j < n; j++){
			if( an[j] == an[i] ) mode++;
		}
		cn[i] = mode;
	}
	for(int i = 0; i < n; i++){
		if( an[i] != cn[i] ) ret = false;
		an[i] = cn[i];
	}
	delete []cn;
	return ret;
}
int main(void){
	while( true ){
		int n;
		int cnt = 0;
		int *an;

		cin >> n;
		if( n == 0 ) break;
		an = new int[n];

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

		while ( true ){
			if( OperationFA( an, n ) ) break;
			cnt++;
		}

		cout << cnt << '\n';
		cout << an[0];
		for(int i = 1; i < n; i++){
			cout << ' ' << an[i];
		}
		cout << '\n';
		delete []an;
	}
	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];

			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;
		}
	}

	return 0;
}

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

using namespace std;

int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0){ break; }
		vector<int> s(n);
		map<int, int> table;
		for(int i = 0; i < n; ++i){
			cin >> s[i];
			if(table.find(s[i]) == table.end()){
				table.insert(pair<int, int>(s[i], table.size() + 1));
			}
			s[i] = table[s[i]];
		}
		int answer = 0;
		vector<int> prev = s;
		while(true){
			vector<int> b(n + 1, 0);
			for(int i = 0; i < n; ++i){ ++b[s[i]]; }
			for(int i = 0; i < n; ++i){ s[i] = b[s[i]]; }
			if(prev == s){ break; }
			prev = s;
			++answer;
		}
		cout << answer << endl;
		for(int i = 0; i < n; ++i){
			cout << s[i] << (i == n - 1 ? '\n' : ' ');
		}
	}
	return 0;
}

C++: #include<iostream>

int main(){
	int n,ans=0,data[12],back[12];
	while(std::cin>>n){
		if(n==0)break;
		for(int i=0;i<n;i++)std::cin>>data[i],back[i]=data[i];
		while(true){
			for(int i=0;i<n;i++){
				int count=0;
				for(int j=0;j<n;j++){
					if(back[i]==back[j])count++;
				}
				data[i]=count;
			}
			bool f=true;
			for(int i=0;i<n;i++){
				if(data[i]!=back[i])f=false;
			}
			if(f)break;
			memcpy(back,data,sizeof(data));
			ans++;
		}
		std::cout<<ans<<std::endl;
		for(int i=0;i<n;i++)std::cout<<data[i]<<" ";
		std::cout<<std::endl;
	}
	return 0;
}