#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, d, m; cin >> m >> d >> n;
int L = 1, R = n, ans = -1;
pair <int, int> a[n];
int id = 0;
for (auto &[x, y] : a) cin >> x, y = id++;
sort(a, a+n);
while (L <= R) {
int x = L + (R-L)/2, ok = 1;
int it = 0, c = 0;
while (it < n) {
++c;
for (int i = 0; i < x; i++) {
if (a[it].first > c) break;
if (a[it].first + d < c) { ok = 0; break; }
it++;
}
if (ok == 0) break;
}
if (ok) ans = x, R = x-1;
else L = x+1;
}
cout << ans << '\n';
int x = ans, it = 0, c = 0;
while (it < n) {
++c;
for (int i = 0; i < x; i++) {
if (a[it].first > c) break;
cout << a[it].second << ' ';
it++;
}
cout << 0 << '\n';
}
while (c < m) cout << 0 << '\n', c++;
}