#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100100;
int n,k,m,p;
ll b[N];
pair<int,int>a[N];
set<pair<ll,int> >S;
bool chk(ll x){
	ll sum=0;
	for(int i=1;i<=n;++i){
		b[i]=x;
		ll ret=(a[i].first-(b[i]-(ll)m*a[i].second));ret=max(ret,0ll);
		ret=(ret+p-1)/p;if(ret>m)return 0;sum+=ret;
	}
	if(sum>m*k)return 0;
	S.clear();
	for(int i=1;i<=n;++i)S.emplace(b[i]/a[i].second,i);
	for(int i=m;i;--i){
		if(S.begin()->first<=0)return 0;
		for(int j=1;j<=k;++j){
			int x=S.begin()->second;S.erase(S.begin());
			b[x]+=p;S.emplace(b[x]/a[x].second,x);
		}
	}
	return 1;
}

int main(){
	cin>>n>>m>>k>>p;
	for(int i=1;i<=n;++i)cin>>a[i].first>>a[i].second;
	ll l=0,r=1e18;
	while(l<r){
		ll mid=(l+r)/2;
		if(chk(mid))r=mid;
		else l=mid+1;
	}
	cout<<l<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100100;
int n,k,m,p,cnt[N];
ll b[N];
pair<int,int>a[N];
priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >S;
bool chk(ll x){
	ll sum=0;
	for(int i=1;i<=n;++i){
		b[i]=x;
		ll ret=(a[i].first-(b[i]-(ll)m*a[i].second));ret=max(ret,0ll);
		cnt[i]=(ret+p-1)/p;if(cnt[i]>m)return 0;sum+=cnt[i];
	}
	if(sum>m*k)return 0;
	while(!S.empty())S.pop();
	for(int i=1;i<=n;++i)S.emplace(b[i]/a[i].second,i);
	for(int i=m;i&&!S.empty();--i){
		if(S.top().first<=0)return 0;
		for(int j=1;j<=k&&!S.empty();++j){
			int x=S.top().second;S.pop();
			if(!cnt[x]){--j;continue;}
			b[x]+=p;--cnt[x];S.emplace(b[x]/a[x].second,x);
		}
	}
	for(int i=1;i<=n;++i)if(cnt[i])return 0;
	return 1;
}

int main(){
	cin>>n>>m>>k>>p;
	for(int i=1;i<=n;++i)cin>>a[i].first>>a[i].second;
	ll l=0,r=1e18;
	while(l<r){
		ll mid=(l+r)/2;
		if(chk(mid))r=mid;
		else l=mid+1;
	}
	cout<<l<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100100;
int n,k,m,p;
ll b[N];
pair<int,int>a[N];
set<pair<ll,int> >S;
bool chk(ll x){
	ll sum=0;
	for(int i=1;i<=n;++i){
		b[i]=x;
		ll ret=(a[i].first-(b[i]-(ll)m*a[i].second));ret=max(ret,0ll);
		sum+=(ret+p-1)/p;
	}
	if(sum>m*k)return 0;
	S.clear();
	for(int i=1;i<=n;++i)S.emplace(b[i]/a[i].second,i);
	for(int i=m;i;--i){
		if(S.begin()->first<=0)return 0;
		for(int j=1;j<=k;++j){
			int x=S.begin()->second;S.erase(S.begin());
			b[x]+=p;S.emplace(b[x]/a[x].second,x);
		}
	}
	return 1;
}

int main(){
	cin>>n>>m>>k>>p;
	for(int i=1;i<=n;++i)cin>>a[i].first>>a[i].second;
	ll l=0,r=1e18;
	while(l<r){
		ll mid=(l+r)/2;
		if(chk(mid))r=mid;
		else l=mid+1;
	}
	cout<<l<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100100;
int n,k,m,p,cnt[N],f[N];
ll b[N];
pair<int,int>a[N];
priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >S;
bool chk(ll x){
	ll sum=0;
	for(int i=1;i<=n;++i){
		b[i]=x;
		ll ret=(a[i].first-(b[i]-(ll)m*a[i].second));ret=max(ret,0ll);
		cnt[i]=(ret+p-1)/p;if(cnt[i]>m)return 0;sum+=cnt[i];
	}
	if(sum>m*k)return 0;
	while(!S.empty())S.pop();
	for(int i=1;i<=n;++i)S.emplace(b[i]/a[i].second,i);
	for(int i=m;i&&!S.empty();--i){
		if(S.top().first<=0)return 0;
		for(int j=1;j<=k;++j)f[j]=-1;
		for(int j=1;j<=k&&!S.empty();++j){
			int x=S.top().second;S.pop();
			if(!cnt[x]){--j;continue;}
			b[x]+=p;--cnt[x];f[j]=x;
		}
		for(int j=1;j<=k;++j)if(f[j]!=-1)S.emplace(b[f[j]]/a[f[j]].second,f[j]);
	}
	for(int i=1;i<=n;++i)if(cnt[i])return 0;
	return 1;
}

int main(){
	cin>>n>>m>>k>>p;
	for(int i=1;i<=n;++i)cin>>a[i].first>>a[i].second;
	ll l=0,r=1e18;
	while(l<r){
		ll mid=(l+r)/2;
		if(chk(mid))r=mid;
		else l=mid+1;
	}
	cout<<l<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100100;
int n,k,m,p;
ll b[N];
pair<int,int>a[N];
set<pair<ll,int> >S;
bool chk(ll x){
	ll sum=0;
	for(int i=1;i<=n;++i){
		b[i]=x;
		ll ret=(a[i].first-(b[i]-m*a[i].second));ret=max(ret,0ll);
		sum+=(ret+p-1)/p;if((ret+p-1)/p>m)return 0;
	}
	if(sum>m*k)return 0;
	S.clear();
	for(int i=1;i<=n;++i)S.emplace(b[i]/a[i].second,i);
	for(int i=m;i;--i){
		if(S.begin()->first<=0)return 0;
		for(int j=1;j<=k;++j){
			int x=S.begin()->second;S.erase(S.begin());
			b[x]+=p;S.emplace(b[x]/a[x].second,x);
		}
	}
	return 1;
}

int main(){
	cin>>n>>m>>k>>p;
	for(int i=1;i<=n;++i)cin>>a[i].first>>a[i].second;
	ll l=0,r=1e18;
	while(l<r){
		ll mid=(l+r)/2;
		if(chk(mid))r=mid;
		else l=mid+1;
	}
	cout<<l<<'\n';
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100100;
int n,k,m,p;
ll b[N];
pair<int,int>a[N];
set<pair<ll,int> >S;
bool chk(ll x){
	ll sum=0;
	for(int i=1;i<=n;++i){
		b[i]=x;
		ll ret=(a[i].first-(b[i]-(ll)m*a[i].second));ret=max(ret,0ll);
		sum+=(ret+p-1)/p;
	}
	if(sum>m*k)return 0;
	S.clear();
	for(int i=1;i<=n;++i)S.emplace(b[i]/a[i].second,i);
	for(int i=m;i;--i){
		if(S.begin()->first<=m-i)return 0;
		for(int j=1;j<=k;++j){
			int x=S.begin()->second;S.erase(S.begin());
			b[x]+=p;S.emplace(b[x]/a[x].second,x);
		}
	}
	return 1;
}

int main(){
	cin>>n>>m>>k>>p;
	for(int i=1;i<=n;++i)cin>>a[i].first>>a[i].second;
	ll l=0,r=1e18;
	while(l<r){
		ll mid=(l+r)/2;
		if(chk(mid))r=mid;
		else l=mid+1;
	}
	cout<<l<<'\n';
	return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#define LL long long
#define mp(x,y) make_pair(x,y)
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
inline void write(LL x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
inline void pr1(int x){write(x);printf(" ");}
inline void pr2(LL x){write(x);puts("");}
LL h[100005],a[100005];
LL s1[100005];
int d[100005];
int n,m,K,P;LL mx;
bool check(LL u)
{
	memset(d,0,sizeof(d));
	bool bk=false;
	LL sum=0;
	for(int i=1;i<=n;i++)
	{
		if(h[i]+a[i]*m<u){s1[i]=h[i];continue;}
		bk=true;
		int cnt=m;LL temp=u;
		while(1&&cnt>1)
		{
			LL ok=(temp-a[i])/a[i]+1;//需要这么多天他凉了
			if(ok>=cnt)
			{
				temp-=(cnt-1)*a[i];
				break;
			}
			temp=temp-(ok-1)*a[i];cnt-=ok;
			LL gg=ceil((double)(2*a[i]-temp)/P);
			d[cnt+1]+=gg;sum+=gg;temp+=gg*P;
			temp-=a[i];
//			printf("GG %d %d %d\n",i,cnt,temp);
			if(sum>m*K)return false;
		}
//		puts("");
		s1[i]=temp-a[i];
	}
	if(!bk)return false;
	LL pre=0;
	for(int i=m;i>=1;i--)
	{
		pre+=d[i];
		if(pre>(m-i+1)*K)return false;//后面不够屯这么多次
	}
	for(int i=1;i<=n;i++)if(s1[i]<h[i])
		sum+=ceil((double)(h[i]-s1[i])/P);
	return sum<=m*K;
}
int main()
{
	n=read();m=read();K=read();P=read();
	LL l=0,r=0;
	for(int i=1;i<=n;i++)h[i]=read(),a[i]=read(),r=max(r,h[i]+a[i]*m),l=max(l,a[i]);
	LL ans;
	while(l<=r)
	{
		LL mid=(l+r)/2;
		if(check(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
//	ans=check(10);
	pr2(ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
const int M = 5e3+10;
vector<int> g[M];
int h[N],a[N],n,m,k,p;
ll b[N];
bool check(ll x){
    int rs=0;
    for(int i=1;i<m;++i) g[i].clear();
    for(int i=1;i<=n;++i){
        b[i]=x; if(b[i]<a[i]) return false;
        if(b[i]/a[i]<m) g[b[i]/a[i]].push_back(i);
    }
    for(int i=1;i<m;++i){
        rs+=k;
        for(auto o:g[i]){
            while(b[o]/a[o]==i){
                if(!rs) return false;
                rs--; b[o]+=p;
            }
            if(b[o]/a[o]<m) g[b[o]/a[o]].push_back(o);
        }
        g[i].clear();
    } rs+=k;
    for(int i=1;i<=n;++i){
        while(b[i]-1LL*a[i]*m<h[i]){
            if(!rs) return false;
            rs--; b[i]+=p;
        }
    }
    return true;
}
int main(){
    scanf("%d %d %d %d",&n,&m,&k,&p);
    for(int i=1;i<=n;++i) scanf("%d %d",&h[i],&a[i]);
    ll l=-1,r=5e11+1e9+1,mid;
    while(l+1<r){
        mid=(l+r)>>1;
        if(check(mid)) r=mid;
        else l=mid;
    }
    printf("%lld\n",r);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
const int M = 5e3+10;
vector<int> g[M];
int h[N],a[N],n,m,k,p;
ll b[N];
bool check(ll x){
    int rs=0;
    for(int i=1;i<=m;++i) g[i].clear();
    for(int i=1;i<=n;++i){
        b[i]=x; if(b[i]<a[i]) return false;
        if(b[i]/a[i]<=m) g[b[i]/a[i]].push_back(i);
    }
    for(int i=1;i<=m;++i){
        rs+=k;
        for(auto o:g[i]){
            while(b[o]/a[o]==i){
                if(!rs) return false;
                rs--; b[o]+=p;
            }
            if(b[o]/a[o]<=m) g[b[o]/a[o]].push_back(o);
        }
        g[i].clear();
    }
    for(int i=1;i<=n;++i){
        while(b[i]-1LL*a[i]*m<h[i]){
            if(!rs) return false;
            rs--; b[i]+=p;
        }
    }
    return true;
}
int main(){
    scanf("%d %d %d %d",&n,&m,&k,&p);
    for(int i=1;i<=n;++i) scanf("%d %d",&h[i],&a[i]);
    ll l=-1,r=5e11+1e9+1,mid;
    while(l+1<r){
        mid=(l+r)>>1;
        if(check(mid)) r=mid;
        else l=mid;
    }
    printf("%lld\n",r);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
const int M = 5e3+10;
vector<int> g[M];
int h[N],a[N],n,m,k,p;
ll b[N];
bool check(ll x){
    int rs=0;
    for(int i=1;i<m;++i) g[i].clear();
    for(int i=1;i<=n;++i){
        b[i]=x; if(b[i]<a[i]) return false;
        if(b[i]/a[i]<m) g[b[i]/a[i]].push_back(i);
    }
    for(int i=1;i<m;++i){
        rs+=k;
        for(auto o:g[i]){
            while(b[o]/a[o]==i){
                if(!rs) return false;
                rs--; b[o]+=p;
            }
            if(b[o]/a[o]<m) g[b[o]/a[o]].push_back(o);
        }
        g[i].clear();
    }
    for(int i=1;i<=n;++i){
        while(b[i]-1LL*a[i]*m<h[i]){
            if(!rs) return false;
            rs--; b[i]+=p;
        }
    }
    return true;
}
int main(){
    scanf("%d %d %d %d",&n,&m,&k,&p);
    for(int i=1;i<=n;++i) scanf("%d %d",&h[i],&a[i]);
    ll l=-1,r=5e11+1e9+1,mid;
    while(l+1<r){
        mid=(l+r)>>1;
        if(check(mid)) r=mid;
        else l=mid;
    }
    printf("%lld\n",r);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
const int M = 5e3+10;
vector<int> g[M];
int h[N],a[N],n,m,k,p;
ll b[N];
bool check(ll x){
    int rs=0;
    for(int i=1;i<m;++i) g[i].clear();
    for(int i=1;i<=n;++i){
        b[i]=x; if(b[i]<a[i]) return false;
        if(b[i]/a[i]<m) g[b[i]/a[i]].push_back(i);
    }
    for(int i=1;i<m;++i){
        rs+=k;
        for(auto o:g[i]){
            while(b[o]/a[o]==i){
                if(!rs) return false;
                rs--; b[o]+=p;
            }
            if(b[o]/a[o]<m) g[b[o]/a[o]].push_back(o);
        }
        g[i].clear();
    } rs+=k;
    for(int i=1;i<=n;++i){
        while(b[i]-1LL*a[i]*m<h[i]){
            if(!rs) return false;
            rs--; b[i]+=p;
        }
    }
    return true;
}
int main(){
    scanf("%d %d %d %d",&n,&m,&k,&p);
    for(int i=1;i<=n;++i) scanf("%d %d",&h[i],&a[i]);
    ll l=-1,r=5e12+1e9+1,mid;
    while(l+1<r){
        mid=(l+r)>>1;
        if(check(mid)) r=mid;
        else l=mid;
    }
    printf("%lld\n",r);
}


///                             In The Name Of Allah
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e5 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int h[N], a[N], f[N], n, m, k, p, mx = 0;

bool check(int x) {
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(x >= f[i])
			continue;
		cnt += (f[i] - x + p - 1) / p;
	}
	if(cnt > k * (m + 1))
		return false;
	for(int i = 1; i <= n; i++) {
		if(x >= f[i])
			continue;
		int val = (f[i] - x + p - 1) / p;
		int pos = 0, cnt = h[i];
		while(val && pos < m) {
			if(cnt >= p) {
				val--;
				cnt -= p;
				continue;
			}
			int g = (p - cnt + a[i] - 1) / a[i];
			if(g + pos > m) {
				cnt += (m - pos) * a[i];
				break;
			}
			cnt += g * a[i];
			cnt -= p;
			val--;
			pos += g;
		}
		if(val > 1)
			return false;
		if(val == 1 && max((int)0, cnt - p) + a[i] > x)
			return false;
	}
	return true;
}

int32_t main() {
	use_fast;
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i++)
		cin >> h[i] >> a[i], f[i] = h[i] + a[i] * m, mx = max(mx, f[i]);
	m--;
	int l = 0, r = mx;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << r << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/


///                             In The Name Of Allah
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e5 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int h[N], a[N], f[N], n, m, k, p, ct[N], mx = 0;

bool check(int x) {
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(x >= f[i])
			continue;
		cnt += (f[i] - x + p - 1) / p;
	}
	for(int i = 0; i <= m + 1; i++)
		ct[i] = 0;
	if(cnt > k * (m + 1))
		return false;
	for(int i = 1; i <= n; i++) {
		if(x >= f[i])
			continue;
		int val = (f[i] - x + p - 1) / p;
		int pos = 0, cnt = h[i];
		while(val && pos <= m) {
			if(cnt >= p) {
				val--;
				cnt -= p;
				continue;
			}
			int g = (p - cnt + a[i] - 1) / a[i];
			if(g + pos > m) {
				cnt += (m - pos) * a[i];
				if(val > 1 || max((int)0, cnt - p) + a[i] > x)
					return false;
				cnt -= (m - pos) * a[i];
				ct[min(x / a[i], m + 1)]++;
				break;
			}
			cnt += g * a[i];
			cnt -= p;
			val--;
			pos += g;
		}
	}
	for(int i = 1; i <= m + 1; i++) {
		ct[i] += ct[i - 1];
		if(i * k < ct[i])
			return false;
	}
	return true;
}

int32_t main() {
	use_fast;
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i++)
		cin >> h[i] >> a[i], f[i] = h[i] + a[i] * m, mx = max(mx, f[i]);
	m--;
	int l = 0, r = mx;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << r << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/


//                             In The Name Of Allah
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define ll long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e5 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int h[N], a[N], n, m, k, p;
ll f[N], mx;

bool check(ll x) {
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(x >= f[i])
			continue;
		cnt += (f[i] - x + p - 1) / p;
	}
	if(cnt > k * (m + 1))
		return false;
	for(int i = 1; i <= n; i++) {
		if(f[i] <= x)
			continue;
		int val = (f[i] - x + p - 1) / p;
		int pos = 0, cnt = h[i];
		while(val && pos < m) {
			if(cnt >= p) {
				val--;
				cnt -= p;
				continue;
			}
			int g = (p - cnt + a[i] - 1) / a[i];
			if(g + pos > m) {
				cnt += (m - pos) * a[i];
				break;
			}
			cnt += g * a[i];
			cnt -= p;
			val--;
			pos += g;
		}
		if(val > 1)
			return false;
		if(val == 1 && max((int)0, cnt - p) + a[i] > x)
			return false;
	}
	return true;
}

int32_t main() {
	use_fast;
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i++)
		cin >> h[i] >> a[i], f[i] = 1ll * h[i] + 1ll * a[i] * m, mx = max(mx, f[i]);
	m--;
	ll l = 0, r = mx;
	while(l < r) {
		ll mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << r << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/


//                             In The Name Of Allah
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e5 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int h[N], a[N], f[N], n, m, k, p, mx = 0;

bool check(int x) {
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(x >= f[i])
			continue;
		cnt += (f[i] - x + p - 1) / p;
	}
	if(cnt > k * (m + 1))
		return false;
	for(int i = 1; i <= n; i++) {
		int val = (f[i] - x + p - 1) / p;
		int pos = 0, cnt = h[i];
		while(val && pos < m) {
			if(cnt >= p) {
				val--;
				cnt -= p;
				continue;
			}
			int g = (p - cnt + a[i] - 1) / a[i];
			if(g + pos > m) {
				cnt += (m - pos) * a[i];
				break;
			}
			cnt += g * a[i];
			cnt -= p;
			val--;
			pos += g;
		}
		if(val > 1)
			return false;
		if(val == 1 && max((int)0, cnt - p) + a[i] > x)
			return false;
	}
	return true;
}

int32_t main() {
	use_fast;
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i++)
		cin >> h[i] >> a[i], f[i] = h[i] + a[i] * m, mx = max(mx, f[i]);
	m--;
	int l = 0, r = mx;
	while(l < r) {
		int mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << r << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/


//                             In The Name Of Allah
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
//#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e5 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int h[N], a[N], n, m, k, p;
ll f[N], mx;

bool check(ll x) {
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(x >= f[i])
			continue;
		cnt += (f[i] - x + p - 1) / p;
	}
	if(cnt > k * (m + 1))
		return false;
	for(int i = 1; i <= n; i++) {
		int val = (f[i] - x + p - 1) / p;
		int pos = 0, cnt = h[i];
		while(val && pos < m) {
			if(cnt >= p) {
				val--;
				cnt -= p;
				continue;
			}
			int g = (p - cnt + a[i] - 1) / a[i];
			if(g + pos > m) {
				cnt += (m - pos) * a[i];
				break;
			}
			cnt += g * a[i];
			cnt -= p;
			val--;
			pos += g;
		}
		if(val > 1)
			return false;
		if(val == 1 && max((int)0, cnt - p) + a[i] > x)
			return false;
	}
	return true;
}

int32_t main() {
	use_fast;
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i++)
		cin >> h[i] >> a[i], f[i] = 1ll * h[i] + 1ll * a[i] * m, mx = max(mx, f[i]);
	m--;
	ll l = 0, r = mx;
	while(l < r) {
		ll mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << r << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/


//                             In The Name Of Allah
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define ll long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 2e5 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
int h[N], a[N], n, m, k, p;
ll f[N], mx;

bool check(ll x) {
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		if(x >= f[i])
			continue;
		cnt += (f[i] - x + p - 1) / p;
	}
	if(cnt > k * (m + 1))
		return false;
	for(int i = 1; i <= n; i++) {
		int val = (f[i] - x + p - 1) / p;
		int pos = 0, cnt = h[i];
		while(val && pos < m) {
			if(cnt >= p) {
				val--;
				cnt -= p;
				continue;
			}
			int g = (p - cnt + a[i] - 1) / a[i];
			if(g + pos > m) {
				cnt += (m - pos) * a[i];
				break;
			}
			cnt += g * a[i];
			cnt -= p;
			val--;
			pos += g;
		}
		if(val > 1)
			return false;
		if(val == 1 && max((int)0, cnt - p) + a[i] > x)
			return false;
	}
	return true;
}

int32_t main() {
	use_fast;
	cin >> n >> m >> k >> p;
	for(int i = 1; i <= n; i++)
		cin >> h[i] >> a[i], f[i] = 1ll * h[i] + 1ll * a[i] * m, mx = max(mx, f[i]);
	m--;
	ll l = 0, r = mx;
	while(l < r) {
		ll mid = (l + r) >> 1;
		if(check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	cout << r << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04
5- ...
*/


#include<bits/stdc++.h>
const int N=100010;
int n,m,k,c[N];
long long p,h[N],a[N];
int check(long long an){
	std::priority_queue< std::pair<int,int> >q;
	for(int i=1;i<=n;++i){
		if(h[i]+m*a[i]<=an)continue;
		q.push(std::make_pair(-(an/a[i]),i));
		c[i]=0;
	}
	int cnt=0;
	for(int i=1;q.size()&&i<=m;++i){
		for(int j=1;q.size()&&j<=k;++j){
			if(-q.top().first<i)return 0;
			int now=q.top().second;c[now]++;
			q.pop();
			if(c[now]*p+an-m*a[now]<h[now])q.push(std::make_pair(-(an+c[now]*p)/a[now],now));
			++cnt;
		}
	}
	return q.empty();
}
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cin>>n>>m>>k>>p;
	for(int i=1;i<=n;++i){
		std::cin>>h[i]>>a[i];
	}
	long long L=0,R=0;
	for(int i=1;i<=n;++i){
		R=std::max(R,h[i]+1ll*a[i]*m);
	}
	while(R-L>=3){
		long long Mid=(R+L)>>1;
		if(check(Mid))R=Mid;
		else L=Mid+1;
	}
	for(long long i=L;i<=R;++i){
		if(check(i)){
			std::cout<<i<<'\n';
			return 0;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
inline LL read()
{
	LL num=0, fl=1;
	char ch=getchar();
	while (!isdigit(ch)){if (ch=='-') fl=-1; ch=getchar();}
	while (isdigit(ch)){num=num*10LL+ch-'0'; ch=getchar();}
	return num*fl;
}
struct node
{
 	long long d;
 	int id;
 	bool operator<(const node&a)const{
  		return d>a.d;
 	}
};
long long a[100005],h[100005],t[100005],n,m,k,p;
bool check(long long x)
{
 	priority_queue<node> q;
 	for(int i=1;i<=n;i++)
 	{
  		t[i]=x;
  		if(x-a[i]*m<h[i])q.push({x/a[i],i});
 	}
 	for(int i=1;i<=m;i++)
  		for(int j=1;j<=k;j++)
  		{
   		if(q.empty())return true;
   		int d=q.top().d,id=q.top().id;
   		q.pop();
   		if(d<i)return false;
   		t[id]+=p;
   		if(t[id]-a[id]*m<h[id])q.push({t[id]/a[id],id});
  		}
 	return q.empty();
}
int main()
{
//	freopen("bamboo.in","r",stdin);
//	freopen("bamboo.out","w",stdout);
 	n = read(), m = read(), k = read(), p = read();
 	for(int i=1;i<=n;i++)
 		h[i] = read(), a[i] = read();
 	long long l=0,r=1ll<<60;
 	while(l<r)
 	{
  		long long mid=(l+r)>>1;
  		if(check(mid))r=mid;
  		else l=mid+1;
 	}
 	cout<<l<<endl;
 	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int N=200001;
int n,m,k,p;
long long a[N],h[N],f[N];
struct Node
{
    long long day;
    int id;
    bool operator > (const Node & b)const
    {
        return day>b.day;
    }
};
priority_queue<Node,vector<Node>,greater<Node> >q;
bool check(long long x)
{
    memset(f,0,sizeof(f));
    while(!q.empty()) q.pop();
    for(int i=1;i<=n;i++)
        if(x-a[i]*m<h[i]) q.push((Node){x/a[i],i});
    for(int i=1;i<=m;i++)
        for(int j=1;j<=k;j++)
        {
            if(q.empty()) return true;
            Node u=q.top();
            q.pop();
            if(u.day<i) return 0;
            f[u.id]++;
            if(x+p*f[u.id]-m*a[u.id]<h[u.id]) q.push((Node){(x+p*f[u.id])/a[u.id],u.id});
        }
    return q.empty();
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&h[i],&a[i]);
    long long l=0,r=1e15,ans;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%d",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#define mid ((l+r)>>1)
using namespace std;
const int N=100001;
const long long MAX=1e15;
int n,m,k,p;
long long h[N],a[N];
long long now[N];
bool check(long long x)
{
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
    for(int i=1;i<=n;i++)
    {
        now[i]=x;
        if(x-m*a[i]>=0)continue;
        q.push(make_pair(x/a[i],i));
    }
    int times=0;
    for(;times<=k*m;times++)
    {
        if(q.empty()) break;
        pair<int,int> u=q.top();
        q.pop();
        if(u.first<=times/k)return false;
        long long index=u.second;
        now[index]+=p;
        if(now[index]-m*a[index]>=0) continue;
        q.push(make_pair(now[index]/a[index],index));
    }
    if(times>k*m) return false;
    for(int i=1;i<=n;i++)
    {
        long long sum=m*a[i]+h[i]-now[i];
        if(sum<=0) continue;
        else times+=ceil((double)sum/p);
        if(times>k*m) return false;
    }
    return true;
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&k,&p);
    long long l=1,r=MAX;
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&h[i],&a[i]);
    while(l<r)
    {
        if(check(mid))r=mid;
        else l=mid+1;
    }
    printf("%lld",l);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
const int N=100001;
int n,m,k,p;
long long h[N],a[N];
long long now[N];
bool check(long long x)
{
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
    for(int i=1;i<=n;i++)
    {
        now[i]=x;
        if(x-m*a[i]>=0)continue;
        q.push(make_pair(x/a[i],i));
    }
    int times=0;
    for(;times<=k*m;times++)
    {
        if(q.empty()) break;
        pair<int,int> u=q.top();
        q.pop();
        if(u.first<=times/k)return false;
        now[u.second]+=p;
        if(now[u.second]-m*a[u.second]>=0) continue;
        q.push(make_pair(now[u.second]/a[u.second],u.second));
    }
    if(times>k*m) return false;
    for(int i=1;i<=n;i++)
    {
        long long sum=m*a[i]+h[i]-now[i];
        if(sum<=0) continue;
        else times+=ceil((double)sum/p);
        if(times>k*m) return false;
    }
    return true;
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&h[i],&a[i]);
    long long l=1,r=1e15,ans;
    while(l<=r)
    {
        long long mid=(l+r)/2;
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%lld",ans);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int N=200001;
int n,m,k,p;
long long a[N],h[N],f[N];
struct Node
{
    long long day;
    int id;
    bool operator > (const Node & b)const
    {
        return day>b.day;
    }
};
priority_queue<Node,vector<Node>,greater<Node> >q;
bool check(long long x)
{
    memset(f,0,sizeof(f));
    while(!q.empty()) q.pop();
    for(int i=1;i<=n;i++)
        if(x-a[i]*m<h[i]) q.push((Node){x/a[i],i});
    for(int i=1;i<=m;i++)
        for(int j=1;j<=k;j++)
        {
            if(q.empty()) return true;
            Node u=q.top();
            q.pop();
            if(u.day<i) return 0;
            f[u.id]++;
            if(x+p*f[u.id]-m*a[u.id]<h[u.id]) q.push((Node){(x+p*f[u.id])/a[u.id],u.id});
        }
    return q.empty();
}
int main()
{
    scanf("%d%d%d%d",&n,&m,&k,&p);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld",&h[i],&a[i]);
    long long l=0,r=1e10,ans;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(check(mid)) ans=mid,r=mid-1;
        else l=mid+1;
    }
    printf("%d",ans);
    return 0;
}


#include<cstdio>
#include<queue>
#include<iostream>
#define N 100000
#define mid ((l+r)>>1)
using namespace std;
const long long MAX=1e15;
long long n,m,k,p,l,r;
long long h[N+5],a[N+5];
long long now[N+5];
bool judge(long long x)
{
    priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
    for(long long i=0;i<n;++i)
    {
        now[i]=x;
        if(x-m*a[i]>=0)continue;
        q.push(make_pair(x/a[i],i));
    }
    long long times=0;
    for(;times<=k*m;times++)
    {
        if(q.empty())break;
        pair<int,int> temp=q.top();
        q.pop();
        if(temp.first<=times/k)return 0;
        long long index=temp.second;
        now[index]+=p;
        if(now[index]-m*a[index]>=0)continue;
        q.push(make_pair(now[index]/a[index],index));
    }
    if(times>k*m)return 0;
    for(int i=0;i<n;++i)
    {
        long long temp=m*a[i]+h[i]-now[i];
        if(temp<=0)continue;
        else times+=((temp/p)+(long long)(temp%p!=0));
        if(times>k*m)return 0;
    }
    return 1;
}
int main()
{
    scanf("%lld%lld%lld%lld",&n,&m,&k,&p);
    l=1,r=MAX;
    for(long long i=0;i<n;++i)
        scanf("%lld%lld",&h[i],&a[i]);
    while(l<r)
    {
        if(judge(mid))r=mid;
        else l=mid+1;
    }
    printf("%lld",l);
    return 0;
}


#include <bits/stdc++.h>

typedef long long LL;

const int MAXN = 1e5 + 10;

int n, m, K, p;
int a[MAXN], h[MAXN];
LL now[MAXN];
struct Node {
	int id, val;
	Node(int _ = 0, int $ = 0) { id = _, val = $; }
	inline friend bool operator< (const Node &a, const Node &b) { return a.val > b.val; }
};

inline bool check(LL k) {
	std::priority_queue <Node> Q;
	for (int i = 1; i <= n; ++i) now[i] = k;
	for (int i = 1; i <= n; ++i) if (h[i] + 1LL * a[i] * m > now[i]) Q.push(Node(i, now[i] / a[i]));
	for (int i = 1; i <= m; ++i)
		for (int j = 1; j <= K; ++j) {
			if (!Q.size()) return true;
			Node QAQ = Q.top(); Q.pop();
			if (QAQ.val < i) return false;
			now[QAQ.id] += p;
			if (h[QAQ.id] + 1LL * a[QAQ.id] * m > now[QAQ.id]) Q.push(Node(QAQ.id, now[QAQ.id] / a[QAQ.id]));
		}
	return Q.empty();
}

int main() {
	scanf("%d%d%d%d", &n, &m, &K, &p);
	for (int i = 1; i <= n; ++i) scanf("%d%d", h + i, a + i);
	LL ans = 0, max = 0;
	for (int i = 1; i <= n; ++i) max = std::max(max, h[i] + 1LL * a[i] * m);
	for (LL L = 1, R = max, mid = (L + R) >> 1; L <= R; mid = (L + R) >> 1) check(mid) ? (R = (ans = mid) - 1) : (L = mid + 1);
	printf("%lld\n", ans);
	return 0;
}


#include <iostream>
#include <queue>
#include <string.h>
#include <algorithm>
#define INF 0x3f3f3f3f3f3f3f
#define CRE priority_queue<Node, vector <Node>, greater <Node> >
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
ll a[maxn], b[maxn];
ll h[maxn];
struct Node {
    int day, id;
    Node() {};
    Node(int a, int b)
    :day(a), id(b){};
    friend bool operator > (Node a, Node b) {
        return a.day > b.day;
    }
};
int n, m, k, p;
priority_queue<Node, vector <Node>, greater <Node> > q;
void clear(CRE & s) {
    CRE k;
    swap(k, s);
}
bool check(ll x) {
    clear(q);
    memset(b, 0, sizeof(b));
    for (int i = 1; i <= n; i++) {
        if (a[i] * m + h[i] > x) {
            q.push(Node(x / a[i], i));
        }
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= k; j++) {
            if (q.empty())
            return true;
            Node y = q.top();
            q.pop();
            if (y.day < i)
            return false;
            b[y.id]++;
             if (x + b[y.id] * p - a[y.id] * m < h[y.id])
                q.push(Node((x + b[y.id] * p) / a[y.id], y.id));

        }
    }
    return q.empty();

}
int main() {
    cin >> n >> m >> k >> p;
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", h + i, a + i);
    }
    ll l = 0, r = INF;
    while (r > l) {
        ll mid = (r + l) >> 1;
        if (check(mid)) {
            r = mid;
        } else
         l = mid + 1;
    }
    cout << r << endl;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q) / p);
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        //if(mod[i] == 0)continue;
        ll pd = 0, Re = h[i], nd, nh;
        for(int j = 0; j < T[i]; j++){
            if(j == 0){
                if(Re >= mod[i]){
                    nd = pd;
                    nh = Re;
                }
                else{
                    nd = (mod[i] - Re + a[i] - 1) / a[i];
                    nh = nd * a[i] + h[i];
                }
            }
            else if(Re >= (j + 1) * p){
                nd = pd;
                nh = Re;
            }
            ans[nd]++;
            Re = nh;
            pd = nd;
            if(pd >= m){
                return 0;
            }
        }
    }
    for(int i = 0;i < m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << (up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q + p - 1) / p);
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        //if(mod[i] == 0)continue;
        ll pd = 0, Re = h[i], nd, nh;
        for(int j = 0; j < T[i]; j++){
            if(j == 0){
                if(Re >= mod[i]){
                    nd = pd;
                    nh = Re;
                }
                else{
                    nd = (mod[i] - Re + a[i] - 1) / a[i];
                    nh = nd * a[i] + h[i];
                }
            }
            else if(Re >= (j + 1) * p){
                nd = pd;
                nh = Re;
            }
            ans[nd]++;
            Re = nh;
            pd = nd;
            if(pd >= m){
                return 0;
            }
        }
    }
    for(int i = 0;i < m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q) / p);
            if(mod[i] == 0){
                T[i]--;
                mod[i] = p;
            }
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        //if(T[i] + (mod[i] != 0) > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        if(mod[i] == 0)continue;
        ll pd = -1;
        if(h[i] >= mod[i]){
            ans[0]++;
            pd = 0;
        }
        else{
            ans[(mod[i] - h[i] + a[i] - 1) / a[i]]++;
            pd = (mod[i] - h[i] + a[i] - 1) / a[i];
        }
        //cout << pd << " ";
        for(int j = 0; j < T[i]; j++){
            ll D = ((j + 1) * p + mod[i] - h[i] + a[i] - 1) / a[i];
            if(D <= pd){
                ans[pd + 1]++;
                pd++;
            }
            else{
                pd = D;
                ans[D]++;
            }
            //cout << pd << " ";
        }
        if(pd > m)return 0;
    }
    for(int i = 0;i < m; i++){
        if(ans[i] > k){
            ans[i + 1] += (k - ans[i]);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    return (ans[m - 1] <= k);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q) / p);
            if(mod[i] == 0){
                T[i]--;
                mod[i] = p;
            }
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] + (mod[i] != 0) > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        if(mod[i] == 0)continue;
        ll pd = -1;
        if(h[i] >= mod[i]){
            ans[0]++;
            pd = 0;
        }
        else{
            ans[(mod[i] - h[i] + a[i] - 1) / a[i]]++;
            pd = (mod[i] - h[i] + a[i] - 1) / a[i];
        }
        //cout << pd << " ";
        for(int j = 0; j < T[i]; j++){
            ll D = ((j + 1) * p + mod[i] - h[i] + a[i] - 1) / a[i];
            if(D <= pd){
                ans[pd + 1]++;
                pd++;
            }
            else{
                pd = D;
                ans[D]++;
            }
            //cout << pd << " ";
            if(pd >= m)return 0;
        }
    }
    for(int i = 0;i <= m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m + 1] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + MAXN, 0);
    fill(T, T + MAXN, 0);
    fill(mod, mod + MAXN, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q + p - 1) / p);
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i]);
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] > m)return 0;
    }
    if(cnt > m * k)return 0;
    for(int i = 0; i < n; i++){
        //if(mod[i] == 0)continue;
        ll pd = 0, Re = h[i], nd, nh;
        for(int j = 0; j < T[i]; j++){
            nd = (p - Re % p + a[i] - 1) / a[i] + pd;
            nh = nd * a[i] + h[i];
            if(j == 0){
                if(Re >= mod[i]){
                    nd = pd;
                    nh = Re;
                }
                else{
                    nd = (mod[i] - Re + a[i] - 1) / a[i];
                    nh = nd * a[i] + h[i];
                }
            }
            else if(Re >= (j + 1) * p){
                nd = pd;
                nh = Re;
            }
            ans[nd]++;
            Re = nh;
            pd = nd;
            if(pd >= m){
                return 0;
            }
        }
    }
    for(int i = 0;i < m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + MAXN, 0);
    fill(T, T + MAXN, 0);
    fill(mod, mod + MAXN, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q + p - 1) / p);
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i]);
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] > m)return 0;
    }
    if(cnt > m * k)return 0;
    for(int i = 0; i < n; i++){
        if(T[i] == 0)continue;
        ll pd = 0, Re = h[i];
        for(int j = 0; j < T[i]; j++){
            ll nd = (p - Re % p + a[i] - 1) / a[i] + pd , nh = nd * a[i] + h[i];
            if(j == 0){
                if(Re >= mod[i]){
                    nd = pd;
                    nh = Re;
                }
                else{
                    nd = (mod[i] - Re + a[i] - 1) / a[i];
                    nh = nd * a[i] + h[i];
                }
            }
            else if(Re >= (j + 1) * p){
                nd = pd;
                nh = Re;
            }
            Re = nh;
            pd = nd;
            ans[pd]++;
            if(pd >= m){
                return 0;
            }
        }
    }
    for(int i = 0;i < m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    if(ans[m] == 0)return 1;
    return 0;
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << up;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q) / p);
            if(mod[i] == 0){
                T[i]--;
                mod[i] = p;
            }
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] + (mod[i] != 0) > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        if(mod[i] == 0)continue;
        ll pd = -1;
        if(h[i] >= mod[i]){
            ans[0]++;
            pd = 0;
        }
        else{
            ans[(mod[i] - h[i] + a[i] - 1) / a[i]]++;
            pd = (mod[i] - h[i] + a[i] - 1) / a[i];
        }
        //cout << pd << " ";
        for(int j = 0; j < T[i]; j++){
            ll D = ((j + 1) * p + mod[i] - h[i] + a[i] - 1) / a[i];
            if(D <= pd){
                ans[pd + 1]++;
                pd++;
            }
            else{
                pd = D;
                ans[D]++;
            }
            //cout << pd << " ";
        }
    }
    for(int i = 0;i < m; i++){
        if(ans[i] > k){
            ans[i + 1] += (k - ans[i]);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    return (ans[m - 1] <= k);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q) / p);
            if(mod[i] == 0){
                T[i]--;
                mod[i] = p;
            }
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] + (mod[i] != 0) > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        if(mod[i] == 0)continue;
        ll pd = -1;
        if(h[i] >= mod[i]){
            ans[0]++;
            pd = 0;
        }
        else{
            ans[(mod[i] - h[i] + a[i] - 1) / a[i]]++;
            pd = (mod[i] - h[i] + a[i] - 1) / a[i];
        }
        //cout << pd << " ";
        for(int j = 0; j < T[i]; j++){
            ll D = ((j + 1) * p + mod[i] - h[i] + a[i] - 1) / a[i];
            if(D <= pd){
                ans[pd + 1]++;
                pd++;
            }
            else{
                pd = D;
                ans[D]++;
            }
            //cout << pd << " ";
            if(pd >= m)return 0;
        }
    }
    for(int i = 0;i < m; i++){
        if(ans[i] > k){
            ans[i + 1] += (k - ans[i]);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    return (ans[m] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q + p - 1) / p);
            if(mod[i] == 0){
                T[i]--;
                mod[i] = p;
            }
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] + (mod[i] != 0) > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        if(mod[i] == 0)continue;
        ll pd = -1;
        if(h[i] >= mod[i]){
            ans[0]++;
            pd = 0;
        }
        else{
            ans[(mod[i] - h[i] + a[i] - 1) / a[i]]++;
            pd = (mod[i] - h[i] + a[i] - 1) / a[i];
        }
        //cout << pd << " ";
        for(int j = 0; j < T[i]; j++){
            ll D = ((j + 1) * p + mod[i] - h[i] + a[i] - 1) / a[i];
            if(D <= pd){
                ans[pd + 1]++;
                pd++;
            }
            else{
                pd = D;
                ans[D]++;
            }
            //cout << pd << " ";
            if(pd >= m)return 0;
        }
    }
    for(int i = 0;i <= m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m + 1] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    ll cnt = 0;
    fill(ans, ans + MAXN, 0);
    fill(T, T + MAXN, 0);
    fill(mod, mod + MAXN, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q + p - 1) / p);
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i]);
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
    }
    if(cnt > m * k)return 0;
    for(int i = 0; i < n; i++){
        if(T[i] == 0)continue;
        ll pd = 0, Re = h[i];
        for(int j = 0; j < T[i]; j++){
            ll nd = (p - Re % p + a[i] - 1) / a[i] + pd , nh = nd * a[i] + h[i];
            if(j == 0){
                if(Re >= mod[i]){
                    nd = pd;
                    nh = Re;
                }
                else{
                    nd = (mod[i] - Re + a[i] - 1) / a[i];
                    nh = nd * a[i] + h[i];
                }
            }
            else if(Re >= (j + 1) * p){
                nd = pd;
                nh = Re;
            }
            Re = nh;
            pd = nd;
            ans[pd]++;
            if(pd >= m){
                return 0;
            }
        }
    }
    for(int i = 0;i < m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    if(ans[m] == 0)return 1;
    return 0;
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = 0, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << up;
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q) / p);
            if(mod[i] == 0){
                T[i]--;
                mod[i] = p;
            }
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] + (mod[i] != 0) > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        if(mod[i] == 0)continue;
        ll pd = -1;
        if(h[i] >= mod[i]){
            ans[0]++;
            pd = 0;
        }
        else{
            ans[(mod[i] - h[i] + a[i] - 1) / a[i]]++;
            pd = (mod[i] - h[i] + a[i] - 1) / a[i];
        }
        //cout << pd << " ";
        for(int j = 0; j < T[i]; j++){
            ll D = ((j + 1) * p + mod[i] - h[i] + a[i] - 1) / a[i];
            if(D <= pd){
                ans[pd + 1]++;
                pd++;
            }
            else{
                pd = D;
                ans[D]++;
            }
            //cout << pd << " ";
        }
    }
    for(int i = 0;i <= m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m + 1] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + MAXN, 0);
    fill(T, T + MAXN, 0);
    fill(mod, mod + MAXN, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q + p - 1) / p);
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i]);
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] > m)return 0;
    }
    if(cnt > m * k)return 0;
    for(int i = 0; i < n; i++){
        //if(mod[i] == 0)continue;
        ll pd = 0, Re = h[i], nd, nh;
        for(int j = 0; j < T[i]; j++){
            ll nd = (p - Re % p + a[i] - 1) / a[i] + pd;
            ll nh = nd * a[i] + H[i];
            if(j == 0){
                if(Re >= mod[i]){
                    nd = pd;
                    nh = Re;
                }
                else{
                    nd = (mod[i] - Re + a[i] - 1) / a[i];
                    nh = nd * a[i] + h[i];
                }
            }
            else if(Re >= (j + 1) * p){
                nd = pd;
                nh = Re;
            }
            ans[nd]++;
            Re = nh;
            pd = nd;
            if(pd >= m){
                return 0;
            }
        }
    }
    for(int i = 0;i < m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q) / p);
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] + (mod[i] != 0) > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        //if(mod[i] == 0)continue;
        ll pd = 0, Re = h[i], nd = 0, nh = 0;
        for(int j = 0; j < T[i]; j++){
            if(j == 0){
                if(Re >= mod[i]){
                    nd = pd;
                    nh = Re;
                }
                else{
                    nd = (mod[i] - Re + a[i] - 1) / a[i];
                    nh = nd * a[i] + h[i];
                }
            }
            else if(Re >= (j + 1) * p){
                nd = pd;
                nh = Re;
            }
            ans[nd]++;
            Re = nh;
            pd = nd;
            if(pd >= m){
                return 0;
            }
        }
    }
    for(int i = 0;i < m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + m, 0);
    fill(T, T + n, 0);
    fill(mod, mod + n, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q) / p);
            if(mod[i] == 0){
                T[i]--;
                mod[i] = p;
            }
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i] + (mod[i] != 0));
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] + (mod[i] != 0) > m)return 0;
    }
    if(cnt > m * k)return 0;
    fill(ans, ans + m, 0);
    for(int i = 0; i < n; i++){
        if(mod[i] == 0)continue;
        ll pd = -1;
        if(h[i] >= mod[i]){
            ans[0]++;
            pd = 0;
        }
        else{
            ans[(mod[i] - h[i] + a[i] - 1) / a[i]]++;
            pd = (mod[i] - h[i] + a[i] - 1) / a[i];
        }
        //cout << pd << " ";
        for(int j = 0; j < T[i]; j++){
            ll D = ((j + 1) * p + mod[i] - h[i] + a[i] - 1) / a[i];
            if(D <= pd){
                ans[pd + 1]++;
                pd++;
            }
            else{
                pd = D;
                ans[D]++;
            }
            //cout << pd << " ";
            if(pd > m)return 0;
        }
    }
    for(int i = 0;i <= m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    return (ans[m + 1] == 0);
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << max(MAX, up);
    return 0;
}


