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 <cstring>

using namespace std;

int main(int argc, char *argv[]) {
  int *num, *hoge, n;
  num = new int[12];
  hoge = new int[12];
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++)
      cin >> num[i];

    int time = 0;
    while (true) {
      memset(hoge, 0, sizeof(int) * 12);
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          if (num[i] == num[j])
            hoge[i]++;
      if (memcmp(num, hoge, sizeof(int) * n) == 0)
        break;
      int *tmp = hoge;
      hoge = num;
      num = tmp;
      time++;
    }

    cout << time << endl;
    for (int i = 0; i < n; i++) {
      if (i)
        cout << ' ';
      cout << num[i];
    }
    cout << endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int n,t,s[100],sa[100];
void angel(int turn){
    int cnt;
    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 <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n&&n!=0){
		int nums[15];
		int cnts[10000];
		fill(cnts,cnts+10000,0);
		for(int i = 0; i < n; i++){
			cin>>nums[i];
			cnts[nums[i]]++;
		}
		int cnt=0;
		while(1){
			bool f=false;
			for(int i = 0; i < n; i++){
				if(nums[i]!=cnts[nums[i]]){
					nums[i]=cnts[nums[i]];
					f=true;
				}
			}
			if(!f)
				break;

			fill(cnts,cnts+10000,0);
			for(int i = 0; i < n; i++){
				cnts[nums[i]]++;
			}
			cnt++;
		}
		cout<<cnt<<endl;
		for(int i = 0; i < n; i++){
			cout<<nums[i];
			if(i==n-1)
				cout<<endl;
			else
				cout<<" ";
		}
	}

	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;

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

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

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

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(void){
	int n;
	int a;
	int ans2=0;
	int s[13];
	map<int,int> sc;
	int ans=1;
	while(1){
		ans2=0;
		cin >> n;
		for(a=0;a<=12;a++)s[a]=0;
		if(n==0)break;
		for(a=0;a<n;a++){
			cin >> s[a];
		}
		for(a=0;a<n;a++){
			sc[s[a]]++;
		}
		while(1){
			ans=1;
			for(a=0;a<n;a++){
				if(s[a]!=sc[s[a]])ans=0;
				s[a]=sc[s[a]];
			}
			if(ans==1)break;
			else{
				ans2++;
				for(a=0;a<n;a++)sc[a]=0;
				for(a=0;a<n;a++)sc[s[a]]++;
			}
		}
		cout << ans2 << endl;
		for(a=0;a<n-1;a++)cout << s[a] << ' ';
		cout << s[n-1] << endl;
	}
	return 0;
}

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