#include <bits/stdc++.h>
using namespace std;
int n, k;
long long t, T, x, cost;
long long res_cost;
const double eps = 1e-6;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    cin >> t >> T >> x >> cost;
    if (t + k <= T) {
      res_cost += cost;
    } else {
      long long pInB = T - t;
      if (pInB <= 0)
        res_cost += x * k + cost;
      else {
        long long bA = ceil(k / (double)pInB);
        long long cur_cost = min(bA * cost, x * k + cost);
        res_cost += cur_cost;
      }
    }
  }
  cout << res_cost;
  return 0;
}
