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

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

Python: import sys
while 1:
	n=int(input())
	if n==0:
		break
	s=list(int(input().split()))
	cont=0
	while 1:
		tmp=[]
		for i in range(n):
			tmp[i]=[s.count(s[i])]
		if s==temp:
			print(cont)
			break
		else:
			cont+=1
	for i in range(n):
		if i != n-1:
			sys.stdout('{0} '.format(s[i]))
		else:
			print(s[i])

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0108

"""
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))
            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
    a = list(map(int, input().split()))
    b = []
    cnt = 0
    while True:
        for m in a:
            b.append(a.count(m))
        if a == b:
            break
        cnt += 1
        a = b
        b = []
    print(cnt)
    print(' '.join(map(str,b)))

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
            tmp = ary[:]
            ary = [ran[i] for i in ary]
            if tmp == ary:
                break

        print(case)
        print(*ary)


if __name__ == '__main__':
    main()

Python: import copy

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

    datas = list(map(int, input().split()))
    prev = copy.deepcopy(datas)
    curr = [0] * n
    cnt = 0

    while 1:
        for i, p in enumerate(prev):
            curr[i] = prev.count(p)

        if prev == curr:
            break
        prev = copy.deepcopy(curr)
        cnt += 1

    print(cnt)
    print(' '.join(str(p) for p in prev))

Python: while True:
    n = int(input())
    if n == 0:
        break
    S = list(map(int, input().split()))
    pre, cur = [S.count(s) for s in S], []
    cnt = 1
    while True:
        cur = [pre.count(p) for p in pre]
        if cur == pre:
            break
        pre = [c for c in cur]
        cnt += 1
    print(cnt)
    print(' '.join(map(str, cur)))

Python: while 1:
 if'0'==input():break
 s=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: # coding=utf-8

###
### for python program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    def pnum_check(self, n):
        if (n==1):
            return False
        elif (n==2):
            return True
        else:
            for x in range(2,n):
                if(n % x==0):
                    return False
            return True

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
# print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
# print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
# print(" {}".format(i), end="")

def printA(A):
    N = len(A)
    for i, n in enumerate(A):
        print(n, end='')
        if i != N-1:
            print(' ', end='')
    print()

# リスト内包表記 ifあり
# [x-k if x != 0 else x for x in C]

# ソート
# N = N.sort()

# 10000個の素数リスト
# P = mymath.pnum_eratosthenes(105000)

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

while True:
    N = int(input())
    if N==0:
        break
    S = [int(x) for x in input().split()]

    ans = 0
    P = S.copy()

    while True:
        count = [0 for i in range(101)]
        for i in P:
            count[i] += 1
        C = []
        for i in P:
            C.append(count[i])
        
        ans += 1

        if P == C:
            break
        else:
            P = C.copy()
    
    print(ans-1)
    printA(P)

Python: while True:
    n = int(input())
    if n == 0:
        break
    else:
        s = list(map(int, input().split(' ')))

    times = 0
    old_nums = [-1] * n
    while old_nums != s:
        new_nums = []
        for i in s:
            new_nums.append(s.count(i))
        old_nums = s[::]
        s = new_nums[::]
        times += 1
    print(times - 1)
    print(' '.join(map(str, s)))

Python: while True:
    n = int(input())
    if n == 0:
        break
    s_list = [list(map(int, input().split()))]
    i = 0
    while True:
        i += 1
        s = []
        for j in s_list[-1]:
            s.append(s_list[-1].count(j))
        if s == s_list[-1]:
            break
        s_list.append(s)
    print(i - 1)
    print(*s)