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)))
	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: while True:
    n = int(input())
    if n == 0:
        break
    S = list(map(int, input().split()))
    pre = [S.count(s) for s in S]
    cur = []
    cnt = 1
    while cnt < n:
        cur = [pre.count(p) for p in pre]
        if cur == pre:
            break
        pre = [c for c in cur]
        cnt += 1
    print(cnt)
    print(*cur)

Python: def f(a,c):
    b=[a.count(i) for i in a]
    if b==a:print(c);print(' '.join(map(str,b)));return
    f(b,c+1) 
while 1:
    n=int(input())
    if not n:break
    a=list(map(int,input().split()))
    f(a,0)

Python: while True:
    length = int(input())

    if length == 0:
        break

    oldList = [int(item) for item in input().split(" ")]
    operateCount = 0

    while True:

        numberCount = {}
        for item in oldList:
            if item in numberCount:
                numberCount[item] += 1
            else:
                numberCount[item] = 1

        newList = []
        for number in oldList:
            newList.append(numberCount[number])

        if oldList == newList:
            print(str(operateCount))
            items = [str(item) for item in newList]
            items = " ".join(items)
            print(items)
            break

        operateCount += 1
        oldList = newList

Python: while True:
	n = int(input())
	if n == 0:
	    break
	s = []
	u = 0
	v = 0
	s = list(map(int, 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: while(int(input())):
    ar = list(map(int, input().split()))
    n = 0
    while(True):
        br = [ar.count(l) for l in ar]
        if ar == br:
            break
        ar = br
        n += 1
    print(n)
    print(" ".join(str(e) for e in br))

Python: while 1:
 n=int(input())
 if n:
  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: # AOJ 0108 Operation of Frequency of Appearance
# Python3 2018.6.18 bal4u

f = [0]*105
a = [[0 for j in range(15)] for i in range(2)]
while True:
	n = int(input())
	if n == 0: break
	a[0] = list(map(int, input().split()))
	a[1] = [0]*n
	cnt = k1 = 0
	while True:
		for i in range(n): f[a[k1][i]] += 1
		k2 = 1-k1
		for i in range(n): a[k2][i] = f[a[k1][i]]
		if a[0] == a[1]: break
		for i in range(n): f[a[k1][i]] = 0
		k1 = k2
		cnt += 1
	print(cnt)
	print(*a[0])

Python: while 1:
 n=int(input())
 if n==0: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: 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: #!/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):
    counter = Counter()

    while 1:
        if not int(readline()):
            exit()

        ary = [int(digit) for digit in readline().split()]

        for num in count():
            counter.clear()
            counter.update(ary)
            if all(key == value for key, value in counter.items()):
                break
            ary = [counter[value] for value in ary]

        print(num)
        print(*ary)


if __name__ == '__main__':
    main()

Python: import sys
a=sys.stdin
while 1:
 if'0'==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: def f(l,c):
  m = [l.count(i) for i in l]
  c += 1
  if l == m:
    print(c-1)
    m = [str(i) for i in m]
    print(' '.join(m))
    return
  else:
    f(m,c)
  
while True:
  n = int(input())
  if n == 0:
    break
  l = [i for i in input().split()]
  f(l,0)

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
            ary = [ran[i] for i in ary]
            if all(key == cnt for key, cnt in ran.items()):
                break

        print(case if case else 1)
        print(*ary)


if __name__ == '__main__':
    main()

Python: import sys
for a in sys.stdin:
 if' 'not in a:break
 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: 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: import sys
from collections import Counter


def c2f(data):
    num = 0
    while True:
        counter = Counter(data)
        next = [counter[item] for item in data]
        if data == next:
            break
        num += 1
        data = next

    return num, data

while True:
    num = int(sys.stdin.readline())
    if num == 0:
        break
    line = sys.stdin.readline()
    data = [int(item) for item in line.split(' ')]

    num, result = c2f(data)
    print(num)
    print(*result, sep = ' ')

Python: output = []

while True:
    length = int(input())

    if length == 0:
        break

    oldList = [int(item) for item in input().split(" ")]
    operateCount = 0

    while True:

        numberCount = {}
        for item in oldList:
            if item in numberCount:
                numberCount[item] += 1
            else:
                numberCount[item] = 1

        newList = []
        for number in oldList:
            newList.append(numberCount[number])

        if oldList == newList:
            output.append(str(operateCount))
            items = [str(item) for item in newList]
            items = " ".join(items)
            output.append(items)
            break

        operateCount += 1
        oldList = newList

print("\n".join(output))

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_str:
			print(str(v))
			print(" ".join(t_str))
			break
		else:
			s = t
			v += 1

Python: from collections import Counter

def solve():
    N = int(input())
    if N == 0:
        return False
    *S, = map(int, input().split())
    cnt = 0
    while 1:
        c = Counter(S)
        *T, = map(c.__getitem__, S)
        if S == T:
            break
        S = T
        cnt += 1
    print(cnt)
    print(*S)
    return True
while solve():
    ...