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 <cstdio>
#include <utility>
#include <vector>
#include <unordered_map>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

int main() {
	for (int n; (n = in());) {
		int c = 0;
		vector<int> s(n), p(n);
		for (int &x: s)
			x = in();

		for (; s != p; c++) {
			p = s;
			unordered_map<int, int> m;
			for (int x: s)
				m[x]++;
			for (int i = 0; i < n; i++)
				s[i] = m[p[i]];
		}
		outl(c - 1);
		out(s);
	}
}

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

int main() {
  int n;
  while(cin >> n) {
    int s[12] = {0},c[12] = {0},c2[12] = {0},k,check=1;
    if(n==0)break;

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

    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
        if(c[i] == c[j]) {
          c2[i]++;
        }
      }
    }

    //ok
    k=0;//k=1;
    while(check){
      check = 0;

      int c2[10000] = {0};
      for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
          if(c[i] == c[j]) {
            c2[i]++;
          }
        }
      }
      for(int i=0;i<n;i++) {
        if(c2[i] != c[i]) {
          for(int j=0;j<n;j++) {
            c[j] = c2[j];
          }
          check = 1;
          k++;
        }
      }

    }
    cout << k << endl;
    for(int i=0;i<n;i++) {
      cout << c[i] << " ";
    }
    cout << "\b" << endl;
  }
}

C++: #include <bits/stdc++.h>
#define MAX_N 15
using namespace std;

int data[MAX_N];
int n;

void print() {
    for(int r = 0; r < n; r++) {
        printf("%d ", data[r]);
    }
    putchar('\n');
}

bool judge() {
    for(int r = 0; r < n; r++) {
        if(count(data, data+n, data[r]) != data[r]) return(false);
    }
    return(true);
}

void convert() {
    int tmp[n];
    for(int r = 0; r < n; r++) {
        tmp[r] = (int)count(data,data+n,data[r]);
    }
    memcpy(data, tmp, sizeof(tmp));
}

int solve() {
    int res = 0;
    do {
        convert();
        res++;
    }while(!judge());
    return(res);
}

int main(void) {
    while(cin >> n, n != 0) {
        for(int r = 0; r < n; r++) {
            cin >> data[r];
        }
        printf("%d\n", solve());
        print();
    }
    return(0);
}

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

int countArrayElm(int *ary,int n,int key){
	int cnt=0;
	for(int i=0;i<n;++i){
		if(ary[i] == key)cnt++;
	}
	return cnt;
}



int main() {
	
	
	int n;
	int *s,*c;
	int count;
	
	
	while(cin>>n,n){
		s = new int[n];
		c = new int[n];
		count = 0;
		
		for(int i=0;i<10;++i){
			cin >> s[i];
			c[i] = 0;
		}
		
		while( 1 ){
			for(int i=0;i<n;++i){
				c[i] = countArrayElm(s,n,s[i]);
			}
			
			if([s,c,n](){ for(int i=0;i<n;++i){if(s[i]!=c[i])return 0;}return 1;}())break;
			
			for(int i=0;i<n;++i){
				s[i] = c[i];
			}
			
			count++;
		}
		
		cout << count << endl;
		for(int i=0;i<n;++i){
			
			cout << (i?" ":"") << c[i];
		}
		cout << endl;
	}
	return 0;
}

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

int main(){

  int n, s[12], num[12][2], valid, len, cnt;
  
  while(cin >> n){
    if(n == 0) break;
    for(int i=0; i<n; i++){
      cin >> s[i];
    }  
    
    cnt = 0;

    do{
      valid = 0;
      num[0][0] = 0;
      len = 1;
      num[0][0] = s[0];
      num[0][1] = 1;
      
      for(int i=1; i<n; i++){
        for(int j=0; j<len; j++){
          if(num[j][0] == s[i]){
            num[j][1]++;
            break;
          }
          else if(j == len - 1){
            num[len][0] = s[i];
            num[len][1] = 1;
            len++;
            break;
          }
        }
      }    

      for(int i=0; i<n; i++){
        for(int j=0; j<len; j++){
          if(num[j][0] == s[i] && num[j][1] != s[i]){
            s[i] = num[j][1];
            valid = 1;
            break;
          }
        }
      }

      if(valid == 1) cnt++;
    }while(valid == 1);
    
    cout << cnt << endl;
    for(int i=0; i<n; i++){
      cout << s[i];
      if(i != n-1) cout << " ";
      else cout << endl;
    }
  }

  return 0;

}

C++: 
#include <cstdio>
#include <cstring>

const int MAXN = 105;
char map[MAXN][MAXN];
int n, m;
int d[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

int dfs(int px, int py, char c)
{
    map[px][py] = ' ';
    for(int i = 0; i < 4; i++)
    {
        int x = px + d[i][0];
        int y = py + d[i][1];
        if(x >= 0 && x < n && y >=0 && y < m
           && c == map[x][y])
           dfs(x, y, c);
    }
}

int main()
{
    while(~scanf("%d%d", &n, &m))
    {
        if(0 == n && 0 == m) break;
        getchar();
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                scanf("%c", &map[i][j]);
            }
            getchar();
        }
        int ans = 0;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(' ' != map[i][j])
                {
                    dfs(i, j, map[i][j]);
                    ans++;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<int> S;
		vector<int> S_old;
		for(int i=0;i<n;i++){
			int s;
			scanf("%d",&s);
			S.push_back(s);
		}

		int c=0;
		while(1){
			map<int,int> freq;
			S_old = S;
			for(int i=0;i<S.size();i++){
				freq[S[i]]++;
			}

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

			if(S == S_old) break;
			c++;
		}

		cout << c << endl;
		for(int i=0;i<S.size();i++){
			printf("%d%s",S[i],i==S.size()-1 ? "\n" : " ");
		}

	}
}