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<map>
using namespace std;
typedef map<int, int> mii;

bool check(int *numl, int *newl, int n = 0){
  for (int i = 0; i < n; i++) {
    if(numl[i] != newl[i])return false;
  }
  return true;
}

void printline(int *line, int n){
  std::cout << "printline:" << std::endl;
  for (int i = 0; i < n; i++) {
    std::cout << line[i] << " ";
  }
  std::cout << std::endl;
}

int main(){
  int n;
  while(cin >> n, n){
    int numl[n], newl[n], ans = 0;
    mii counter;

    for (int i = 0; i < n; i++) {
      cin >> numl[i];
      
      if(counter.find(numl[i]) == counter.end()){
        counter[numl[i]] = 1;
      }else{
        counter[numl[i]]++; 
      }
    }
    
    while(!check(newl, numl, n)){
      ans++;
      for (int i = 0; i < n; i++) {
        newl[i] = numl[i];
        numl[i] = counter[numl[i]];
      }
      
      counter.clear();

      for (int i = 0; i < n; i++) {
        if(counter.find(numl[i]) == counter.end()){
          counter[numl[i]] = 1;
        }else{
          counter[numl[i]]++; 
        }        
      }

      //printline(numl, n);
    }
    std::cout << ans - 1 << std::endl;
    for (int i = 0; i < n; i++) {
      std::cout << newl[i] << " ";
    }
    std::cout << std::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++){
					if(i != 0) cout << " ";
					cout << data[i];
				}
				cout << endl;
				break;
			}
			rev++;
			max = in;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime> 

using namespace std;
int main(){   
	int n,c;  
	int r=0;   
	while(cin >> n && n){      
		c = 0;       
		vector<int> one(n);
		vector<int> two(n);    
		for(int i=0;i<n;i++){ 
			cin >> one[i];      
		}        
		while(one != two){           
			for(int k=0;k<one.size();k++){      
				r=0;            
				for(int i=0;i<one.size();i++)if(one[k]==one[i])r++;     
				two[k]=r;            
			}          
			c++;      
			swap(one,two);    
		}         
		cout << c-1 << endl;       
		for(int i=0;i<n;i++){     
			if(i)cout << " ";     
			cout << one[i];       
		}       
		cout << endl; 
	}
}

C++: #include <cstdio>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
int a[2][13], n, f, c;
int main()
{
    while (scanf("%d", &n), n) {
        rep(i, n) scanf("%d", &a[0][i]);
        c = f = 0;
        while (true) {
            bool ok = true;
            rep(i, n) if (a[0][i] != a[1][i]) ok = false;
            if (ok) break;
            rep(i, n) a[1-f][i] = std::count(a[f], a[f] + n, a[f][i]);
            f = 1 - f;
            c++;
        }
        printf("%d\n", c-1);
        rep(i, n-1) printf("%d ", a[f][i]); printf("%d\n", a[f][n-1]);
    }
    return 0;
}

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

int main() {
	int n;

	while(cin >> n, n) {
		vector<int> v1, v2;
		int count = 0;

		for(int i = 0; i < n; i++) {
			int tmp;
			cin >> tmp;
			v1.push_back(tmp);
		}

		while(1) {
			count++;
			for(int i = 0; i < n; i++) {
				int tmp = 0;
				for(int j = 0; j < n; j++) {
					if(v1[i] == v1[j])
						tmp++;
				}
				v2.push_back(tmp);
			}

			if(v1 == v2)
				break;
			v1 = v2;
			v2.clear();
		}

		cout << count - 1 << endl;
		cout << v1[0];
		for(int i = 1; i < n; i++)
			cout << " " << v1[i];
		cout << endl;
	}

	return 0;
}

C++: //Name: Operation of Frequency of Appearance
//Level: 2
//Category: シミュレーション
//Note:

/**
 * 問題文のとおりにシミュレーションする。
 * 出現頻度操作は、各数の出現回数を数えるパスと、全体を変換するパスの2パスに分けると良い。
 *
 * オーダーは不明。
 */
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

bool solve() {
    int N;
    cin >> N;
    if(!N) return false;

    vector<int> v(N);
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
    }
    int ans = 0;
    while(true) {
        vector<int> next(N);
        unordered_map<int,int> freq;
        for(int i : v) {
            freq[i]++;
        }
        for(int i = 0; i < N; ++i) {
            next[i] = freq[v[i]];
        }
        if(next == v) break;
        ++ans;
        next.swap(v);
    }
    cout << ans << endl;
    for(int i = 0; i < N; ++i) {
        if(i > 0) cout << ' ';
        cout << v[i];
    }
    cout << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(solve()) ;
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j,p;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    vi a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(p,100000){
      vi num(101,0);
      rep(i,n)num[a[i]]++;
      rep(i,n)b[i]=num[a[i]];
      bool f=true;
      rep(i,n)if(a[i]!=b[i])f=false,a[i]=b[i];
      if(f)break;
    }
    cout<<p<<endl;
    rep(i,n){
      if(i)cout<<" ";
      cout<<a[i];
    }
    cout<<endl;
  }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    while (cin >> n, n)
    {
        vector<int> s(n), v(n);
        rep(i, n) cin >> s[i];
        int cnt = 0;
        bool flag = 0;
        while (flag != 1)
        {
            copy(ALL(s), v.begin());
            rep(i, n) s[i] = count(ALL(v), v[i]);
            rep(i, n)
            {
                if (s[i] != v[i])
                    break;
                if (i == n - 1)
                    flag = 1;
            }
            cnt++;
        }
        OP(cnt - 1);
        rep(i, n) i != n - 1 ? cout << s[i] << " " : OP(s[i]);
    }
    return 0;
}