#include <bits/stdc++.h>
const double E = exp(1);
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  long long t, T, x, cost;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> t >> T >> x >> cost;
    long long tt = T - t;
    if (tt <= 0)
      ans += cost + x * m;
    else if (tt >= m)
      ans += cost;
    else {
      long long k = (m + tt - 1) / tt;
      long long res1 = cost * k;
      long long res2 = cost + x * m;
      ans += min(res1, res2);
    }
  }
  cout << ans << endl;
  return 0;
}
