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 <stdio.h>

void getFA(int *src, int *dst, int n){
  for (int i=0; i<n; i++){
    int cnt=0;
    for (int j=0; j<n; j++){
      if (src[i]==src[j]) cnt++;
    }
    dst[i] = cnt;
  }
}

#define N 12

int main(void){
  int n;
  int cnt;
  int a[N],b[N];
  bool modified;

  while (scanf("%d",&n), n){
    for (int i=0; i<n; i++){
      scanf("%d",&a[i]);
    }
    cnt = 0;
    while (true){
      modified = false;
      getFA(a,b,n);
      for (int i=0; i<n; i++){
	if (a[i]!=b[i]) modified = true;
	a[i] = b[i];
      }
      if (modified){
	cnt++;
      } else {
	break;
      }
    }
    printf("%d\n", cnt);
    for (int i=0; i<n-1; i++){
      printf("%d ",b[i]);
    }
    printf("%d\n", b[n-1]);
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n;
	while(cin>>n){
		if(n==0) break;
		lint ct=0;
		int s[13]={};
		rep(i,0,n){
			cin>>s[i];
		}
		int ans[13]={};
		for(ct=0;;ct++){
			rep(i,0,13){
				ans[i]=0;
			}
			int d[13]={};
			rep(i,0,n){
				d[s[i]]++;
			}
			rep(i,0,n){
				ans[i]=d[s[i]];
			}
			int c=0;
			rep(i,0,n){
				if(ans[i]==s[i]) c++;
			}
			if(c==n) break;
			rep(i,0,n){
				s[i]=ans[i];
			}
		}
		o((ct==0?1:ct));
		rep(i,0,n){
			if(i==0) cout<<ans[i];
			else cout<<" "<<ans[i];
		}
		cout<<endl;
	}
}

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

bool isEqualArray(int n, int* s1, int* s2) {
    for (int i = 0; i < n; i++) {
        if (s1[i] != s2[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int* s1 = new int [n];
        for (int i = 0; i < n; i++) {
            cin >> s1[i];
        }
        int count = 0;
        int* s2 = new int [n];
        while (!isEqualArray(n, s1, s2)) {
            for (int i = 0; i < n; i++) {
                s2[i] = s1[i];
            }
            for (int i = 0; i < n; i++) {
                int exist = 0;
                for (int j = 0; j < n; j++) {
                    if (s2[i] == s2[j]) {
                        exist++;
                    }
                }
                s1[i] = exist++;
            }
            count++;
        }
        cout << count - 1 << endl;
        for (int i = 0; i < n; i++) {
            cout << s1[i] << " ";
        }
        cout << endl;
        delete[] s1;
        delete[] s2;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        int ans[10000]={},kawa[10000];
        for(int i=0;i<n;i++)cin>>kawa[i];
        for(int i=0;;i++){
            int num[10001]={};
            for(int j=0;j<n;j++)num[kawa[j]]++;
            bool rever=1;
            for(int j=0;j<n;j++){
                kawa[j]=num[kawa[j]];
                if(kawa[j]!=ans[j])rever=0;
            }
            if(rever){
                cout<<i<<endl<<kawa[0];
                for(int j=1;j<n;j++)cout<<" "<<kawa[j];
                cout<<endl;
                break;
            }
            else for(int j=0;j<n;j++)ans[j]=kawa[j];
        }
    }
}

C++: #include <iostream>
using namespace std;
int main(){
    while(true){
        int n,b=0,a[10][12]={0},count=0,sum1=0,sum2=0;
            cin>>n;
        if(n==0)break;
            for(int i=0;i<n;i++){
                cin>>a[1][i];
            }
            while(true){
                b=b+1;
            for(int i=0;i<n;i++){
                count=0;
                for(int j=0;j<n;j++){
                    if(a[b][i]==a[b][j])count=count+1;
                }
                a[b+1][i]=count;
                sum1=sum1+count;
            }
                if(sum1==sum2)break;
                sum2=sum1;
                sum1=0;
        }
        cout<<b-1<<endl;
        for(int i=0;i<n;i++){
            cout<<a[b][i]<<" ";
        }
        cout<<endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n;
  while(cin>>n){
    if(n==0) break;
    vector<int> ary;
    int tmp;
    REP(i,n){
      cin>>tmp;
      ary.push_back(tmp);
    }
    int countt = 0;
    while(true){
      vector<int> ary2;
      REP(i,n){
        ary2.push_back(count(ary.begin(),ary.end(),ary[i]));
      }
      if(ary==ary2){
        cout<<countt<<endl;
        bool f = false;
        REP(i,n){
          if(f) cout<<" ";
          f = true;
          cout<<ary[i];
        }
        cout<<endl;
        break;
      }
      ary = ary2;
      countt++;
    }
  }
  return 0;
}

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

int main()
{
	int n;
	int seq[16];
	int tmp[16];
	while(cin>>n,n){
		for(int i=0; i<n; i++)
			cin>>seq[i];
			
		int ans = 0;
		int k;
		do{
			map<int,int> mii;
			for(int i=0; i<n; i++)
				tmp[i] = seq[i];
			for(int i=0; i<n; i++)
				mii[seq[i]]++;
				
			for(int i=0; i<n; i++)
				seq[i] = mii[seq[i]];
			
			ans++;
			for(k=0; k<n && seq[k]==tmp[k]; k++)
				;
		}while( k!=n );
		
		printf("%d\n",ans-1);
		for(int i=0; i<n; i++){
			if( i==0 )
				printf("%d",seq[i]);
			else
				printf(" %d",seq[i]);
		}
		puts("");
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool isChanged(int *S, int *prevS, int n);

int main() {
    int n;
    int S[12], freq[101], prevS[12];

    while (cin >> n) {
        if(n == 0) break;

        for (int i=0; i<n; i++) {
            cin >> S[i];
        }

        int cont = -1;
        for (int i=0; i<12; i++) prevS[i] = -1;

        while (isChanged(S, prevS, n)) {
            for (int i=0; i<101; i++) freq[i] = 0;

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

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

            cont++;
        }

        cout << cont << endl;
        for (int i=0; i<n-1; i++) {
            cout << S[i] << " ";
        }
        cout << S[n-1] << endl;
    }

    return 0;
}

bool isChanged(int *S, int *prevS, int n) {
    for (int i=0; i<n; i++) {
        if(S[i] != prevS[i]) return true;
    }

    return false;
}