#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define ll int
#define double double long
#define fori(i,j,k) for(ll i=j; i<=k;i++)
#define study ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define all(s) s.begin(),s.end()
#define ins insert
#define ss second
#define ff first
#ifndef DB
#define DB 0
#endif
#define debugl(l) if constexpr((l)<DB)
#define debug debugl(0)
const ll sz=1e6+10;
ll INF=1e9;
ll mod=1e9+7;
void work(){
ll n,d,m;
cin>>n>>d>>m;
vector<pair<ll,ll>>v(m);
vector<ll>ig;
fori(i,0,m-1){
cin>>v[i].ff;
v[i].ss=i;
}
sort(all(v));
vector<ll>en(n+10,0);
fori(i,0,m-1){
en[v[i].ff]=i+1;
}
fori(i,1,n-d)
ig.pb(en[i]);
ll l=0,r=sz;
while(l<=r){
ll mid=(l+r)>>1;
bool ok=1;
fori(i,1,n-d){
ll cur=((i+d)*mid);
if(cur<0)
cur=INT_MAX;
if(cur<en[i])
ok=0;
}
if(ok==0){
l=mid+1;
}
else{
r=mid-1;
}
}
/*
8 2 12
1 2 4 2 1 3 5 6 2 3 6 4
*/
ll p=r+1;
cout<<p<<endl;
ll cur=0;
fori(i,0,m-1){
cout<<v[i].ss+1<<' ';
cur++;
if(cur%p==0 || (en[v[i].ff])==(i+1)){
cur=0;
cout<<0<<"\n";
}
}
}
int main()
{
//#ifndef LOCAL
// freopen("log1.txt","r",stdin);
// freopen("log2.txt","w",stdout);
//#endif
study;
ll t=1;
//cin>>t;
fori(i,1,t){
work();
}
}