#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int t[N], T[N], x[N], c[N];
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> t[i] >> T[i] >> x[i] >> c[i];
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int tem = T[i] - t[i];
    if (tem >= m)
      ans += c[i];
    else {
      if (tem <= 0)
        ans = ans + c[i] + 1LL * x[i] * m;
      else {
        int t1 = m % tem ? m / tem + 1 : m / tem;
        ans = ans + min(c[i] + 1LL * x[i] * m, 1LL * c[i] * t1);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
