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>

using namespace std;

int main(){
	int in;

	while(cin >> in){
		int rev = 0, max = 0;

		if(in == 0) break;

		int data[in];

		for(int i = 0; i < in; i++){
			cin >> data[i];
			if(data[i] > max) max = data[i];
		}

		while(1){

			int sum[max+1];

			for(int	i = 0; i <= max; i++){
				sum[i] = 0;
			}
		
			for(int i = 0; i < in; i++){
				sum[data[i]]++;
			}
			for(int i = 0; i < in; i++){
				data[i] = sum[data[i]];
			}
			int status = 0;

			for(int i = 0; i < in; i++){
				if(data[i] != sum[data[i]]) status = 1;
			}

			if(status == 0){
				cout << rev << endl;
				for(int i = 0; i < in; i++){
					if(i != 0) cout << " ";
					cout << data[i];
				}
				cout << endl;
				break;
			}
			rev++;
			max = in;
		}
	}

	return 0;
}

C++: #include <stdio.h>

int main(){
	int n,in[12],out[12],i,j,t,r,flag;
	
	while(~scanf("%d",&n)){
		if(n==0)break;

		t=0;
		
		for(i=0;i<n;i++){
			scanf("%d",&in[i]);
		}
		flag=1;
		while(flag){
			for(i=0;i<n;i++)out[i]=0;
			for(i=0;i<n;i++){
				for(j=0;j<n;j++){
					if(in[i]==in[j])++out[i];
				}
			}
			
			++t;
			flag=0;
			for(i=0;i<n;i++){
				if(in[i]!=out[i])flag=1;
			}
			
			for(i=0;i<n;i++){
				in[i]=out[i];
			}
		}
		printf("%d\n",t-1);
		for(i=0;i<n-1;i++){
			printf("%d ",in[i]);
		}
		printf("%d\n",in[n-1]);
	}
	return 0;
}

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");
			*/
			
			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 <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while(cin >> n,n) {
    vector<int> v(n);
    REP(i,n)
      cin >> v[i];
    int ans = 0;
    while(true) {
      vector<int> nextv(n);
      REP(i,n) {
        nextv[i] = count(ALL(v),v[i]);
      }
      if (v == nextv) break;
      ans++;
      v = nextv;
    }
    cout << ans << endl;
    REP(i,n) {
      if (i) cout << " ";
      cout << v[i];
    }
    cout << endl;
  }
  
}

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

using namespace std;

int main(void) {
	while(1) {
		int c = 0, n, S1[13], S2[13];
		
		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 <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

int main() {

more:

  int n; cin >> n;
  if (!n) return 0;

  map<int,int> s;
  vector<int> xs(n);
  vector<int> ys(n);
  rep (i, n) cin >> xs[i];

  for (int k = 0; ; ++k) {
    s.clear();
    for (int x : xs) {
      s[x]++;
    }

    bool ac = true;
    rep (i, n) {
      int x = s[xs[i]];
      if (xs[i] != x) {
        xs[i] = x;
        ac = false;
      }
    }
    if (ac) {
      cout << k << endl;
      cout << xs << endl;
      break;
    }
  }

  goto more;
}

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 <cstdio>

int main(void)
{
	int n;
	int i, j;
	int count, ct, k = 0;
	int num[2][15];
	
	while (scanf("%d", &n), n){
		count = 0;
		for (i = 0; i < n; i++){
			scanf("%d", &num[0][i]);
		}
		k = 0;
		while (1){
			for (i = 0; i < n; i++){
				ct = 0;
				for (j = 0; j < n; j++){
					if (num[k][i] == num[k][j]) ct++;
				}
				num[1 - k][i] = ct;
			}
			ct = 0;
			for (i = 0; i < n; i++){
				if (num[0][i] == num[1][i]) ct++;
			}
			if (ct == n){
				break;
			}
			k = 1 - k;
			count++;
		}
		
		printf("%d\n%d", count, num[0][0]);
		for (i = 1; i < n; i++){
			printf(" %d", num[0][i]);
		}
		printf("\n");
	}
	return (0);
}