#include <iostream>
#include <vector>
#include <map>

int main()
{
    int input_num;
    
    while (std::cin >> input_num) {
        
        /*終了条件*/
        if (input_num == 0) break;
    
        std::vector<int> num_array(input_num, 0);

        for (int i = 0; i < input_num; ++i) {
            std::cin >> num_array[i];
        }
        
        bool is_end = false;
        int ans_num = 0;

        while (!is_end) {
            std::map<int, int> array_cnt;
            int i = 0;
            std::vector<int> copy_array(num_array);

            while (i < input_num) {
                array_cnt[copy_array[i]] += 1;
                i++;
            }

            for (int i = 0; i < input_num; ++i) {
                copy_array[i] = array_cnt[copy_array[i]];
            }
            
            if (copy_array == num_array) {
                is_end = true;
            } else {
                ans_num++;
                num_array = copy_array;
            }
        }

        std::cout << ans_num << std::endl;
        
        for (int i = 0; i < input_num; ++i) {
            std::cout << num_array[i] << " ";
        }

        std::cout << std::endl;
    }

    return 0;
}