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 <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;

int main(){
	int n,v;
	map<int,int> mp;
	while(1){
		vector<int>  b ;
		cin >> n ;
		if(n==0){
			return 0;
		}
		for(int i=0;i<n;i++){
			cin >> v;
			b.push_back(v);
		}
		for(int j=0;;j++){
			vector<int>  a ;
			for(int i=0;i<=12;i++){
				mp[i]=0;
			}
			for(int i=0;i<n;i++){
			mp[b[i]] ++;
		}
			for(int i=0;i<n;i++){
				a.push_back(mp[b[i]]);
			}
			if(a == b){
				cout << j << "\n";
				cout << a[0] ;
				for(int i=1;i<n;i++){
					cout << " " << a[i] ;
				}
				cout << "\n";
				break;
			}
			else{
				b = a;
			}
		}
	}
}

C++: #include <iostream>
using namespace std;
int n,t,s[100],sa[100];
void angel(int turn){
    int cnt=0;
    for(int i=0;i<n;i++){
        for(int o=0;o<n;o++){
            if(sa[i]==sa[o]){
                cnt++;
            }
        }
        s[i]=cnt;
        cnt=0;
    }
    int check=0;
    for(int i=0;i<n;i++){
        if(s[i]!=sa[i]){
            check=1;
        }
    }
    if(check==0){
        t=turn;
    }
    else{
        for(int i=0;i<n;i++){
            sa[i]=s[i];
        }
        angel(turn+1);
    }
}
int main(void){
    cin>>n;
    while(n!=0){
        for(int i=0;i<n;i++){
            cin>>s[i];
            sa[i]=s[i];
        }
        angel(0);
        cout<<t<<endl;
        for(int i=0;i<n;i++){
            cout<<s[i]<<' ';
        }
        //cout<<endl;
        cin>>n;
    }
    return 0;
}

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

using namespace std;

int main(){
	int n[12],N,p[12],pc[12],pp[12],t,c=0,flg;

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

	while(1){
		c++;
		flg=0;

		//initialize counter
		for(int j=0;j<N;j++){
			pc[j] = 0;
		}

		//count
		for(int i=0;i<N;i++){
			//pick up
			t = n[i];

			for(int j=0;j<N;j++){
				if(t==n[j]){
					pc[i]++;
				}
			}
		}

		//make p[]
		for(int i=0;i<N;i++){
			n[i] = pc[i];
		}

		//judge
		for(int i=0;i<N;i++){
			if(n[i]!=pp[i]){
				flg=1;
			}
		}

		//make pp[]
		for(int i=0;i<N;i++){
			pp[i] = n[i];
		}

		//if made p[]
		if(flg==0){
			break;
		}
	}

	cin >> t;

	c--;

	cout << c << endl;
	for(int i=0;i<N-1;i++){
		cout << pp[i] << " ";
	}
	cout << pp[N-1] << endl;

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    short hudou[1000][101];
    for(int i=0;i<1000;i++)
      for(int j=0;j<101;j++)
	hudou[i][j]=0;
    short num[1000][n];
    for(int i=0;i<n;i++){
      cin>>num[0][i];
    }
    int cnt=0;
    while(1){
      for(int i=0;i<n;i++)
	hudou[cnt][num[cnt][i]]++;
      for(int i=0;i<n;i++)
	num[cnt+1][i]=hudou[cnt][num[cnt][i]];
      int i,flag=1;
      for(i=0;i<n;i++){
	if(num[cnt][i]!=num[cnt+1][i]){
	  flag=0;
	  break;
	}
      }
      if(flag){
	cout<<cnt<<endl;
	for(int j=0;j<n;j++){
	  cout<<num[cnt][j];
	  if(j!=n-1)
	    cout<<" ";
	}
	cout<<endl;
	break;
      }else
	cnt++;
    }
  }
  return 0;
}

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

int ans[1000][2][12];//二つ目の次元の0の0に数列の長さ、0の1に操作回数、1に答えの数列

int counter=0,flag=0;

