#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, d;
  cin >> n >> m >> d;
  d++;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a.begin(), a.end());
  int days = 0;
  unordered_map<int, int> day;
  set<int> s;
  for (int x : a) {
    int cur = d - x;
    auto it = s.lower_bound(cur);
    if (it != s.end()) {
      day[-x] = day[*it];
      s.erase(it);
    } else {
      day[-x] = ++days;
    }
    s.insert(-x);
  }
  cout << days << "\n";
  for (const int &x : b) cout << day[-x] << " ";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  while (t--) solve();
  return 0;
}
