#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 ans = 1;
pair <int, int> a[n];
int id = 1;
for (auto &[x, y] : a) cin >> x, y = id++;
sort(a, a+n);
deque <int> dq;
for (int i = 0; i < n; i++) {
dq.emplace_back(a[i].first);
while (dq.size() && dq.front() + d <= a[i].first) dq.pop_front();
ans = max(ans, (int) ceil((double) dq.size() / (d+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++;
}