#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  long long T, cost, t, x;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> t >> T >> x >> cost;
    if (T <= t) {
      ans += cost + m * x;
    } else {
      if (m <= T - t) {
        ans += cost;
        continue;
      }
      long long temp;
      if (m % (T - t))
        temp = m / (T - t) + 1;
      else
        temp = m / (T - t);
      ans += min(m * x + cost, temp * cost);
    }
  }
  cout << ans << endl;
  return 0;
}
