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<cmath>
#include<vector>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
  int n;
  while(cin>>n,n){
    vector<int>in1(n);
    vector<int>in2(n);
    int count=0;
    rep(i,n)cin>>in1[i];
    while(1){
      count++;
      bool h=true;
      rep(i,in1.size()){
	int co=0;
	rep(j,in1.size()){
	  if(in1[j]==in1[i])co++;
	}
	in2[i]=co;
	//cout<<co<<endl;
	if(in1[i]!=co)h=false;
      }
      if(h)break;
      //
      count++;
      h=true;
      rep(i,in2.size()){
	int co=0;
	rep(j,in2.size()){
	  if(in2[j]==in2[i])co++;
	}
	in1[i]=co;
	if(in2[i]!=co)h=false;
      }
      if(h)break;
    }
    cout<<count-1<<endl;
    cout<<in1[0];
    rep(i,in1.size()-1)cout<<" "<<in1[i+1];
    cout<<endl;
  }
}


  /*
  while(cin>>n,n){
    int co=0;
    vector< vector<int> >in(n);
    rep(i,n)cin>>in[0][i];
    do{
      vector<int>n;
      vector<int>num;
      rep(i,in[co].size()){
	bool han=false;
	int a;
	rep(j,n.size())if(num[j]==in[co][i]){a=j;han=true;}
	if(han){
	  n[a]++;
	}else{
	  n.push_back(in[co][a]);
	  num.push_back(1);
	}
      }
      rep(i,in[co].size()){
	rep(i,num.size())if(in[co][i]==num[
	in[co+1][i]=


      bool han1=false;
      
    }while();*/

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

using namespace std;

int main() {
	map< int, int> l;
	int n, a[12], c;
	bool f;
	while(1) {
		cin >> n;
		if(!n) break;
		c = 0;
		for( int i=0; i<n; i++) cin >> a[i];
		while(1) {
			l.clear(); f = false;
			for( int i=0; i<n; i++) {
				if(l.count(a[i])==0) l[a[i]] = 1;
				else l[a[i]]++;
			}
			for( int i=0; i<n; i++) {
				if(a[i]!=l[a[i]]) { 
					a[i] = l[a[i]];
					f = true;
				}
			}
			if(!f) break;
			c++;
		}
		cout << c << endl;
		for( int i=0; i<n; i++) cout << a[i] << ( i==n-1 ? "" : " " );
		cout << endl;
	}
	return 0;
}

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

int n;
int a[12], prv[12];
std::map<int, int> cnt, tmp;
int ans;

int main()
{
	while( std::cin >> n, n )
	{
		ans = 0;
		memset( a, 0, sizeof( a ) );
		memset( prv, 0, sizeof( prv ) );
		cnt.clear();
		tmp.clear();

		for( int i = 0; i != n; ++i )
		{
			std::cin >> a[i];
			++cnt[a[i]];
		}

		while( true )
		{
			std::copy( a, a + 12, prv );

			for( int i = 0; i != n; ++i )
			{
				a[i] = cnt[a[i]];
				++tmp[a[i]];
			}

			if( std::equal( a, a + 12, prv ) )
				break;

			++ans;

			cnt = tmp;
			tmp.clear();
		}

		std::cout << ans << std::endl;
		for( int i = 0; i != n; ++i )
			std::cout << a[i] << ( i == n - 1 ? '\n' : ' ' );
	}

	return 0;
}

C++: #include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define MAX_ELEMENT 12
#define MAX_LINE 200

void calculate(vector<vector<int>>& calcVec) {
	map<int, int> calcMap, checkMap;
	int cnt, i, j;
	bool check;
	printf("Output:\n");
	for (i = 0; i < calcVec.size(); i++) {
		for (j = 0; j < calcVec[i].size(); j++) {
			calcMap[calcVec[i][j]]++;
		}
		cnt = 1;
		while (cnt) {
			check = true;
			for (j = 0; j < calcVec[i].size(); j++) {
				calcVec[i][j] = calcMap[calcVec[i][j]];
				checkMap[calcVec[i][j]]++;
			}
			for (j = 0; j < calcVec[i].size(); j++) {
				check &= (calcVec[i][j] == checkMap[calcVec[i][j]]);
			}
			if (check)break;
			calcMap = checkMap;
			checkMap.clear();
			cnt++;
		}
		printf("%d\n",cnt);
		for (j = 0; j < calcVec[i].size(); j++) {
			printf("%d ", calcVec[i][j]);
		}
		printf("\n");
		calcMap.clear();
		checkMap.clear();
	}
}

