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 <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

int main(){
    int n;
    vi p;
    while(cin >> n, n){
        rep(i, n){int m; cin >> m; p.pb(m); }

        vi v(n, 0);
        int count = 0;
        while(true){
            bool finish = true;
            for(int i=0;i < n; i++){
                if(p[i] != v[i]) finish = false;
            }
            if(finish) break;
            v = p;
            for(int i=0; i < n; i++){
                int c = 0;
                for(int j=0; j < n; j++){
                    if(v[i] == v[j]) c++;
                }
                p[i] = c;
            }
            count++;
        }
        cout << count-1 << endl;
        for(int i=0; i < n; i++){
            if(i == 0) cout << v[i];
            else cout << " " << v[i];
        }
        cout << endl;
    }
}

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

//変換
vector<int> into(vector<int> s){
  map<int, int> mp;
  for(int i=0; i<s.size(); i++){
    if(mp.find(s[i])==mp.end()){
      mp.insert(map<int, int>::value_type(s[i], 1));
    }
    else{
      mp[s[i]]++;
    }
  }
  vector<int> ret;
  for(int i=0; i<s.size(); i++){
    ret.push_back(mp[s[i]]);
  }
  return ret;
}

//判定
bool judge(vector<int> a, vector<int> b){
  for(int i=0; i<a.size(); i++)
    if(a[i]!=b[i])return false;
  return true;
}

int main(){
  int n;
  while(true){
    vector<int> pre, now;
    cin>>n;
    if(n==0)break;
    for(int i=0; i<n; i++){
      int tmp;
      cin>>tmp;
      pre.push_back(tmp);
    }
    int ans=0;
    now=into(pre);
    while(!judge(pre, now)){
      pre=now;
      now=into(pre);
      ans++;
    }
    cout<<ans<<endl;
    for(int i=0; i<n; i++){
      if(i!=n-1)cout<<now[i]<<' ';
      else cout<<now[i]<<endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>

int main(){
	int n,i,j;
	int ar[12];
	int old_ar[12];
	int t;
	while(1){
	scanf("%d",&n);
		if(n==0)return 0;
	for(i=0;i<n;i++){
		scanf("%d",&ar[i]);
		old_ar[i]=ar[i];
	}
	t=0;
	int c;
	while(1){
		t++;
		for(i=0;i<n;i++){
			c=0;
			for(j=0;j<n;j++)if(old_ar[i]==old_ar[j])c++;
			ar[i]=c;
		}
		for(i=0;i<n;i++)if(ar[i]!=old_ar[i])break;
		if(i==n)break;
		for(i=0;i<n;i++)old_ar[i]=ar[i];
	}
	printf("%d\n",t-1);
	for(i=0;i<n;i++)printf("%d%c",ar[i],i==n-1?'\n':' ');
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[2][12]={};
        for(int i=0;i<n;i++){
                cin>>ans[0][i];
                ans[1][i]=ans[0][i];
        }
        for(int i=0;;i++){
            int num[100]={};
            for(int j=0;j<n;j++)num[ans[0][j]]++;
            bool rever=1;
            for(int j=0;j<n;j++){
                ans[0][j]=num[ans[0][j]];
                if(ans[0][j]!=ans[1][j])rever=0;
            }
            if(rever){
                cout<<i<<endl;
                for(int j=0;j<n-1;j++)cout<<ans[0][j]<<" ";
                cout<<ans[0][n-1]<<endl;
                break;
            }
            for(int j=0;j<n;j++)ans[1][j]=ans[0][j];
        }
    }
}

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

using namespace std;

int main() {
  int n;
  while(cin >> n, n != 0){
    int s[2][n];
    for(int i = 0; i < n ; i++)
    {
      cin >> s[0][i];
    }
    bool fixed = false;
    int src_index = 0;
    int operation_count = 0;
    while(!fixed)
    {
      map<int, int> appearance_map;
      for(int i = 0; i < n ; i ++)
      {
        ++appearance_map[s[src_index][i]];
      }
      fixed = true;
      for(int i = 0; i < n; i++) {
        s[1-src_index][i] = appearance_map[s[src_index][i]];
        if(s[0][i] != s[1][i]){
          fixed = false;
        }
      }
      if(fixed)break;
      src_index = 1 - src_index;
      ++operation_count;
    }
    cout << operation_count << endl;
    for(int i = 0; i < n; i++) {
      cout << s[0][i];
      if(i < n - 1) cout << " ";
    }
    cout << endl;
  }
}

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<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		vi array(n);
		rep(i, n)
			scanf("%d", &array[i]);

		int cnt;
		for(cnt=0;; ++cnt){
			vi tmp(n, 0);
			rep(i, n) rep(j, n)
				tmp[i] += array[i] == array[j];
			bool changed = false;
			rep(i, n){
				if(array[i] != tmp[i]){
					changed = true;
					array[i] = tmp[i];
				}
			}
			if(!changed)
				break;
		}
		printf("%d\n", cnt);
		rep(i, n)
			printf("%s%d", i?" ":"", array[i]);
		puts("");
	}
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int n, s[100], k[100];

int main(){
	while (cin >> n&&n){
		REP(i, n){
			cin >> s[i];
		}
		int num = 0;
		bool f = 1;
		while (f){
			int co[100] = {};
			REP(i, n){
				k[i] = s[i];
				co[s[i]]++;
			}
			REP(i, n){
				s[i] = co[s[i]];
			}
			REP(i, n){
				if (s[i] != k[i])break;
				if (i == n - 1){
					f = 0; num--;
				}
			}
			num++;
		}
		cout << num << endl;
		REP(i, n){
			i == n - 1 ? cout << s[i] << endl : cout << s[i] << " ";
		}
	}
}