#include <bits/stdc++.h>
using namespace std;
long long mx1, mx2, m, mx;
long long a, b, c, d, e, f;
long long fu(long long x) {
  long long l, ll = m - (x - 1) * e;
  if (ll <= e) ll = 0;
  l = x * d + ll * c;
  return l;
}
void bs(int low, int high) {
  while (low < high) {
    int mid = (low + high) / 2;
    long long l = fu(mid);
    long long x = fu(low);
    long long y = fu(high);
    mx = min(mx, l);
    high = mid - 1;
    low = mid + 1;
  }
}
int main() {
  long long n, i, j, k = 0;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> a >> b >> c >> d;
    e = b - a;
    if (e <= 0) {
      k += d + m * c;
      continue;
    }
    if (e >= m) {
      k += d;
      continue;
    }
    f = ceil(double(m) / double(e));
    mx1 = fu(1);
    mx2 = fu(f);
    mx = min(mx1, mx2);
    k += mx;
  }
  cout << k << endl;
  return 0;
}