#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int n, m, k, p;

ll T[MAXN], a[MAXN], h[MAXN], ans[MAXN], mod[MAXN];

bool f(ll q){
    //cout << q << endl;
   // cout << q << endl;
    ll cnt = 0;
    fill(ans, ans + MAXN, 0);
    fill(T, T + MAXN, 0);
    fill(mod, mod + MAXN, 0);
    for(int i = 0; i < n; i++){
        //momkene inja bug bokhore!
        ll LAST = m * a[i] + h[i];
        if(LAST > q){
            mod[i] = (LAST - q) % p;
            T[i] = ((LAST - q + p - 1) / p);
        }
        else{
            T[i] = 0;
            mod[i] = 0;
        }
        cnt += (T[i]);
        //cout << LAST << " " << T[i] << " " << mod[i] << endl;
        if(T[i] > m)return 0;
    }
    if(cnt > m * k)return 0;
    for(int i = 0; i < n; i++){
        if(T[i] == 0)continue;
        ll pd = 0, Re = h[i];
        for(int j = 0; j < T[i]; j++){
            ll nd = (p - Re % p + a[i] - 1) / a[i] + pd , nh = nd * a[i] + h[i];
            if(j == 0){
                if(Re >= mod[i]){
                    nd = pd;
                    nh = Re;
                }
                else{
                    nd = (mod[i] - Re + a[i] - 1) / a[i];
                    nh = nd * a[i] + h[i];
                }
            }
            else if(Re >= (j + 1) * p){
                nd = pd;
                nh = Re;
            }
            Re = nh;
            pd = nd;
            ans[pd]++;
            if(pd >= m){
                return 0;
            }
        }
    }
    for(int i = 0;i < m; i++){
        //cout << ans[i] << " ";
        if(ans[i] > k){
            ans[i + 1] += (ans[i] - k);
        }
    }
    //cout << (ans[m - 1] <= k) << endl;
    //cout << endl;
    if(ans[m] == 1)return 1;
    return 0;
}

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    cin >> n >> m >> k >> p;
    ll MAX = 0;
    for(int i = 0; i < n ;i ++){
        cin >> h[i] >> a[i];
        MAX = max(MAX, a[i]);
    }
    ll d = -1, up = 1e15;
    while(up - d > 1){
        ll mid = (up + d) / 2;
        if(f(mid)){
            up = mid;
        }
        else{
            d = mid;
        }
    }
    cout << up;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id;
}node[200100];
int a[201000],M;
ll ans[201000];
ll cnt[1001000];
ll tc[2000100];
ll sum;
bool cmp(Node a,Node b){
    int x = a.l/M;
    int y = b.l/M;
    if(x != y) return x < y;
    else return a.r < b.r;
}
void Delete(int id){
    ll &c = cnt[a[id]];
    sum -= (tc[c]) * a[id];
    c--;
}
void Insert(int id){
    ll &c = cnt[a[id]];
    c++;
    sum += (tc[c]) * a[id];
}
int main(){
    int N,Q;
    for(int i = 0; i <= 1000000; i++)
        tc[i] = 2 * i - 1;
    cin>>N>>Q;
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
    }
    M = sqrt(N*1.0)+200;
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;

        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        //printf("%I64d\n",ans[i]);
        cout<<ans[i]<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id;
}node[200100];
int a[201000],M;
ll ans[201000];
ll cnt[10001000];
ll sum;
bool cmp(Node a,Node b){
    int x = a.l/M;
    int y = b.l/M;
    if(x != y) return x < y;
    else return a.r < b.r;
}
void Delete(int id){
    ll &c = cnt[a[id]];
    sum -= (c*c-(c-1)*(c-1)) * a[id];
    c--;
}
void Insert(int id){
    ll &c = cnt[a[id]];
    c++;
    sum += (c*c-(c-1)*(c-1)) * a[id];
}
int main(){
    int N,Q;
    cin>>N>>Q;
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
    }
    M = sqrt(N*1.0);
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;

        if(l > nr){
            sum = 0;
            nl = l;
            nr = l-1;
        }

        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        printf("%d\n",ans[i]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id;
}node[200100];
int a[201000],M;
ll ans[201000];
ll cnt[1001000];
ll tc[2000100];
ll sum;
bool cmp(Node a,Node b){
    int x = a.l/M;
    int y = b.l/M;
    if(x != y) return x < y;
    else return a.r < b.r;
}
void Delete(int id){
    ll &c = cnt[a[id]];
    sum -= (tc[c]) * a[id];
    c--;
}
void Insert(int id){
    ll &c = cnt[a[id]];
    c++;
    sum += (tc[c]) * a[id];
}
int main(){
    int N,Q;
    for(int i = 1; i <= 1000000; i++)
        tc[i] = 2 * i - 1;
    cin>>N>>Q;
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
    }
    M = sqrt(N*1.0)+200;
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;

        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        //printf("%I64d\n",ans[i]);
        cout<<ans[i]<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id;
}node[200100];
int a[201000],M;
ll ans[201000];
ll cnt[1001000];
ll tc[2000100];
ll sum;
bool cmp(Node a,Node b){
    int x = a.l/M;
    int y = b.l/M;
    if(x != y) return x < y;
    else return a.r < b.r;
}
void Delete(int id){
    ll &c = cnt[a[id]];
    sum -= (tc[c]) * a[id];
    c--;
}
void Insert(int id){
    ll &c = cnt[a[id]];
    c++;
    sum += (tc[c]) * a[id];
}
int main(){
    int N,Q;
    for(int i = 0; i <= 1000000; i++)
        tc[i] = 2 * i - 1;
    cin>>N>>Q;
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
    }
    M = 500;
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;
        if(l > nr ){
            for(int j = nl; j <= nr; j++) cnt[a[j]] = 0;
            nl = l;
            nr = l-1;
            sum = 0;
        }
        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        printf("%I64d\n",ans[i]);

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id;
}node[200100];
int a[201000],M;
ll ans[201000];
ll cnt[1001000];
ll tc[1000100];
ll sum;
bool cmp(Node a,Node b){
    int x = a.l/M;
    int y = b.l/M;
    if(x != y) return x < y;
    else return a.r < b.r;
}
void Delete(int id){
    ll &c = cnt[a[id]];
    sum -= (c*2-1) * a[id];
    c--;
}
void Insert(int id){
    ll &c = cnt[a[id]];
    c++;
    sum += (c*2-1) * a[id];
}
int main(){
    int N,Q;
    for(int i = 1; i <= 1000000; i++)
        tc[i] = 2 * i - 1;
    cin>>N>>Q;
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
    }
    M = sqrt(N*1.0)+200;
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;

        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        //printf("%I64d\n",ans[i]);
        cout<<ans[i]<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id;
}node[200100];
int a[201000],M;
ll ans[201000];
ll cnt[1001000];
ll tc[1000100];
ll sum;
bool cmp(Node a,Node b){
    int x = a.l/M;
    int y = b.l/M;
    if(x != y) return x < y;
    else return a.r < b.r;
}
void Delete(int id){
    ll &c = cnt[a[id]];
    sum -= tc[c] * a[id];
    c--;
}
void Insert(int id){
    ll &c = cnt[a[id]];
    c++;
    sum += tc[c] * a[id];
}
int main(){
    int N,Q;
    for(int i = 1; i <= 1000000; i++)
        tc[i] = 2 * i - 1;
    cin>>N>>Q;
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
    }
    M = sqrt(N*1.0)+200;
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;

        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        printf("%I64d\n",ans[i]);

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id,x;
}node[200100];
int M;
ll a[201000];
ll ans[201000];
int cnt[1001000];
ll sum;
bool cmp(Node a,Node b){
    if(a.x != b.x) return a.x < b.x;
    else return a.r < b.r;
}
void Delete(int id){
    sum -= (cnt[a[id]]*2 - 1) * a[id];
    cnt[a[id]]--;
}
void Insert(int id){
    cnt[a[id]] ++;
    sum += (cnt[a[id]]*2 - 1) * a[id];
}
int main(){
    int N,Q;
    cin>>N>>Q;
    M = sqrt(N*1.0);
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
        node[i].x = node[i].l/M;
    }
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;
        if(l > nr ){
            for(int j = nl; j <= nr; j++) cnt[a[j]] = 0;
            nl = l;
            nr = l-1;
            sum = 0;
        }
        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        printf("%I64d\n",ans[i]);

    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id;
}node[200100];
int a[201000],M;
ll ans[201000];
ll cnt[10001000];
ll sum;
bool cmp(Node a,Node b){
    int x = a.l/M;
    int y = b.l/M;
    if(x != y) return x < y;
    else return a.r < b.r;
}
void Delete(int id){
    ll &c = cnt[a[id]];
    sum -= (c*c-(c-1)*(c-1)) * a[id];
    c--;
}
void Insert(int id){
    ll &c = cnt[a[id]];
    c++;
    sum += (c*c-(c-1)*(c-1)) * a[id];
}
int main(){
    int N,Q;
    cin>>N>>Q;
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
    }
    M = sqrt(N*1.0)+100;
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;

        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        //printf("%I64d\n",ans[i]);
        cout<<ans[i]<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
