#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;
typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;
const int maxN = int(2e6)+7;
int n , p , q , m , a[maxN];
int first[maxN] , last[maxN];
ii dp[maxN];
void solve(){
cin >> n >> p >> q >> m;
for (int i = 1 ; i <= n ; i++){
first[i] = +maxN;
last[i] = -maxN;
}
for (int i = 1 ; i <= m ; i++){
int x , y;
cin >> x >> y;
first[y] = min(first[y] , x);
last[y] = max(last[y] , x);
}
dp[0] = {0 , 0};
for (int i = 1 ; i <= n ; i++){
dp[i].fi = max(dp[i - 1].fi + p , last[i]);
dp[i].se = min(dp[i - 1].se + q , first[i] + q - 1);
}
int k = -1;
for (int i = 1 ; i <= n ; i++){
if (dp[i].fi <= n && n <= dp[i].se) k = i;
}
cout << k << "\n";
int cur = n;
while (k > 0){
for (int i = cur - 1 ; i >= 0 ; i--){
if (dp[k - 1].fi <= i && i <= dp[k - 1].se && p <= cur - i && cur - i <= q && first[k] > i){
for (int j = i + 1 ; j <= cur ; j++) a[j] = k;
cur = i;
k--;
break;
}
}
}
for (int i = 1 ; i <= n ; i++) cout << a[i] << " ";
}
#define name "K"
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(name".INP" , "r")){
freopen(name".INP" , "r" , stdin);
freopen(name".OUT" , "w" , stdout);
}
int t = 1; //cin >> t;
while (t--) solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBhbGwodikgdi5iZWdpbigpICwgdi5lbmQoKQojZGVmaW5lIHN6KHYpIGludCh2LnNpemUoKSkKI2RlZmluZSB1bnEodikgc29ydChhbGwodikpOyB2LnJlc2l6ZSh1bmlxdWUoYWxsKHYpKSAtIHYuYm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jsKICAgIHdoaWxlIChrID4gMCl7CiAgICAgICAgZm9yIChpbnQgaSA9IGN1ciAtIDEgOyBpID49IDAgOyBpLS0pewogICAgICAgICAgICBpZiAoZHBbayAtIDFdLmZpIDw9IGkgJiYgaSA8PSBkcFtrIC0gMV0uc2UgJiYgcCA8PSBjdXIgLSBpICYmIGN1ciAtIGkgPD0gcSAmJiBmaXJzdFtrXSA+IGkpewogICAgICAgICAgICAgICAgZm9yIChpbnQgaiA9IGkgKyAxIDsgaiA8PSBjdXIgOyBqKyspIGFbal0gPSBrOwogICAgICAgICAgICAgICAgY3VyID0gaTsKICAgICAgICAgICAgICAgIGstLTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgZm9yIChpbnQgaSA9IDEgOyBpIDw9IG4gOyBpKyspIGNvdXQgPDwgYVtpXSA8PCAiICI7Cn0KCiNkZWZpbmUgbmFtZSAiSyIKCmludCBtYWluKCl7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApOyBjaW4udGllKDApOyBjb3V0LnRpZSgwKTsKICAgIGlmIChmb3BlbihuYW1lIi5JTlAiICwgInIiKSl7CiAgICAgICAgZnJlb3BlbihuYW1lIi5JTlAiICwgInIiICwgc3RkaW4pOwogICAgICAgIGZyZW9wZW4obmFtZSIuT1VUIiAsICJ3IiAsIHN0ZG91dCk7CiAgICB9CiAgICBpbnQgdCA9IDE7IC8vY2luID4+IHQ7CiAgICB3aGlsZSAodC0tKSBzb2x2ZSgpOwogICAgcmV0dXJuIDA7Cn0KCg==