Mr. Kitayuta's garden is planted with n bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the i-th bamboo is hi meters, and it grows ai meters at the end of each day. 

Actually, Mr. Kitayuta hates these bamboos. He once attempted to cut them down, but failed because their stems are too hard. Mr. Kitayuta have not given up, however. He has crafted Magical Hammer with his intelligence to drive them into the ground.

He can use Magical Hammer at most k times during each day, due to his limited Magic Power. Each time he beat a bamboo with Magical Hammer, its height decreases by p meters. If the height would become negative by this change, it will become 0 meters instead (it does not disappear). In other words, if a bamboo whose height is h meters is beaten with Magical Hammer, its new height will be max(0, h - p) meters. It is possible to beat the same bamboo more than once in a day.

Mr. Kitayuta will fight the bamboos for m days, starting today. His purpose is to minimize the height of the tallest bamboo after m days (that is, m iterations of "Mr. Kitayuta beats the bamboos and then they grow"). Find the lowest possible height of the tallest bamboo after m days.

Input

The first line of the input contains four space-separated integers n, m, k and p (1 ≤ n ≤ 105, 1 ≤ m ≤ 5000, 1 ≤ k ≤ 10, 1 ≤ p ≤ 109). They represent the number of the bamboos in Mr. Kitayuta's garden, the duration of Mr. Kitayuta's fight in days, the maximum number of times that Mr. Kitayuta beat the bamboos during each day, and the power of Magic Hammer, respectively.

The following n lines describe the properties of the bamboos. The i-th of them (1 ≤ i ≤ n) contains two space-separated integers hi and ai (0 ≤ hi ≤ 109, 1 ≤ ai ≤ 109), denoting the initial height and the growth rate of the i-th bamboo, respectively.

Output

Print the lowest possible height of the tallest bamboo after m days.

Examples

Input

3 1 2 5
10 10
10 10
15 2


Output

17


Input

2 10 10 1000000000
0 10
0 10


Output

10


Input

5 3 3 10
9 5
9 2
4 7
9 10
3 8


Output

14
#include <bits/stdc++.h>
#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 long long N = 2e5 + 100, OO = 1e9 + 7, T = 22, M = 1e9 + 7, P = 6151,
                SQ = 1300, lg = 22;
long long h[N], a[N], f[N], n, m, k, p, ct[N], mx = 0;
bool check(long long x) {
  long long cnt = 0;
  for (long long i = 1; i <= n; i++) {
    if (x >= f[i]) continue;
    cnt += (f[i] - x + p - 1) / p;
  }
  for (long long i = 0; i <= m + 1; i++) ct[i] = 0;
  if (cnt > k * (m + 1)) return false;
  for (long long i = 1; i <= n; i++) {
    if (x >= f[i]) continue;
    long long val = (f[i] - x + p - 1) / p;
    long long pos = 0, cnt = h[i];
    while (val && pos <= m) {
      if (cnt >= p) {
        val--;
        cnt -= p;
        continue;
      }
      long long g = (p - cnt + a[i] - 1) / a[i];
      if (g + pos > m) {
        cnt += (m - pos) * a[i];
        if (val > 1 || max((long long)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 (long long i = 1; i <= m + 1; i++) {
    ct[i] += ct[i - 1];
    if (i * k < ct[i]) return false;
  }
  return true;
}
int32_t main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m >> k >> p;
  for (long long i = 1; i <= n; i++)
    cin >> h[i] >> a[i], f[i] = h[i] + a[i] * m, mx = max(mx, f[i]);
  m--;
  long long l = 0, r = mx;
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid + 1;
  }
  cout << r << endl;
  return 0;
}
