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