"use strict";

var util = require("util"),
    puts = util.puts,
    p = util.print,
    cin = parseInput();

function isFixed(nums, prev) {
    if ( prev === undefined || nums.length != prev.length ) return false;
    for ( var i = 0; i < nums.length; i++ ) {
        if ( nums[i] != prev[i] ) return false;
    }
    return true;
}

function toFrequency(nums) {
    var memo = [],
        ret = [];

    for ( var i = 0; i < nums.length; i++ ) {
        var n = nums[i],
            cnt = 1;

        if ( memo[n] === undefined ) {
            for ( var j = i + 1; j < nums.length; j++ ) {
                if ( n == nums[j] ) cnt++;
            }
            memo[n] = cnt;
        }
        ret[i] = memo[n];
    }
    return ret;
}

var n;

while( n = cin.nextInt() ) {
    var nums = [],
        prev = [],
        cnt = 0;

    while(n--) nums.push(cin.nextInt());

    while(true) {
        prev = nums.slice(0);
        nums = toFrequency(nums);

        if ( isFixed(nums, prev) ) break;
        cnt++;
    }

    puts(cnt);
    puts(nums.join(" "));
}


function parseInput(useSplitSpace) {
    var index = 0,
        ret = [],
        input = require("fs").readFileSync("/dev/stdin", "utf8"),
        inputs = input.replace(/\r/g, '').split("\n");

    useSplitSpace = useSplitSpace || true;

    // 入力を改行/空白で区切り平坦な配列に変換
    inputs.forEach(function(val) {
        if ( useSplitSpace && val !== "" ) {
            val.split(" ").forEach(function(el) {
                if ( el !== "" ) ret.push(el);
            });
        } else {
            ret.push(val);
        }
    });

    return {
        hasNext: function(val) {
            if ( typeof val === "undefined" ) {
                return typeof ret[index] !== "undefined";
            } else {
                return ret[index] === val;
            }
        },
        next: function() {
            if ( typeof ret[index+1] === "undefined" ) throw new RangeError("Index out of bounds at '" + index+1 + "'");
            return ret[index++];
        },
        nextNumber: function () {
            if ( !/^\d+$/.test(this.top()) ) throw new TypeError("'" + this.top() + "' cannot convet to Number");
            return +this.next();
        },
        nextInt: function() {
            return parseInt(this.nextNumber());
        },
        top: function() {
            return ret[index];
        },
        rewind: function() {
            index = 0;
        }
    };
}