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