#include <bits/stdc++.h>
#define int long long
int n,a,b;
std::vector<std::pair<int,int>> range;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> n >> a >> b;
int in1,in2;
for(int i=1;i<=n;i++)std::cin >> in1 >> in2,range.push_back({in1,in2});
int cycle1 = a/std::__gcd(b+1,a);
__int128 big = cycle1;big*=b;
int cycle2 = cycle1*b;
std::vector<std::pair<int,int>> compress;
if(big<=(__int128)1e18){
for(auto [l,r]:range){
if(r-l>=cycle2){
compress.push_back({0,cycle2-1});
continue;
}
int nl = l%cycle2;
int nr = r%cycle2;
if(l/cycle2==r/cycle2)compress.push_back({nl,nr});
else{
compress.push_back({0,nr});
compress.push_back({nl,cycle2-1});
}
}
}
else{
compress=range;
}
std::sort(compress.begin(),compress.end());
int ans=0,high=-1;
//std::cout << "->" << cycle1 << ' ' << cycle2 << '\n';
for(auto [l,r]:compress){
if(l>high){
high = std::max(high,r);
ans += r-l+1;
}
else{
ans += std::max((int)0,r-high);
high = std::max(high,r);
}
//std::cout << l << ' ' << r << ' ' << high << ' ' << ans << '\n';
}
std::cout << ans;
}