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 <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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n,c;
	int r=0;
	while(cin >> n && n){
		c = 0;
		vector<int> one(n);
		vector<int> two(n);
		for(int i=0;i<n;i++){
			cin >> one[i];
		}
		while(one != two){
			for(int k=0;k<one.size();k++){
				r=0;
				for(int i=0;i<one.size();i++)
					if(one[k]==one[i])r++;
				two[k]=r;
			}
			c++;
			swap(one,two);
		}
		cout << c-1 << endl;
		for(int i=0;i<n;i++){
			if(i)cout << " ";
			cout << one[i];
		}
		cout << endl;
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n,t,a[12],b[12],s[12];

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

C++: #include<stdio.h>
#include<math.h>
#include<string.h>

void sha(char *a, char *b, int k){
  int i;
  char w[101];
  for(i=0;i<101;i++)
    w[i]=0;
  for(i=0;i<k;i++){
    w[a[i]]++;
  }
  for(i=0;i<k;i++){
    b[i]=w[a[i]];
  }
}

int main(){
  int n;
  while(1){
    char s[12];
    char p[12];
    char q[12];
    scanf("%d", &n);
    char c;scanf("%c", &c);
    if(n!=0){
      int i;
      for(i=0;i<n;i++){
	scanf("%d", &s[i]);
      }
      char v;scanf("%c", &v);
    }
    else
      {break;}

    strcpy(p, s);
    int h=0;
    while(1){
      sha(p, q, n);
      if(strcmp(p, q)==0){
	  printf("%d\n",h);
	  int d;
	  for(d=0;d<n;d++)
	    printf("%d ", p[d]);
	  printf("\n");
	  break;}
      strcpy(p, q);
      h++;
    }
  }
  
  //printf("%d\n",an);
  //int i;
  //for(i=0;i<n;i++){
  //  printf("%d ", ans[i]);
  //}
  //printf("\n");
  
  /*int t;
  for(t=0;t<n-1;t++){
    printf("%d ", p[t]);
  }
  printf("%d\n", p[n-1]);*/

  
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;


void printv(int v[], int len) {
	int ifs = 1;
	for (int i = 0; i < len; i++) {
		if (ifs == 0)
			cout << " ";
		cout << v[i];
		ifs = 0;
	}
	cout << endl;
}

int main() {
	int n;
	while (cin >> n, n) {
		int *s = new int[n];
		for (int i = 0; i < n; i++)
			cin >> s[i];
		int *c = new int[n];
		int *p = new int[n];
		int cnt = 0;
		int vlen = sizeof(int) * n;
		memcpy(c, s, vlen);
		while (1) {
			memset(p, 0, vlen);
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					if (c[i] == c[j])
						p[i]++;
			if (memcmp(c, p, vlen) == 0)
				break;
			memcpy(c, p, vlen);
			cnt++;
		}
		cout << cnt << endl;
		printv(p, n);

		delete[] s;
		delete[] c;
		delete[] p;
	}
	return 0;
}

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

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int n;

void solve() {
  int b[20], a[20], res = 0;
  rep(i,n) cin>>b[i];
  while (true) {
    rep(j,n) {
      int cnt = 0;
      rep (k,n) if (b[j] == b[k]) cnt++;
      a[j] = cnt;
    }
    
    bool flag = false;
    rep(j,n) if (b[j] != a[j]) flag = true;
    if (!flag) break;
    
    rep(j,n) b[j] = a[j];
    res++;
  }
  cout<<res<<endl<<a[0];
  REP(i,1,n) cout<<" "<<a[i];
  cout<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int a[12];
int b[12];
int main()
{
  int n,i,j,c,d,f;
  for(;;){
    cin >> n;
    if(n==0) break;
    for(i=0;i<n;i++){
      cin >> a[i];
    }
    c = 0;
    for(;;){
      f = 1;
      for(i=0;i<n;i++){
	d = 0;
	for(j=0;j<n;j++){
	  if(a[j] == a[i]) d++;
	}
	b[i] = d;
	if(a[i] != b[i]) f = 0;
      }
      if(f) break;
      memcpy(a,b,sizeof(int)*n);
      c++;
    }
    cout << c << endl << a[0];
    for(i=1;i<n;i++){
      cout << " " << a[i];
    }
    cout << endl;
  }
  return 0;
}

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

#define N 100000

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]);
				
		//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;	
				}
			}
					
			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<vector>
#include<map>
using namespace std;
typedef long long ll;

int main(){
  int n;
  while(cin >> n,n){
    vector<ll> cur(n);
    for(int i=0;i<n;i++)cin >> cur[i];

    int ans = 0;
    for(;;){
      map<ll,ll> freq;
      
      for(int i=0;i<n;i++)freq[cur[i]]++;

      vector<ll> nxt(n);
      for(int i=0;i<n;i++)nxt[i] = freq[cur[i]];

      bool f = true;
      for(int i=0;i<n;i++){
	if(nxt[i] != cur[i])f = false;
      }
      if(f)break;
      ans++;
      cur = nxt;
    }

    cout << ans << endl;
    for(int i=0;i<n;i++)cout << cur[i] << " \n"[i==n-1];
  }
}