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>
using namespace std;
int main(void){
  char d1[12],d2[12];
  int n1,n2;
  int n,a;
  while(cin>>n,n!=0){
    for(int i=0;i<n;i++){
      scanf("%d",&d2[i]);
      d2[i]+='0';
    }
    a=0;
    n1=0;
    n2=atoi(d2);
    while(n1!=n2){
      n1=n2;
      for(int j=0;j<n;j++){
	d1[j]=d2[j];
	d2[j]=0;
      }
      for(int j=0;j<n;j++){
	for(int k=0;k<n;k++){
	  if(d1[j]==d1[k]){
	    d2[j]++;
	  }
	}
	d2[j]+='0';
      }
      n2=atoi(d2);
      a++;
    }
    cout<<a-1<<endl;
    for(int j=0;j<n-1;j++){
      printf("%c ",d1[j]);
    }
    cout<<d1[n-1]<<endl;
  }
  return 0;
}

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

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

C++: #include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n,s[22],p[22];
  while(cin >> n && n){
    for(int i = 0; i < n; i++) cin >> p[i];

    bool f = true;
    int m = 0;
    while(f){
      f = false;
      for(int i = 0; i < n; i++) s[i] = p[i];
      for(int i = 0; i < n; i++){
	p[i] = 0;
	for(int j = 0; j < n; j++){
	  if(s[i] == s[j])p[i]++;
	}
	if(s[i]!=p[i]) f = true;
      }
      m++;
    }
    cout << m << endl;
    for(int i = 0; i < n; i++) cout << p[i] << (i+1==n?'\n':' ');
  }
}

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

using namespace std;

int main(){
	int n;
	while(1){
		cin >> n;
		if(n==0) break;
		int a[n];
		int e = 0;
		for(int i=0;i<n;i++) cin >> a[i];
		while(1){
			int b[n],c[n];
			for(int i=0;i<n;i++) b[i] = 0;
			for(int i=0;i<n;i++) b[a[i]-1]++;
			for(int i=0;i<n;i++) c[i] = b[a[i]-1];
			int d = 0;
			for(int i=0;i<n;i++) if(a[i]==c[i]) d++;
			if(d==n) break;
			e++;
			for(int i=0;i<n;i++) a[i] = c[i];
		}
		cout << e << endl;
		cout << a[0];
		for(int i=1;i<n;i++) cout << " " << a[i];
		cout << endl;
	}
}

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

int main(){
  int n;
  int s[111];
  while(1){
    cin >> n;
    int ans=0,cou=0;
    if(n == 0) break;
    for(int i=0;i<n;i++){
      cin >> s[i];
    }
    while(cou != n){
      cou = 0;
      int cheak[111]={0};
      for(int i=0;i<n;i++){
	if(cheak[s[i]] == 0){
	  for(int j=0;j<n;j++){
	    if(s[i] == s[j]){
	      cheak[s[i]]++;
	    }
	  }
	}
      }
      for(int i=0;i<n;i++){
	s[i] = cheak[s[i]];
	if(cheak[s[i]] == s[i]){
	  cou++;
	}
      }
      ans++;
    }
    cout << ans-1 << endl;
    for(int i=0;i<n;i++){
      cout << s[i];
      if(i == n-1) cout << endl;
      else cout << " ";
    }
  }
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	int n, cnt, i, j, inpt, sousa_cnt;
	vector<int> S, P;
	vector<int> *Sp, *Pp, *tmpp;
	Sp=&S;
	Pp=&P;
	while(true){
		cin>>n; if(n==0)break;
		Pp->resize(n, 0);
		Sp->resize(n, 0);
		for(i=0;i<n;i++){
			cin>>inpt;
			(*Sp)[i] = inpt;
		}
		for(sousa_cnt=0; true; sousa_cnt++){
			for(i=0;i<n;i++){
				cnt = 0;
				for(j=0;j<n;j++){
					if((*Sp)[i] == (*Sp)[j]) cnt++;
				}
				(*Pp)[i] = cnt;
			}
			for(i=0;i<n;i++){
				if((*Pp)[i] != (*Sp)[i]) break;
			}
			if(i==n) break;
			tmpp = Sp; Sp = Pp; Pp = tmpp;
		}
		cout<<sousa_cnt<<endl;
		cout<<(*Pp)[0];
		for(i=1;i<n;i++){
			cout<<" "<<(*Pp)[i];
		}
		cout<<endl;
	}
	return 0;
}

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

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

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

#define N 100000

int main(){
	while(1){	
		int n, count=0;
		int before[13], after[13], c[N];
	
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i)scanf(" %d", &before[i]);
				
		//roop
		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;	
				}
			}
		
			/*for(int i=0; i<n; ++i)
				printf(" %d", after[i]);
			printf("\n");
			*/
			
			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("%d", after[i]);
			if(i<n-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

using namespace std;

vector<int> func(vector<int> s){
  vector<int>t;
  for(int i=0;i<s.size();i++){
    int cnt=0;
    for(int j=0;j<s.size();j++){
      if(s[i]==s[j])cnt++;
    }
    t.push_back(cnt);
  }
  return t;
}

int main(void){
  vector<int>p;
  int n,x;
  
  while(cin >> n,n){
    p.clear();
    for(int i=0;i<n;i++){
      cin >> x;
      p.push_back(x);
    }
    
    int cnt=0;
    while(true){
      vector<int>res=func(p);
      if(res==p){
	cout << cnt << endl;
	for(int i=0;i<res.size();i++){
	  cout << res[i];
	  if(i==res.size()-1)cout << endl;
	  else cout <<" ";
	}
	break;
      }
      p=res;
      cnt++;
    }
  }
  return 0;
}

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

using namespace std;

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

int main(int argc, char **argv)
{
	int n, *a, *b, *c, s;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		a = (int *)calloc(n+1, sizeof(int));
		b = (int *)calloc(n+1, sizeof(int));
		c = (int *)calloc(13, sizeof(int));
		for(int i = 0; i < n; i++){
			cin >> a[i];
			c[a[i]]++;
		}
		for(int i = 0; i < n; i++){
			b[i] = a[i];
			a[i] = c[a[i]];
		}
		s = 0;
		while(func(a, b, n)){
			for(int i = 0; i < n; i++){
				b[i] = a[i];
				a[i] = c[a[i]];
			}
			for(int i = 0; i < n; i++){
				c[i] = 0;
			}
			for(int i = 0; i < n; i++){
				c[a[i]]++;
			}
			s++;
		}
		cout << s-1 << endl;
		for(int i = 0; i < n-1; i++){
			cout << a[i] << " ";
		}
		cout << a[n-1] << endl;
		
		free(c);
		free(b);
		free(a);
	}
	
	return 0;
}