#include <bits/stdc++.h>
using namespace std;
vector<long long> divisores(long long m) {
  set<long long> d;
  for (long long i = 1; i * i <= m; i++) {
    if (m % i == 0) {
      d.insert(i);
      d.insert(m / i);
    }
  }
  vector<long long> res;
  for (auto i : d) res.push_back(i);
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, m;
  cin >> n >> m;
  auto d = divisores(m);
  long long res = 0;
  for (int i = 0; i < n; i++) {
    long long t, T, x, cost;
    cin >> t >> T >> x >> cost;
    long long minCost = (1LL << 62);
    for (const auto buses : d) {
      long long kosto = buses * cost;
      long long temp = m / buses + t;
      if (temp > T) {
        kosto += x * m;
      }
      minCost = min(minCost, kosto);
    }
    if (T > t) {
      long long maxChicos = T - t;
      long long buses = (m + maxChicos - 1) / maxChicos;
      long long kosto = buses * cost;
      minCost = min(minCost, kosto);
    }
    res += minCost;
  }
  cout << res << endl;
  return 0;
}