void getInputValue(vector<vector<int>>& calcVec) {
	string num, buf1, buf2;
	vector<int> vec;
	printf("Input:\n");
	for (int i = 0; i < MAX_LINE; i++) {
		getline(cin, num);

		int ele_length = atoi(num.c_str());
		if (!ele_length) { break; }

		vec.reserve(ele_length);
		getline(cin, buf1);
		stringstream ss(buf1);
		while (getline(ss, buf2, ' ')) {
			int value = atoi(buf2.c_str());
			if (!value) { break; }
			if (ele_length == vec.size()) { break; }
			vec.emplace_back(value);
		}
		calcVec.push_back(vec);
		vec.clear();
	}
}


int main() {
	vector<vector<int>> calcVec;
	getInputValue(calcVec);
	calculate(calcVec);
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    /*
    cin.tie(0);
    ios::sync_with_stdio(false);
    //*/
    int n; cin >> n;
    while (n != 0) {
        int flag = 1;
        int p[n];
        rep(i, n) {
            cin >> p[i];
        }
        int count = 0;
        int q[101] = {0};
        fill(q, q+101, 0);
        while (flag == 1){
            flag = 0;
            fill(q, q+101, 0);
            rep(i, n) q[p[i]]++;
            //rep(i, n) cout << q[p[i]] << " ";
            for (int i = 0; i < n-1; i++) {
                if (p[i] != q[p[i]]) flag = 1;
            }
            rep(i ,n) p[i] = q[p[i]];
            count++;
        }
        rep(i, n-1) cout << q[p[i]] << " ";
        cout << q[p[n-1]] << endl;
        cout << count-1 << endl;
        cin >> n;
    }

    return 0;
}

C++: /*
	0108:Operation of Frequency of Appearance
*/
#include	<iostream>
#include	<cstring>

using namespace std;

int main(void) {
	while(1) {
		int c = 0, n, S1[12], S2[12];
		
		cin >> n;
		if(n == 0) { break; }
		for(int i = 0; i < n; i++) {
			cin >> S1[i];
		}
		memset(S2, 0, sizeof(S2));
		while(1) {
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(S1[i] == S1[j]) {
						S2[i]++;
					}
				}
			}
			if(memcmp(S1, S2, sizeof(S1)) == 0) { break; }
			memcpy(S1, S2, sizeof(S2));
			memset(S2,  0, sizeof(S2));
			c++;
		}
		cout << c << endl;
		for(int i = 0; i < n; i++) {
			if(i == 0) {
				cout << S1[i];
			} else {
				cout << ' ' << S1[i];
			}
		}
		cout << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<bitset>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int s[1000];
        for(int i=0;i<n;i++)cin>>s[i];
        bool endFlag=false;
        while(!endFlag){
            endFlag=true;
            int cnt[1000]={0};
            for(int i=0;i<n;i++)cnt[s[i]]++;
            for(int i=0;i<n;i++){
                if(s[i]!=cnt[s[i]]){
                    s[i]=cnt[s[i]];
                    endFlag=false;
                }
            }
        }
        for(int i=0;i<n;i++){
            if(i!=0)cout<<" ";
            cout<<s[i];
        }
        cout<<endl;
    }
}

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

using namespace std;

#define loop(i,a,b) for(int i=(a); i<(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin>>n,n){
        int a[12];
        rep(i,n) cin>>a[i];
        int c=0;
        while(1){
            map<int,int> m;
            rep(i,n) m[a[i]]++;
            bool update=false;
            rep(i,n){
                if(a[i]!=m[a[i]]){
                    a[i]=m[a[i]];
                    update=true;
                }
            }
            if(!update) break;
            else c++;
        }
        cout<<c<<endl;
        rep(i,n) cout<<a[i]<<(i==n-1 ? '\n' : ' ');
    }
}