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 - 1; i++) {
      std::cout << newl[i] << " ";
    }
    std::cout << newl[n - 1] <<std::endl;
  }
  return 0;
}

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

int main()
{
  while (true)
  {
    int n;
    cin >> n;
    if ( n == 0 ) break;
    int* sequence = new int[n];
    for (int i=0; i<n; i++)
    {
      cin >> sequence[i];
    }
    int* result_sequence = new int[n];
    int result_num = 0;

    while (true)
    {
      for (int i=0; i<n; i++)
      {
        result_sequence[i] = 0;
      }
      for (int i=0; i<n; i++)   //  出現頻度操作
      {
        for (int j=0; j<n; j++)
        {
          if ( sequence[i] == sequence[j] )
          {
            result_sequence[i]++;
          }
        }
      }
      result_num++;

      bool flag = true;
      for (int i=0; i<n && flag; i++)
      {
        if ( sequence[i] != result_sequence[i] )
        {
          flag = false;
        }
      }
      if ( flag )   //不動点になっていれば
      {
        break;
      }
      else
      {
        for (int i=0; i<n; i++)
        {
          sequence[i] = result_sequence[i];
        }
      }
    }

    cout << result_num-1 << endl;
    for (int i=0; i<n; i++)
    {
      cout << result_sequence[i] << flush;
      if ( i == n-1 )
      {
        cout << endl;
      }
      else
      {
        cout << ' ' << flush;
      }
    }

    delete[] result_sequence;
    delete[] sequence;
  } //  データセット毎
}

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


int main(){
  int n;
  while(true){
  cin >> n;
  if(n == 0)break;
  vector<int> vec,pre;
  map<int,int> counter;
  for(int i=0;i<n;i++){
    int input; cin >> input;
    counter[input]++;
    vec.push_back(input);
  }
  
  int cnt = 0;
  while(true){
    pre.clear();
    map<int,int> pc;
    for(int i=0;i<vec.size();i++){
      pre.push_back(counter[vec[i]]);
      pc[counter[vec[i]]]++;
    }  
    counter.clear();
    counter = pc;
    if(pre == vec)break;
    vec = pre;
    cnt++;
  }
  cout << cnt << endl;
  for(int i=0;i<n;i++){
    cout << pre[i];
    i == n-1?cout << endl:cout << ' ';
  }
  }
  return 0;
}

C++: #include <map>
#include <vector>
#include <iostream>
using namespace std;
int main(){
	int i,n,x;
	for(;scanf("%d",&n),n;){
		vector<int>v,u;
		for(i=0;i<n;i++)scanf("%d",&x),v.push_back(x);
		for(x=0;;x++){
			u.clear();
			map<int,int>m;
			for(i=0;i<n;i++)m[v[i]]++;
			for(i=0;i<n;i++)u.push_back(m[v[i]]);
			if(v==u)break;
			v=u;
		}
		printf("%d\n%d",x,u[0]);
		for(i=1;i<n;i++)printf(" %d",u[i]);
		puts("");
	}
}

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

#define N 1000000

int main(){
	while(1){	
		int n, count=0;
		long before[13], after[13], c[N];
	
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i)scanf(" %ld", &before[i]);
				
		//loop
		bool flag=false;
		while(!flag){
			
			for(int i=0; i<=N; ++i) c[i]=0;
			for(int i=0; i<n; ++i) c[ before[i] ]++;
			
			for(int i=0; i<n; ++i)
				after[i]=c[ before[i] ];	
			
			flag=true;
			for(int i=0; i<n; ++i){
				if(before[i]!=after[i]){
					flag=false;
					break;	
				}
			}
					
			count++;
			for(int i=0; i<n; ++i) before[i]=after[i];
		}
		
		printf("%d\n", count-1);
		for(int i=0; i<n; ++i){
			printf("%ld", after[i]);
			if(i<n-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

using namespace std;

bool check(int a[13], int n)
{
	for(int i = 1; i < n; i++){
		if(a[i] != a[0]){
			return true;
		}
	}
	
	return false;
}

int main()
{
	int a[13], b[13], d[13], n;
	bool c[13];
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> a[i];
		}
		
		int s = 0, t;
		while(check(a, n)){
			fill(b, b+13, 0);
			fill(c, c+13, false);
			for(int i = 0; i < n; i++){
				if(!c[a[i]]){
					for(int j = 0; j < n; j++){
						if(a[i] == a[j]){
							b[a[i]]++;
						}
					}
				}
				d[i] = b[a[i]];
				c[a[i]] = true;
			}
			
			for(int i = 0; i < n; i++){
				t = a[i];
				a[i] = d[i];
				d[i] = t;
			}
			s++;
		}
		cout << s << endl;
		cout << d[0];
		for(int i = 1; i < n; i++){
			cout << " " << d[i];
		}
		cout << endl;
	}
	
	return 0;
}

C++: #include<iostream>

int main(){
	int n,ans=0,data[12],back[12];
	while(std::cin>>n){
		if(n==0)break;
		for(int i=0;i<n;i++)std::cin>>data[i],back[i]=data[i];
		while(true){
			for(int i=0;i<n;i++){
				int count=0;
				for(int j=0;j<n;j++){
					if(back[i]==back[j])count++;
				}
				data[i]=count;
			}
			bool f=true;
			for(int i=0;i<n;i++){
				if(data[i]!=back[i])f=false;
			}
			if(f)break;
			for(int i=0;i<n;i++)back[i]=data[i];
			ans++;
		}
		std::cout<<ans<<std::endl;
		for(int i=0;i<n;i++)std::cout<<data[i]<<" ";
		std::cout<<std::endl;
	}
	return 0;
}

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


bool mani(int a[12], int n)
{
	int b[12];
	fill(b, b + 12, 0);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (a[i] == a[j])
				b[i]++;
	bool f = true;
	for (int i = 0; i < n; i++)
	{
		if (a[i] != b[i])
		{
			f = false;
			break;
		}
	}
	for (int i = 0; i < n; i++)
		a[i] = b[i];
	return f;
}


int main()
{
	int n, a[12];
	cin >> n;
	while (true)
	{
		int c = 0;
		int it = 0;
		while (cin >> a[it])
		{
			it++;
			if (it == n)
				break;
		}
		if (it < n) break;
		while (true)
		{
			if (mani(a, n))
				break;
			c++;
		}
		cout << c << endl;
		cout << a[0];
		for (int i = 1; i < n; i++)
			cout << " " << a[i];
		cout << endl;
	}
	return 0;
}

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

int n,Count;
std::vector<int> Before,After;

int main(){
	while(std::cin>>n, n){
		Count=0;
		Before.clear();
		Before= After= std::vector<int>(n,0);
		for(int i=0;i<n;++i)
			std::cin>>Before[i];
		
		while(1){
			for(int i=0;i<n;++i){
				After[i]=std::count(Before.begin(),Before.end(),Before[i]);
			}
			if(Before==After)break;
			Before=After;
			++Count;
		}
		
		std::cout<<Count<<std::endl;
		for(int i=0;i<n;++i)
			std::cout<<Before[i]<<(i==n-1?"\n":" ");
	}
	return 0;
}