#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
multiset<int> s[N];
int cnt[N];
int main() {
  int n;
  cin >> n;
  int a[n];
  int mi = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[i] = x;
    mi = max(mi, x);
    cnt[x]++;
    s[x].insert(i);
  }
  for (int i = mi; i > 1; i--) {
    if (cnt[i] > cnt[i - 1]) return cout << -1, 0;
  }
  int ans[N];
  int ma = 0;
  for (int i = 0; i < n; i++) {
    ans[i] = s[a[i]].size();
    ma = max(ma, ans[i]);
    s[a[i]].erase(s[a[i]].find(i));
  }
  for (int i = 1; i <= n; i++) {
    if (s[a[i - 1]].size()) {
      return cout << -1, 0;
    }
  }
  cout << ma << endl;
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
}
