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

bool same(int n, int *array, int *rs)
{
  int cnt = 0;

  for (int i = 0; i < n; i++){
    if (array[i] == rs[i]){
      cnt++;
    }
  }

  return (n == cnt ? true : false);
}

int main()
{
  int n;
  int array[12];

  while (scanf("%d", &n), n){
    for (int i = 0; i < n; i++){
      scanf("%d", &array[i]);
    }
    for (int op = 0;; op++){
      int rs[12];
      for (int i = 0; i < n; i++){
        int cnt = 0;
        for (int j = 0; j < n; j++){
          if (array[i] == array[j]){
            cnt++;
          }
        }
        rs[i] = cnt;
      }
      if (same(n, array, rs)){
        printf("%d\n", op);
        for (int i = 0; i < n - 1; i++){
          printf("%d ", rs[i]);
        }
        printf("%d\n", rs[n - 1]);
        break;
      }
      memcpy(array, rs, sizeof(array));
    }
  }

  return (0);
}

C++: #include<iostream>
using namespace std;
int n;
int t[12];
int u[12];

bool check(){
  for(int i=0;i<n;i++){
    if(t[i]!=u[i])return false;
  }
  return true;
}

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++)cin>>t[i];

    for(int i=0;i<=10000;i++){

      for(int j=0;j<n;j++){u[j]=t[j];t[j]=0;}
      
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  if(u[j]==u[k])t[j]++;
	}
      }      
      if(check()){
	cout<<i<<endl;
	break;
      }
    }

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

C++: #include<iostream>
using namespace std;
int main(){
  int a[12],b[12],n;
  while(cin >>n,n){
    for(int i=0; i<n; i++){cin >>a[i];}
    for(int i=0;;i++){
      for(int j=0; j<n; j++){
	int s = 0;
	for(int k=0; k<n; k++){
	  if(a[j] == a[k]){s++;}
	}
	b[j] = s;
      }
      bool f = true;
      for(int j=0; j<n; j++){
	if(a[j] != b[j]){f = false;}
	a[j] = b[j];
      }
      if(f){
	cout <<i<<endl<<a[0];
	for(int j=1; j<n; j++){
	  cout <<" "<<a[j];
	}
	cout <<endl;
	break;
      }
    }
  }
  return 0;
}

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

using namespace std;

struct DATA{
  int x;
  int isFound;
};

vector<int> Operation(vector<int>);

int main(){
  int i, n, a, count;
  vector<int> before, after;

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

    for(i=0; i<n; ++i){
      cin >> a;
      before.push_back(a);
    }

    count = 0;
    while(1){
      after = Operation(before);
      if(after == before) break;
      before = after;
      ++count;
    }

    cout << count << endl;
    for(i=0; i<after.size()-1; ++i)
      cout << after[i] << " ";
    cout << after[after.size()-1] << endl;

    before.clear();
    after.clear();
  }
  return 0;
}

vector<int> Operation(vector<int> before){
  int i, j, count;
  vector<int> list, after;
  DATA onedata;
  vector<DATA> data;

  for(i=0; i<before.size(); ++i){
    onedata.x = before[i];
    onedata.isFound = 0;
    data.push_back(onedata);
  }

  i = 0;
  while(1){
    count = 0;
    list.clear();
    for(j=i; j<data.size(); ++j){
      if(data[j].isFound == 0 && data[i].x == data[j].x){
        data[j].isFound = 1;
        list.push_back(j);
        ++count;
      }
    }

    for(j=0; j<list.size(); ++j)
      data[list[j]].x = count;

    j = 1;
    while(1){
      if(i+j == data.size() || data[i+j].isFound == 0){
        i += j;
        break;
      }      
      ++j;
    }
    if(i == data.size()) break;
  }

  for(i=0; i<data.size(); ++i)
    after.push_back(data[i].x); 

  return after;

}

C++: #include<iostream>

using namespace std;

int main()
{
	int a,n,i,j;
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		int array[20]={0};
		int array2[20]={0};
		int num[20]={0};
		int conv[20]={0};
		
		for(i=1;i<n+1;i++)
		{
			cin >> a ;
			array[a]++;
			num[i]=array2[i]=a;
		}
		
		for(j=0;;j++)
		{
			for(i=1;i<13;i++)
				conv[i]=0;
				
			for(i=1;i<13;i++)
			{
/*////////////////////////////////////////////////////////
			for(int ci=1;ci<13;ci++)
			{
				cout << num[ci] << " " ;
			}
				cout << endl;
			for(int ki=1;ki<13;ki++)
			{
				cout << array[ki] << " " ;
			}
				cout << endl;
				cout << endl;
////////////////////////////////////////////////////////*/
				if(array[i]!=0)
				{
					for(int k=1;k<13;k++)
					{
						if(num[k]==i && conv[k]==0)
						{
							num[k]=array[i];
							conv[k]=1;
						}
					}
					array[i]=0;
				}
			}
			for(i=1;i<13;i++)
			{
				array[num[i]]++;
			}
			
			for(i=1;i<13;i++)
			{
				if(array2[i]!=num[i])
					break;
			}
			if(i==13)
				break;
			
			for(i=1;i<13;i++)
				array2[i]=num[i];
			
		}
		cout << j << endl;
		
		int first=1;
		
		for(i=1;i<13;i++)
		{
			
			if(num[i]!=0 && first==1)
			{
				cout << num[i] ;
				first=0;
			}
			else if(num[i]!=0)
				cout << " " << num[i] ;
		}
		cout << endl;
	}
}

C++: #include <iostream>]
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
int main()
{
  int n;
  int a[12];
  int s[12];
  while(true){
    map<int,int>Map;
    cin>>n;
    if(n==0){break;}  
    rep(i,n){
      cin>>a[i];
    }
    for(int cnt=0;cnt<n*3;cnt++)
    {Map.clear();
      rep(i,n){
        Map[a[i]]++;
      }
      bool flag=true;
      rep(i,n)
      {
        flag=flag&&(Map[a[i]]==a[i]);
        s[i]=Map[a[i]];
      }
      if(flag)
      {
        cout<<cnt<<endl;
        rep(i,n){
          if(i!=0){
            cout<<" ";
          }
          cout<<a[i];
        }
        cout<<endl;
        break;
      }
      rep(i,n){
        a[i]=s[i];
      }
    }
  }
  return 0;
}