void solve(){
	int n;
	cin >> n;
	if(n==0){flag=1;return;}
	ans[counter][0][0]=n;
	
	int S[12];//数列
	for(int i=0;i<n;i++){
		cin >> S[i];
	}
	
	bool check=false;//操作の有無のフラグ
	int time=0;//操作回数
	do{
		map<int,int> marker;
		for(int i=0;i<n;i++){
			marker[S[i]];
			marker[S[i]]++;
		}
		check=false;
		for(int i=0;i<n;i++){
			if(S[i]!=marker[S[i]]){
				check=true;
				S[i]=marker[S[i]];
			}
		}
		if(check) time++;
	}while(check);
	
	ans[counter][0][1]=time;
	for(int i=0;i<n;i++){
		ans[counter][1][i]=S[i];
	}
	counter++;
}

int main(){
	while(flag==0)solve();
	for(int i=0;i<counter;i++){
		cout << ans[i][0][1] << endl;
		for(int j=0;j<ans[i][0][0]-1;j++){
			cout << ans[i][1][j]<<" ";
		}
		cout << ans[i][1][ans[i][0][0]-1] << endl;
	}
}

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

#define NUM 12

using namespace std;

void Change(const int s[], int c[], const int n) {
	for(int i = 0; i < n; i++) {
		c[i] = 0;
	}
	for(int i = 0; i < n; i++) {
		for(int k = 0; k < n; k++) {
			if(s[i] == s[k]) {
				c[i]++;
			}
		}
	}
}

int main() {
	while(1) {
		int s[NUM];
		int c[NUM];
		int n, count = 0;
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++) {
			cin >> s[i];
		}

		while(1) {
			Change(s, c, n);
			bool endflag = true;
			for(int i = 0; i < n; i++) {
				if(s[i] != c[i]) endflag = false;
			}
			if(endflag) break;
			else {
				count++;
				for(int i = 0; i < n; i++) {
					s[i] = c[i];
				}
			}
		}

		cout << count << endl;
		for(int i = 0; i < n; i++) {
			cout << s[i] << (i != n - 1 ? " " : "");
		}
		cout << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int hudou[10000][n+1];
    for(int i=0;i<10000;i++)
      for(int j=0;j<13;j++)
	hudou[i][j]=0;
    int num[10000][n];
    for(int i=0;i<n;i++){
      cin>>num[0][i];
    }
    int cnt=0;
    while(1){
      for(int i=0;i<n;i++)
	hudou[cnt][num[cnt][i]]++;
      for(int i=0;i<n;i++)
	num[cnt+1][i]=hudou[cnt][num[cnt][i]];
      int i,flag=1;
      for(i=0;i<n;i++){
	if(num[cnt][i]!=num[cnt+1][i]){
	  flag=0;
	  break;
	}
      }
      if(flag){
	cout<<cnt-1<<endl;
	for(int j=0;j<n;j++){
	  cout<<num[cnt][j];
	  if(j!=n-1)
	    cout<<" ";
	}
	cout<<endl;
	break;
      }else
	cnt++;
    }
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;
	int count;
	int num[2][15];
	
	while (cin >> n, n){
		count = 0;
		for (int i = 0; i < n; i++){
			cin >> num[0][i];
		}
		int ct, k = 0;
		while (1){
			for (int i = 0; i < n; i++){
				ct = 0;
				for (int j = 0; j < n; j++){
					if (num[k][i] == num[k][j]) ct++;
				}
				num[1 - k][i] = ct;
			}
			ct = 0;
			for (int i = 0; i < n; i++){
				if (num[0][i] == num[1][i]) ct++;
			}
			if (ct == n){
				break;
			}
			k = 1 - k;
			count++;
		}
		
		cout << count << endl << num[0][0];
		for (int i = 1; i < n; i++){
			cout << ' ' << num[0][i];
		}
		cout << endl;
	}
	return (0);
}

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

using namespace std;

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

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int p[n], s[n], result = 0;
    for (int i = 0; i < n; i++)
      cin >> p[i];
    for (;;) {
      for (int i = 0; i < n; i++)
        s[i] = p[i];
      map<int, int> counts;
      for (int i = 0; i < n; i++)
        counts[s[i]]++;
      for (int i = 0; i < n; i++)
        p[i] = counts[s[i]];
      if (equal(p, s, n)) break;
      result++;
    }
    cout << result << endl;
    for (int i = 0; i < n; i++)
      cout << p[i] << ' ';
    cout << endl;
  }
}