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)
		}
	}
}

Python: while 1:
 if'0'==input():break
 s=list(map(int,input().split()))
 c=0
 while 1:
  t=s;s=[t.count(e)for e in t]
  if t==s:break
  c+=1
 print(c);print(*s)

Python: while True:
	n = int(input())
	if n == 0:
	    break
	s = []
	u = 0
	v = 0
	s = list(input().split())
	while True:
		t = []
		for i in range(n):
			for j in range(n):
				if s[i] == s[j]:
					u += 1
			t.append(u)
			t_str = list(map(str, t))
			u = 0
		if s == t:
			print(str(v))
			print(" ".join(t_str))
			break
		else:
			s = t
			v += 1

Python: def getFreequencyStr(arr):
    datas = [0] * 101
    arr2 = [0] * len(arr)
    # 数を数える
    for i in range(0,len(arr)):
        datas[arr[i]] += 1
    # 頻出を配列にする
    for i in range(0,len(arr)):
        arr2[i] = datas[arr[i]]
    return arr2
        
while(1):
    n = int(input())
    changeNum = 0
    if n == 0:
        break
    arr = list(int(x) for x in input().split())
    while(1):
        arr2 = getFreequencyStr(arr)
        changeNum += 1
        if arr == arr2:
            break
        arr = arr2
    
    print(changeNum - 1)
    for i in range(0,len(arr)):
        if i :
            print(" ",end="")
        print(arr[i],end="")
    print()

Python: while 1:
 n=int(input())
 if n==0:break
 s=list(map(int,input().split()))
 c=0
 while 1:
  t=s;s=[t.count(e)for e in t]
  if t==s:break
  c+=1
 print(c);print(*s)

Python: #!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit
from itertools import count
from collections import Counter


def main(readline=stdin.readline):
    readline()
    ran = Counter()

    while 1:
        ary = [int(s) for s in readline().split()]
        if ary == [0]:
            exit()

        for case in count():
            ran.clear()
            for i in ary:
                ran[i] += 1
            if all(key == cnt for key, cnt in ran.items()):
                break
            ary = [ran[i] for i in ary]

        print(case)
        print(*ary)


if __name__ == '__main__':
    main()

Python: def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

while True:
    N = int(input())
    if N == 0:
        break
    p = [int(i) for i in input().split()]
    cnt = 0

    while True:
        flag = True
        s = [0 for i in range(101)]
        for i in range(N):
            s[p[i]] += 1
        for i in range(N):
            if p[i] != s[p[i]]:
                flag = False
                p[i] = s[p[i]]
        if flag:
            break
        cnt += 1
    print(cnt)
    for i in range(N-1):
        print(p[i], end = " ")
    print(p[N-1])

Python: def operation(N,point):
    N_another = []
    for i in N:
        count = 0
        for j in N:
            if i==j:
                count +=1
        N_another.append(count)
    if N==N_another:return N,point
    else:return operation(N_another,point+1)
while 1:
    num=int(input())
    if num==0:break
    N=list(map(int,input().split()))
    answer_1,answer_2=operation(N,0)
    print(answer_2)
    print(*answer_1)

Python: import sys
for a in sys.stdin:
 if'0'not in a:
  s=list(map(int,a.split()))
  c=0
  while 1:
   t=s;s=[t.count(e)for e in t]
   if t==s:break
   c+=1
  print(c);print(*s)

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int main(){

  int n,s[101],v[13],flag,count;
  
  scanf("%d",&n);
  
  while(n != 0){
    fill(s,s+101,0);
    
    count = 0;
    for(int i=0;i<n;i++){
      scanf("%d",&v[i]);
      s[v[i]]++;
    }
    
    while(1){
      flag = 0;
      for(int i=0;i<n;i++){
	if(v[i] != s[v[i]]){
	  v[i] = s[v[i]];
	  flag++;
	}
      }
      
      if(flag == 0) break;
      
      fill(s,s+101,0);
      for(int i=0;i<n;i++){
	s[v[i]]++;
      }
      
      count++;
    }
    printf("%d\n",count);
    for(int i=0;i<n;i++){
      if(i != n-1) printf("%d ",v[i]);
      else printf("%d\n",v[i]);
    }
    scanf("%d",&n);
  }
  
  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;
	string s;
	while(cin>>n){
		if(n==0) break;
		int ct=0;
		int s[13]={};
		rep(i,0,n){
			cin>>s[i];
		}
		int ans[13]={};
		for(ct=0;;ct++){
			memset(ans,0,sizeof(ans));
			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);
		rep(i,0,n){
			if(i==0) cout<<ans[i];
			else cout<<" "<<ans[i];
		}
		cout<<endl;
	}
}

C++: #include<stdio.h>
int main()
{
	int n,c,i,x,a[12];
	while(scanf("%d",&n),n)
	{
		for(c=i=0;i<n;++i)scanf("%d",&a[i]);
		for(;;)
		{
			int b[13]={0};
			for(i=0;i<n;++i)++b[a[i]];
			for(x=i=0;i<n;++i)if(a[i]!=b[a[i]])x=a[i]=b[a[i]];
			if(!x)break;
			++c;
		}
		printf("%d\n",c);
		for(i=0;i<n;++i)printf("%d%c",a[i],i+1-n?' ':'\n');
	}
	return 0;
}

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

int main(){
  int n;
  int s[12];
  int tmp[12];
  int ans;
  int flag;

  while(1){
    cin >> n;
    if(!n)break;

    ans = 0;
    for(int i=0;i<n;i++)cin >> s[i];

    while(1){

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

      flag = 1;
      for(int i=0;i<n;i++)if(s[i] != tmp[i])flag=0;
    
      if(flag)break;
      else {
	ans++;
	for(int i=0;i<n;i++)s[i] = tmp[i];
      }
    }

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

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

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

    int s[15]={};
    for(int i = 0; i < n; i++) cin >> s[i];
    
   
    int ans = 0;
    int c[15];
    while(1){
      bool issame = true;
      for(int i = 0; i < n; i++){
	int sum = 0;	
	for(int j = 0; j < n; j++){
	  if(s[i] == s[j] ) sum++;
	}
	if(s[i] != sum ) issame = false;
	c[i] = sum;
      }
      if(issame){
	cout << ans << endl;
      	for(int j = 0; j < n; j++){
	  if(j == n-1) cout << s[j] << "\n";
	  else cout << s[j] << " ";
	}
	break;
      }
      for(int j = 0; j < n; j++){
	s[j] = c[j];
      }
      ans++;
    }
  }
  
  return 0;
}