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 <iomanip>
#include <utility>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;


bool mani(int a[12], int n)
{
	int b[12];
	fill(b, b + 12, 0);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (a[i] == a[j])
				b[i]++;
	bool f = true;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			f = false;
			break;
		}
	}
	for (int i = 0; i < n; i++)
		a[i] = b[i];
	return f;
}


int main()
{
	int n, a[12];
	cin >> n;
	while (true)
	{
		int c = 0;
		a[1] = -1;
		for (int i = 0; i < n; i++)
			cin >> a[i];
		if (a[0] == 0 && a[1] == -1) break;
		while (true)
		{
			if (mani(a, n))
				break;
			c++;
		}
		cout << c << endl;
		cout << a[0];
		for (int i = 1; i < n; i++)
			cout << " " << a[i];
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return b.second > a.second;
    }
    return a.first < b.first;
}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);

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

        vector<int> v;
        for (int i = 0; i < n; ++i)
        {
            int a;
            cin >> a;
            v.push_back(a);
        }
        bool update = true;
        int cnt = 0;
        while (update)
        {

            update = false;

            map<int, int> mp;
            for (int i = 0; i < n; ++i)
            {
                mp[v[i]]++;
            }

            for (int i = 0; i < n; ++i)
            {
                if (v[i] != mp[v[i]])
                    update = true;
                v[i] = mp[v[i]];
            }
            cnt++;
        }
        cout << cnt - 1 << endl;
        for (int i = 0; i < n; ++i)
        {
            if (i)
                cout << " ";
            cout << v[i];
        }
        cout << endl;
    }
    return 0;
}

C++: #include <stdio.h>
#include <string.h>

int main(void)
{
	int s[12];
	int c[12];
	
	while (1){
		int n;
		int count;
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		for (int i = 0; i < n; i++){
			scanf("%d", &s[i]);
		}
		
		count = 0;
		do {
			for (int i = 0; i < n; i++){
				c[i] = 0;
				for (int j = 0; j < n; j++){
					if (s[i] == s[j]){
						c[i]++;
					}
				}
			}
			if (memcmp(s, c, sizeof(int) * n) == 0) break;
			memcpy(s, c, sizeof(s));
			
			count++;
		} while (1);
		
		printf("%d\n", count);
		printf("%d", s[0]);
		for (int i = 1; i < n; i++){
			printf(" %d", s[i]);
		}
		puts("");
	}
	
	return (0);
}

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 < n; i++)
		    printf("%d%c", s[i], (i == n-1)? '\n':' ');
		break;
	    }

	    s = ss;
	    c++;
	}
    }
}

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

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

    return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

#define reep(i, f, n) for (int i = f; i < n; ++i)
#define rep(i, n) reep(i, 0, n)

int main()
{
    int n;
    int r;
    int tmp1[15000] = {};
    int tmp2[15000] = {};
    while (scanf("%d", &n))
    {
        if (n == 0)
            break;
        cin.ignore();
        for (int i = 0; i < n; i++)
        {
            scanf(" %d", &r);
            tmp1[i] = r;
        }
        int m = 0;
        int f = 1;
        while (f)
        {
            int chk = 0;
            for (int i=0; i < n; i++)
            {
                int cnt = 0;
                for (int j=0; j < n; j++)
                    if (tmp1[j] == tmp1[i])
                        cnt++;
                // printf("%d ",cnt);
                tmp2[i] = cnt;
                if (tmp2[i] != tmp1[i])
                    chk++;
                // printf("HOGE");
            }
            if (chk == 0)
            {
                printf("%d\n", m);
                for (int i=0; i < n - 1; i++)
                    printf("%d ", tmp2[i]);
                printf("%d\n", tmp2[n - 1]);
                f = 0;
                break;
            }
            else
            {
                m++;
                for (int i=0; i < n; i++)
                    tmp1[i] = tmp2[i];
            }
        }
    }
    return 0;
}