#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cout << *it << " = " << a << endl;
  err(++it, args...);
}
struct region {
  long long t, T, x, cost;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  region r[n];
  for (int i = 0; i < n; i++) {
    cin >> r[i].t >> r[i].T >> r[i].x >> r[i].cost;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (r[i].t >= r[i].T)
      ans += r[i].cost + r[i].x * m;
    else {
      if (r[i].t + m <= r[i].T)
        ans += r[i].cost;
      else {
        long long buses = ceil(double(m) / (r[i].T - r[i].t));
        ans += min(r[i].cost + m * r[i].x, r[i].cost * buses);
      }
    }
  }
  cout << ans;
  return 0;
}
