#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n,a,b; cin >> n >> a >> b; int c = a/gcd(a,b+1);
auto rngins = [&](set<pair<int,int>>& S,int l,int r) -> void {
while(true){
auto it = S.lower_bound(make_pair(l-1,0));
if (it==S.end()||it->second>r+1) break;
l = min(l,it->second),r = max(r,it->first),S.erase(it);
}
S.emplace(r,l);
};
set<pair<int,int>> S;
auto ins = [&](int l,int r) -> void {
//cout << '!' << l << ' ' << r << ' ' << l%c << ' ' << r%c << endl;
if (l>r) return;
if (r-l+1>=c) rngins(S,0,c-1);
else if (l%c<=r%c) rngins(S,l%c,r%c);
else rngins(S,l%c,c-1),rngins(S,0,r%c);
};
map<int,set<pair<int,int>>> M;
while(n--){
int l,r; cin >> l >> r; ins((l+b-1)/b,r/b-1);
if ((l+b-1)/b>r/b) rngins(M[l/b%c],l%b,r%b);
else {
if (l%b) rngins(M[l/b%c],l%b,b-1);
rngins(M[r/b%c],0,r%b);
}
}
int res(0);
for (auto [x,y]:S) res += (x-y+1)*b;//,(cout<<x<<' '<<y<<endl);
for (auto [t,A]:M){
auto it = S.lower_bound(make_pair(t,0));
//cout << t << endl;
//for (auto [x,y]:A) cout << x << ' ' << y << endl;
if (it!=S.end()&&it->second<=t) continue;
for (auto [x,y]:A) res += x-y+1;
}
cout << res << endl;
}