struct Node{
    int l,r,id;
}node[200100];
int a[201000],M;
ll ans[201000];
ll cnt[1001000];
ll tc[1000100];
ll sum;
bool cmp(Node a,Node b){
    int x = a.l/M;
    int y = b.l/M;
    if(x != y) return x < y;
    else return a.r < b.r;
}
void Delete(int id){
    ll &c = cnt[a[id]];
    sum -= tc[c] * a[id];
    c--;
}
void Insert(int id){
    ll &c = cnt[a[id]];
    c++;
    sum += tc[c] * a[id];
}
int main(){
    int N,Q;
    for(int i = 1; i <= 1000000; i++)
        tc[i] = 2 * i - 1;
    cin>>N>>Q;
    for(int i = 1; i <= N; i++)
        scanf("%d",&a[i]);
    for(int i = 0; i < Q; i++){
        scanf("%d %d",&node[i].l,&node[i].r);
        node[i].id = i;
    }
    M = sqrt(N*1.0)+200;
    sort(node,node+Q,cmp);
    int nl =0, nr = 0;
    sum = 0;
    for(int i = 0 ;i < Q; i++){
        int l = node[i].l;
        int r = node[i].r;

        while(nl < l){
            if(nl) Delete(nl);
            nl++;
        }
        while(nl > l){
            nl--;
            Insert(nl);
        }
        while(nr < r){
            nr++;
            Insert(nr);
        }
        while(nr > r){
            Delete(nr);
            nr--;
        }
        ans[node[i].id] = sum;
    }
    for(int i = 0; i < Q; i++)
        //zprintf("%I64d\n",ans[i]);
        cout<<ans[i]<<endl;
    return 0;
}