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++: /*
	0108:Operation of Frequency of Appearance
*/
#include	<iostream>
#include	<cstring>

using namespace std;

int main(void) {
	int n, count, S[12], P[12];
	while(1) {
		count = 0;
		cin >> n;
		if(n == 0) { break; }
		for(int i = 0; i < n; i++) {
			cin >> S[i];
		}
		memset(P, 0, sizeof(P));
		while(1) {
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(S[i] == S[j]) { P[i]++; }
				}
			}
			if( memcmp( P, S, sizeof(S) ) == 0) { break; }

			memcpy(S, P, sizeof(P));
			memset(P, 0, sizeof(P));
			count++;
		}
		cout << count << endl;
		for(int i = 0; i < n; i++) {
			if(i == 0) {
				cout << S[i];
			} else {
				cout << ' ' << S[i];
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
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 n;
int ar1[20] = {};
int ar2[20] = {};


int func(int x){
	int val;
	int cnt = 0;;
	for(int i = 0; i < n; i++){
		if(ar1[i] == x){
			cnt++;
		}
	}
	val = cnt;
	return val;
}


int main(){
	while(cin >> n, n){
		for(int i = 0; i < n; i++){
			cin >> ar1[i]; 
		}
		int all_cnt = 0;
		while(1){
			all_cnt++;
			for(int i = 0; i < n; i++){
				ar2[i] = func(ar1[i]);		
			}

			bool flag = true;
			for(int i = 0; i < n; i++){
				if(ar1[i] != ar2[i]){
					flag = false;
				}
			}
			if(flag == true) {
				cout << all_cnt << endl;
				for(int i = 0; i < n; i++){
					cout << ar2[i] << " ";
				}
				cout << endl;
				break;
			}else{
				for(int i = 0; i < n; i++){
					ar1[i] = ar2[i];
				}
				continue;
			}
		}
	}
}

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

using namespace std;

int main(){
	int N;
	while(cin>>N,N){
		vector<int> num(N);
		for(int i=0;i<N;i++){
			int a;
			cin>>a;
			num[i]=a;
		}
		int cnt=0;
		while(1){
			map<int,int> mp;
			vector<int>::iterator it=num.begin();
			for(;it!=num.end();it++){
				mp[*it]++;
			}
			bool flag=false;
			for(int i=0;i<N;i++){
				if(num[i]!=mp[num[i]]){
					flag=true;
				}
			}
			if(!flag){
				break;
			}
			for(int i=0;i<N;i++){
				num[i]=mp[num[i]];
			}
			cnt++;
		}
		cout<<cnt<<endl;
		for(int i=0;i<N;i++){
			cout<<num[i];
			if(i!=N-1){
				cout<<' ';
			}
		}
		cout<<endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define EQ(a,b) (abs((a)-(b))<EPS)
int d[100];
int tmp[12];
int now[12];
int n;
void copy()
{
	for(int i=0;i<n;i++)
	{
		tmp[i]=now[i];
	}
	return ;
}
int cnt(int x)
{
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(tmp[i]==x)cnt++;
	}
	return cnt;
}
bool check()
{
	bool flag=true;
	for(int i=0;i<n;i++)
	{
		if(now[i]!=tmp[i])flag=false;
	}
	return flag;
}
int main()
{
	while(1)
	{
		int count=0;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			cin >> now[i];
		}
		while(1)
		{
			copy();
			for(int i=0;i<n;i++)
			{
				now[i]=cnt(tmp[i]);
			}
			if(check())
			{
				break;
			}
			count++;
		}
		cout << count << endl;
		for(int i=0;i<n;i++)
		{
			cout << tmp[i];
			if(i!=n-1)
			{
				cout << ' ';
			}
			else
			{
				cout << endl;
			}
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int n;
	int count = 0;
	int num[2][15];
	
	while (cin >> n, n){
		for (int i = 0; i < n; i++){
			cin >> num[0][i];
		}
		int ct, k = 0;
		while (1){
			for (int i = 0; i < n; i++){
				ct = 0;
				for (int j = 0; j < n; j++){
					if (num[k][i] == num[k][j]) ct++;
				}
				num[1 - k][i] = ct;
			}
			ct = 0;
			for (int i = 0; i < n; i++){
				if (num[0][i] == num[1][i]) ct++;
			}
			if (ct == n){
				break;
			}
			k = 1 - k;
			count++;
		}
		
		cout << count << endl << num[0][0];
		for (int i = 1; i < n; i++){
			cout << ' ' << num[0][i];
		}
		cout << endl;
	}
}

C++: #include <cstdio>

int n;
int s[15];
int s_new[15];
int count[105];





int main() {
  while(scanf("%d", &n), n) {
    // input
    for (int i=0; i<n; i++) {
      scanf("%d", &s[i]);
    }

    int loop_count = 0;

    // calc
    while (1) {
      loop_count++;
      
      for (int i=1; i<=100; i++) {
	count[i] = 0;
      }
      for (int i=0; i<n; i++) {
	count[s[i]]++;
    }
      for (int i=0; i<n; i++) {
	s_new[i] = count[s[i]];
      }
      int k;
      for (k=0; k<n; k++) {
	if (s[k] != s_new[k])
	  break;
      }


      // output
      if (k == n) {
	printf("%d\n", loop_count-1);
	printf("%d", s[0]);
	for (int j=1; j<n; j++) {
	  printf(" %d", s[j]);
	}
	printf("\n");
	break;
      }

      // copy
      for (int j=0; j<n; j++) {
	s[j] = s_new[j];
      }
    }
   
  }
}

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

int main()
{
	int n,c,i;
	int pre[12],now[12],cnt[12];
	while(cin >> n,n)
	{
		map<int,int> m;
		for(i=0; i<n; i++)
		{
			cin >> pre[i];
			m[pre[i]] = i;
		}
		for(i=0; i<n; i++)
			now[i] = m[pre[i]];	

		for(c=0; ; c++)
		{
			for(i=0; i<n; i++)
				cnt[i] = 0;

			for(i=0; i<n; i++)
				cnt[now[i]-1]++;		

			for(i=0; i<n; i++)
				now[i] = cnt[now[i]-1];

			for(i=0; i<n; i++)
				if(now[i]!=pre[i])
					break;

			if(i==n) break;

			for(i=0; i<n; i++)
				pre[i] = now[i];
		}

		cout << c << endl << now[0];
		for(i=1; i<n; i++)
			cout << " "<< now[i];
		cout << endl;


	}
	return 0;
}

C++: #include<iostream>
#include<vector>
using namespace std;
int main(){
	int n, cnt, i, j, inpt;
	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;
		}
		while(true){
			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<<(*Pp)[0];
		for(i=1;i<n;i++){
			cout<<" "<<(*Pp)[i];
		}
		cout<<endl;
	}
	return 0;
}