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 True:
    n = int(input())
    if n == 0:
        break
    a = [int(x) for x in input().split()]
    cnt = 0
    while True:
        b = {}
        for i in a:
            if i in b:
                b[i] += 1
            else:
                b[i] = 1
        c = 0
        for k, v in b.items():
            if k == v:
                c += 1
        if len(b) == c:
            break
        else:
            for i in range(n):
                a[i] = b[a[i]]
            cnt += 1
    print(cnt)
    print(*a)

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: from collections import Counter

while True:
  n = int(input())
  if not n:
    break
  
  slst = list(map(int, input().split()))
  temp = [i for i in slst]
  ans = 0

  while True:
    ans += 1
    counter = Counter()
    
    for i in slst:
      counter[i] += 1
    slst = [counter[i] for i in temp]
    
    if temp == slst:
      ans -= 1
      break

    temp = [i for i in slst]
  print(ans)
  print(*slst)

Python: import sys
a=sys.stdin
while 1:
 if'0\n'==a.readline():break
 s=list(map(int,a.readline().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())  ## n = len(S)
    if (n==0):
        break
    S = list(map(int, input().split()))
    C = []
    for s in S:
        num = S.count(s)
        C.append(num)
    c = 0
    #print(c,C)
    if (C == S):
        print(c)
        print(*C)
    else:
        while True:
            copy = C[:]
            for i in range(n):
                ci = C[i]
                num = copy.count(ci)
                C[i] = num
            c += 1
            #print(c,C)
            if (C == copy):
                print(c)
                print(*C)
                break

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0108
AC
"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        # S = [4, 5, 1, 1, 4, 5, 12, 3, 5, 4]
        n = int(input())
        if n == 0:
            break
        S = [int(x) for x in input().split(' ')]

        A = []                  #  After[]
        B = S[:]                #  Before[]
        count = 0
        while True:
            # for s in B:
            #    A.append(B.count(s))
            A = [B.count(b) for b in B]
            if A == B:
                break
            B = A[:]
            A = []
            count += 1

        print(count)
        print(*A)


if __name__ == '__main__':
    main(sys.argv[1:])

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 transport(L,before_L=[],cnt=0):
    cnt += 1
    if L==before_L:
        print(cnt-2)
        return cnt
    L_before = L[:]
    dic = {}
    for i in L:
        dic[i] = 0
    for i in L:
        dic[i] += 1
    # 上の2つのfor文でカウントは出来たので、keyの数字の値をvalueに置き換える
    for i in range(len(L)):
        L[i] = dic[L[i]]
    transport(L,L_before,cnt)

    return L

while 1:
    n = int(input())
    if n==0:
        break
    S = list(map(int,input().split()))
    P = transport(S)
    for i in range(len(P)-1):
        print(P[i],end=" ")
    print(P[-1])

Python: def f(l,c):
  m = [l.count(i) for i in l]
  if l == m:
    print(c)
    m = [str(i) for i in m]
    print(' '.join(m))
    return
  else:
    c += 1
    f(m,c)
  
while True:
  n = int(input())
  if n == 0:
    break
  l = [i for i in input().split()]
  f(l,0)

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 FOA(a, count):
	b = a
	for i in range(len(b)):
		b[i] = a.count(a[i])
	if  b == a:
		print(count)
		print(" ".join(map(str, b)))
		break
	else:
		return FOA(b, count + 1)

while True:
	n = int(input())
	if n == 0:
		break
	a = map(int, input().split())
	FOA(a, 0)

Python: # Aizu Problem 0108: Operation of Frequency of Appearance

#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def operation_of_frequency_of_appearance(S):
    S_old = S[:]
    steps = 0
    while True:
        unique = list(set(S))
        counts = {u: S.count(u) for u in unique}
        S = [counts[s] for s in S]
        if S == S_old:
            return steps, S
        S_old = S[:]
        steps += 1

    
while True:
    N = int(input())
    if N == 0:
        break
    steps, S = operation_of_frequency_of_appearance([int(_) for _ in input().split()])
    print(steps)
    print(' '.join([str(s) for s in S]))

Python: import sys
for a in sys.stdin:
 if' 'in a:
  s=list(map(int,a.strip().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: import sys
for a in sys.stdin:
 if' '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)

Python: import sys
for a in sys.stdin:
 if' '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)

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


SIZE = 101
table = [None]*(SIZE)


while True:
    N = int(input())
    if N == 0:
        break

    TMP = list(map(int,input().split()))

    ans = -1
    count = 0

    while True:

        for i in range(SIZE):
            table[i] = 0

        for i in range(len(TMP)):
            table[TMP[i]] += 1

        WORK = []

        for i in range(len(TMP)):
            WORK.append(table[TMP[i]])

        FLG = True
        for i in range(len(TMP)):
            if TMP[i] != WORK[i]:
                FLG = False
                break

        if FLG == True:
            ans = count
            break

        for i in range(len(WORK)):
            TMP[i] = WORK[i]

        count += 1

    print("%d"%(ans))
    print(' '.join(map(str,TMP)))

Python: import copy

if __name__ == '__main__':

	while True:
		n = int(input())
		if n == 0:
			break

		line = list(map(int,input().split()))
		num = len(line)

		ans = copy.deepcopy(line)
		tmp = [0]*num
		cnt = 0

		for i,j in enumerate(ans):
			tmp[i] = line.count(j)

		while True:
			if ans == tmp:
				print(cnt)
				print(*ans)
				break
			else:
				ans = copy.deepcopy(tmp)
				for i,j in enumerate(ans):
					tmp[i] = ans.count(j)

				cnt += 1