import scala.io.StdIn.{readInt,readLine}

object Main {
  def scan(s:Array[Int],cnt:Int):(Array[Int],Int) = {
    val m = s.groupBy(_.self).map(i=>i._1->i._2.length)
    val mapped = s.map{ m(_) }
    if(mapped.sameElements(s)) (mapped,cnt)
    else
      scan(mapped,cnt+1)
  }
  def main(args:Array[String]) = {
    var n = 0
    while({n=readInt;n}!=0) {
      val s = readLine.split(" ").map(_.toInt)
      val r = scan(s,0)
      println(r._2)
      println(r._1.mkString(" "))
    }
  }
}