#include <bits/stdc++.h>
using namespace std;
const int max_n = 100010;
long long n, m;
long long cp[max_n], x[max_n], cs[max_n];
long long res;
long long clg(long long a, long long b) {
  return ((a / b) + ((a % b == 0) ? 0 : 1));
}
int main() {
  cin >> n >> m;
  int ct, cT, cx, ccs;
  res = 0;
  for (long long i = 0; i < n; ++i) {
    scanf("%d %d %d %d", &ct, &cT, &cx, &ccs);
    cp[i] = ((long long)(cT - ct));
    x[i] = ((long long)(cx));
    cs[i] = ((long long)(ccs));
    if (cp[i] <= 0) {
      res += (cs[i] + m * x[i]);
    } else
      res += min(cs[i] + m * x[i], clg(m, cp[i]) * cs[i]);
  }
  cout << res << endl;
}
