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 <vector>
#include <algorithm>
using namespace std;

int main(){
    int n, a, ans, eqCount;
    vector<int> foo1, foo2;

    while( cin >> n , n ){
        ans = 0;
        foo1.clear();
        for(int i=0 ; i<n ; i++){
            cin >> a;
            foo1.push_back(a);
        }
        while( foo1 != foo2 ){
            ans++;
            foo2.clear();
            for(int i=0 ; i<foo1.size() ; i++){
                a = count( foo1.begin() , foo1.end() , foo1.at(i) );
                foo2.push_back(a);
            }
            swap( foo1 , foo2 );
        }
        cout << (ans-1) << endl;
        for(int i=0 ; i<foo2.size() ; i++){
            cout << foo2[i];
            ( i == foo2.size()-1 )? cout << endl : cout << " " ;
        }
    }
}

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

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

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

using namespace std;

int main(){
  int n;

  while(cin >> n ,n){
    vector<int> v(n);

    for(int i = 0 ; i < n ; i++)
      cin >> v[i];

    int cnt = 0;
    while(true){
      vector<int> next(n);
      for(int i = 0 ; i < n ; i++){
	next[i] = count(v.begin(),v.end(),v[i]);
      }

      if(v == next) break;
      cnt++;
      v = next;
    }
    cout << cnt << endl;
    for(int i = 0 ; i < n ; i++){
      if(i) cout << " " << v[i];
      else cout << v[i];
    }
    cout << endl;;
  }

  return 0;
}

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


void f(std::vector<int> &vector, const int &count = 0){
	bool flag = true;
	std::vector<int> freq(12, 0);
	for (const auto &i : vector) {
		++freq.at(i - 1);
	}
	for (auto &i : vector) {
		flag = (i == freq.at(i - 1)) && flag;
		i = freq.at(i - 1);
	}
	if (flag) {
		std::cout << count << "\n";
		for (auto i = 0; i < vector.size() - 1; ++i){
			std::cout << vector.at(i) << " ";
		}
		std::cout << vector.back() << "\n";
	}
	else {
		f(vector, count + 1);
	}
}
int main() {
	int n;
	std::cin >> n;
	while (n != 0) {
		std::vector<int> vec(n);
		for (auto &i : vec) {
			int temp;
			std::cin >> temp;
			i = temp;
		}
		f(vec);
		std::cin >> n;
	}
	return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,s[22],p[22];
  while(cin >> n && n){
    for(int i = 0; i < n; i++) cin >> p[i];

    bool f = true;
    int m = 0;
    while(f){
      f = false;
      for(int i = 0; i < n; i++) s[i] = p[i];
      for(int i = 0; i < n; i++){
	p[i] = 0;
	for(int j = 0; j < n; j++){
	  if(s[i] == s[j])p[i]++;
	}
	if(s[i]!=p[i]) f = true;
      }
      if(!f) break;
      m++;
    }
    cout << m << endl;
    for(int i = 0; i < n; i++) cout << p[i] << (i+1==n?'\n':' ');
  }
}

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

using namespace std;

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

int main()
{
	int n;
	
	while(cin>>n && n){
		int a[12], b[13], c[12], t=0, s;
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		fill(c, c+n, 0);
		while(1){
			t++;
			fill(b, b+13, 0);
			for(int i = 0; i < n; i++){
				b[a[i]]++;
			}
			s = 1;
			for(int i = 1; i <= n; i++){
				s = max(b[s], b[i]);
			}
			if(check(a, c, n)){
				break;
			}
			
			for(int i = 0; i < n; i++){
				c[i] = a[i];
				a[i] = b[a[i]];
			}
		}
		
		cout << (t-2) << endl;
		cout << a[0];
		for(int i = 1; i < n; i++){
			cout << " " << a[i];
		}
		cout << endl;
	}
	
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int main(){
	ios::sync_with_stdio(false);

	int n;
	int s[12];
	int count[12] = {0};
	int temp;
	int cnt=0;
	int l;

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

		l = 0;

		REP(i, n)
			cin >> s[i];
		
		while (1){

			REP(i, n){
				temp = s[i];
				REP(j, n){
					if (s[j] == temp)
						count[i]++;
				}
				if (s[i] == count[i])
					cnt++;
			}

			if (cnt == n)
				break;

			cnt = 0;
			
			REP(i, n){
				s[i] = count[i];
				count[i] = 0;
			}

			l++;
		}

		printf("%d\n", l);

		REP(i, n){
			printf("%d ", count[i]);
		}
		printf("\n");
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	
	while (cin >> n , n){
		int c = 0, line[12][12] = {0};

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

		for (int i = 0; i < n; i++){
			line[c + 1][i] = count(line[c], line[c] + n, line[c][i]);
		}

		while (1){
			int cnt = 0;
			for (int i = 0; i < n; i++){
				if (line[c][i] == line[c + 1][i]){
					cnt++;
				}
			}
			
			if (cnt == n){
				cout << c << endl;
				cout << line[c][0];
				for (int i = 1; i < n; i++){
					cout << " " << line[c][i];
				}
				cout << endl;
				break;
			}

			c++;

			for (int i = 0; i < n; i++){
				line[c + 1][i] = count(line[c], line[c] + n, line[c][i]);
			}
		}
	}
	return (0);
}