#include <bits/stdc++.h>
using namespace std;

#define fru(j,n) for(int j=0; j<(n); ++j)
#define tr(it,v) for(auto it=(v).begin(); it!=(v).end(); ++it)
//#define tr(it,v) for(typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define x first
#define y second
#define pb push_back
#define ALL(G) (G).begin(),(G).end()

#define y0 yy0
#if 0
        #define DEB printf
#else
        #define DEB(...)
#endif

typedef long long ll;
typedef long long LL;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int inft = 1000000009;
const int mod = 1000000007;
const int MAXN = 1000006;

int n;
ll d, x0, y0;
multiset<ll> F[4];
ll ans = 0;
ll s[4];

void wyciagnij(int a) {
        int b = (a+3)%4;
        if(F[b].empty()) wyciagnij(b);
        ll v = *(F[b].begin());
        F[b].erase(F[b].begin());
        F[a].insert(2*d);
        s[b]-=v;
        s[a]+=2*d;
        DEB("wyciagam %lld z %d\n",v,b);
        ans += v;
        if(b==0) x0-=v;
        if(b==1) y0-=v;
        if(b==2) x0+=v;
        if(b==3) y0+=v;
}

void solve() {
        scanf("%d%lld%lld%lld",&n,&d,&x0,&y0);
        fru(i,n) {
                ll x,y;
                scanf("%lld%lld",&x,&y);
                if(y==-d && x!= d) F[0].insert(d-x);
                if(x== d && y!= d) F[1].insert(d-y);
                if(y== d && x!=-d) F[2].insert(x+d);
                if(x==-d && y!=-d) F[3].insert(y+d);
                x0 -= x;
                y0 -= y;
                ans++;
        }
        fru(h,4) for(ll a : F[h]) s[h] += a;
        while(1) {
                DEB("%lld %lld / %lld %lld %lld %lld\n",x0,y0,s[0],s[1],s[2],s[3]);
                DEB("ans %lld\n",ans);
                if(x0 <= s[0] && x0 >= -s[2] && y0 <= s[1] && y0 >= -s[3]) {
                        printf("%lld\n", ans+abs(x0)+abs(y0));
                        return;
                }
                if(x0 > s[0]) wyciagnij(0);
                else if(x0 < -s[2]) wyciagnij(2);
                else if(y0 > s[1]) wyciagnij(1);
                else wyciagnij(3);
        }
}

int main() {
        int te = 1;
//        scanf("%d",&te);
        fru(ti,te) solve();
        return 0;
}