#include <bits/stdc++.h>
using namespace std;
ifstream Cin("input.txt");
ofstream Cout("output.txt");
int main() {
  long long n, m, i, ans = 0, curans, t, T, x, cost;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    cin >> t >> T >> x >> cost;
    if (t >= T)
      curans = cost + x * m;
    else if (t < T) {
      if (t + m <= T)
        curans = cost;
      else {
        long long numbus = (m - 1) / (T - t) + 1;
        curans = min(m * x + cost, numbus * cost);
      }
    }
    ans += curans;
  }
  cout << ans;
}
