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

def pr(s):
    c=0
    while 1:
        b=s
        t=Counter(s)
        s=[t[i] for i in s]
        c+=1
        if b==s:break
    return s,c-1

while 1:    
    le=int(input())
    if not le:break
    s=list(map(int,input().split()))
    s,c=pr(s)
    print(c)
    print(" ".join(map(str,s)))

Python: while True:
    n = int(input())
    if n == 0:
        break
    a = list(map(int, input().split()))
    b = []
    cnt = 0
    while True:
        for i in a:
            b.append(a.count(i))
        if a == b:
            break
        else:
            a, b = b[:], []
            cnt+=1
    print(cnt)
    print(*a)

Python: # -*- coding: utf-8 -*-

import sys
import os
import math

def freq_op(A):
    B = []
    for a in A:
        B.append(A.count(a))
    return B

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

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

    cnt = 0
    while True:
        B = freq_op(A)
        cnt += 1
        if B == A:
            break
        else:
            A = B

    print(cnt - 1)
    print(*A)

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

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
    return 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 = list(map(int, input().split()))
    pre, cur = [S.count(s) for s in S], []
    cnt = 0
    while pre:
        cur = [pre.count(p) for p in pre]
        pre = 0 if cur == pre else cur[::]
        cnt += 1
    print(cnt)
    print(' '.join(map(str, cur)))

Python: import sys


def _nextstep(s):
    retval=[0 for i in range(len(s))]
    for i,si in enumerate(s):
        retval[i]=s.count(si)
    return retval

def fudouten(s):
    count=0
    while True:
        next=_nextstep(s)
        if next==s:
            return count,s
        else:
            s=next
            count+=1

while True:
    n=int(input())
    if n==0:
        sys.exit()
    s=[int(i) for i in input().split(" ")]
    count,ans=fudouten(s)
    print(count)
    print(" ".join([str(s) for s in ans]))

Python: while 1:
    n=int(input())
    if n==0:break
    count=0
    S_keep=list(map(int,input().split()))
    while 1:
        S=[]
        for i in S_keep:
            S.append(S_keep.count(i))
        if S_keep==S:
            print(count)
            print(" ".join(map(str,S)))
            break
        else:
            count+=1
            S_keep=S

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(' '.join(map(str, cur)))

Python: while True:
    n = int(input())
    if n == 0:
        break
    Num_lis = list(map(int,input().split()))
    New_lis = []
    num = 0
    while True:
        for i in range(n):
            New_lis.append(Num_lis.count(Num_lis[i]))
        if Num_lis == New_lis:
            break
        num += 1
        Num_lis = New_lis
        New_lis = []
    print(num)
    ans = str(Num_lis[0])
    for j in range(1,n):
        ans = ans + " " + str(Num_lis[j])
    print(ans)

Python: while 1:
	n=int(input())
	if n==0:
		break
	s=list(map(int,input().split()))
	cont=0
	while 1:
		tmp=[]
		for i in range(n):
			tmp.append(s.count(s[i]))
		if s==tmp:
			print(cont)
			break
		else:
			s=tmp
			cont+=1
	for i in range(n):
		if i != n-1:
			print(s[i],end=' ')
		else:
			print(s[i])

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 pre:
        cur = [pre.count(p) for p in pre]
        pre = 0 if cur == pre else cur[::]
        cnt += 1
    print(cnt-1)
    print(' '.join(map(str, cur)))

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


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

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

        for case in count():
            ran = {i: ary.count(i) for i in ary}
            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: 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 = 0
    while pre:
        cur = [pre.count(p) for p in pre]
        pre = 0 if cur == pre else cur[::]
        cnt += 1
    print(str(cnt))
    print(' '.join(map(str, cur)))

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 me.io import dup_file_stdin

#@dup_file_stdin
def solve():
    while True:
        n = int(sys.stdin.readline())
        if n == 0 : return
        a = list(map(int,sys.stdin.readline().split(' ')))
        ops = 0
        while True:
            cnt = dict()
            for x in a:
                cnt[x] = cnt.get(x,0) + 1
            changed = False
            for x in a:
                if x != cnt[x]:
                    changed = True
                    break
            if changed:
                a = [cnt[x] for x in a]
                ops += 1
            else:
                print(ops)
                print(' '.join(map(str,a)))
                break
solve()

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]]
		for i in range(n): f[a[k1][i]] = 0
		if a[0] == a[1]: break
		k1 = k2
		cnt += 1
	print(cnt)
	print(*a[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