#include <iostream>
#include <map>

using namespace std;

bool equal(int* a, int* b, int n) {
  for (int i = 0; i < n; i++)
    if (a[i] != b[i])
      return false;
  return true;
}

int main() {
  for (;;) {
    int n;
    cin >> n;
    if (!n) return 0;
    int p[n], s[n], result = 0;
    for (int i = 0; i < n; i++)
      cin >> p[i];
    for (;;) {
      for (int i = 0; i < n; i++)
        s[i] = p[i];
      map<int, int> counts;
      for (int i = 0; i < n; i++)
        counts[s[i]]++;
      for (int i = 0; i < n; i++)
        p[i] = counts[s[i]];
      if (equal(p, s, n)) break;
      result++;
    }
    cout << result << endl;
    for (int i = 0; i < n-1; i++)
      cout << p[i] << ' ';
    cout << p[n-1] << endl;
  }
}