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++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<int> S;
		vector<int> S_old;
		for(int i=0;i<n;i++){
			int s;
			scanf("%d",&s);
			S.push_back(s);
		}

		int c=0;
		while(1){
			map<int,int> freq;
			S_old = S;
			for(int i=0;i<S.size();i++){
				freq[S[i]]++;
			}

			for(int i=0;i<S.size();i++){
				S[i] = freq[S[i]];
			}

			if(S == S_old) break;
			c++;
		}

		cout << c << endl;
		for(int i=0;i<S.size();i++){
			printf("%d%s",S[i],i==S.size()-1 ? "\n" : " ");
		}

	}
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	const int N = 12;
	int n,i,c;
	int a[N],b[N],(*pre)[N], (*next)[N];
	for(;;)
	{
		scanf("%d",&n);
		if(!n) break;
		for(i = 0; i < n; ++i)
			scanf("%d", &a[i]);

		c = 0;
		pre = &a;
		next = &b;
		for(;;)
		{
			for(i = 0; i < n; ++i)
			{
				(*next)[i] = count(*pre, *pre+N, (*pre)[i]);
			}
			{
				bool b=true;
				for(i = 0; i < n; ++i)
					if((*pre)[i] != (*next)[i])
						b = false;
				if(b) break;
			}
			//if(equal(*pre, *pre+N, *next))
			//	break;
			swap(next, pre);
			c++;
		}
		printf("%d\n", c);
		for(i = 0; i < n; ++i)
			printf("%s%d", (i?" ":""), (*pre)[i]);
		putchar('\n');
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int a[100];
		int d[21];
		string b[2] = { "","" }, e;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			e = to_string(a[i]);
			b[1] += e;
		}
		int sum = 0;
		while (b[0] != b[1]) {
			int y = 0;
			int x = 1;
			for (int i = 0; i < 20; i++)
				d[i] = 0;
			for (int i = 0; i < n; i++)
				d[a[i]]++;
			b[y] = "";
			for (int i = 0; i < n; i++) {
				a[i] = d[a[i]];
				e = to_string(a[i]);
				b[y] += e;
			}
			sum++;
			swap(b[0], b[1]);
		}
		cout << sum - 1 << endl;
		for (int i = 0; i < n; i++) {
			if (i == 0)
				cout << a[i];
			else
				cout << " " << a[i];
		}
		cout << endl;
	}
}

C++: #include <iostream>

int main(){
  //nªzñ·³,countªvZñÌÂàè
  int n,count;
  while(std::cin >> n){
    //std::cout << n << std::endl;
    if(!n) {
      break;
    }
    int s[n];
    bool flag;
    int cnt[n];
    int cnt_of[n];
    int new_s[n];
    int old_s[n];
    
    //üÍtF[Y
    for(int i=0;i<n;i++){
      std::cin >> s[i];
    }

    for(int ans=1;;ans++){
      //½Â é©ð¦é
      cnt[0]=s[0];
      cnt_of[0]=1;
      int count=0;
      
      //iÔÚª¡ÜÅÉoÄ«½©mF
      for(int i=1;i<n;i++){
	for(int j=0;;j++){
	  if(cnt[j]==s[i]){
	    cnt_of[j]++;
	    break;
	  }
	  if(j==count){
	    count++;
	    cnt[count]=s[i];
	    cnt_of[count]=1;
	    //	    std::cout << count <<"count+" << i << std::endl;
	    break;
	  }
	}
      }//iÔÚ[v
      
      flag = true;
      //eiÉlðãü
      for(int i=0;i<n;i++){
	for(int j=0;j<=count;j++){
	  if(cnt[j]==s[i]){
	    new_s[i]=cnt_of[j];
	    break;
	  }
	}
	if(new_s[i]!=s[i]){
	  flag = false;
	  s[i]=new_s[i];
	}
      }
      
      //mFpoÍ

      /*      for(int i=0;i<n;i++){
	std::cout << new_s[i] << " ";
      }
      std::cout << std::endl;
      */

      if(flag){
	std::cout << ans << std::endl;
	//mFpoÍ
	for(int i=0;i<n;i++){
	  std::cout << new_s[i] << " ";
	}
	std::cout << std::endl;
	break;
      }
    }
  }//while
}

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){
				for(int j=0; j<n; ++j){
					if(before[i] == before[j]) c[i]++;
				}
			}
				
			for(int i=0; i<n; ++i) after[i]=c[i];	
			
			flag=true;
			for(int i=0; i<n; ++i){
				if(before[i]!=after[i]){
					flag=false;
					break;	
				}
			}
			/*
			for(int i=0; i<n; ++i){
				printf("%ld", after[i]);
				if(i<n-1) printf(" ");
			}
			printf("\n");
			*/0
			
			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 <stdio.h>
#include <string>
#include <string.h>
#include <queue>
#include <cmath>

#define int64 long long int

using namespace std;
typedef pair<int, int> P;

int freq(int *, int);

int main()
{
    int n, S[12], buf, count;
    
    while(1){
        cin >> n;
        if(n == 0) break;
        
        for (int i=0; i<n; i++) {
            cin >> buf;
            S[i] = buf;
        }
        
        count = 0;
        while(freq(S, n)) count++;
        
        cout << count << endl;
        for(int i=0; i<n-1; i++) cout << S[i] << ' ';
        cout << S[n-1] << endl;
        
    }
    
    return 0;
}

int freq(int *S, int n){
    int C[12] = {0}, buf, flag = 0;
    for(int i=0; i<n; i++){
        buf = S[i];
        for(int j=0; j<n; j++){
            if(S[j] == buf) C[i]++;
        }
    }
    for(int i=0; i<n; i++){
        if(S[i] != C[i]){
            flag = 1;
            break;
        }
    }
    if(flag){
        for(int i=0; i<n; i++) S[i] = C[i];
        return 1;
    }
    return 0;
}

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";
				for(int i=0;i<n;i++){
					cout << a[i] << " ";
				}
				cout << "\n";
				break;
			}
			else{
				b = a;
			}
		}
	}
}