#include <bits/stdc++.h>
int in() {
  int r = 0, c;
  for (c = getchar(); c <= 32; c = getchar())
    ;
  if (c == '-') return -in();
  for (; c > 32; r = (r << 1) + (r << 3) + c - '0', c = getchar())
    ;
  return r;
}
using namespace std;
const int INF = int(1e9 + 7);
int main() {
  long long res = 0;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    long long t, T, x, c;
    cin >> t >> T >> x >> c;
    long long ans = x * m + c;
    long long aux = ans;
    if (T > t) aux = (m + T - t - 1) / (T - t) * c;
    ans = min(ans, aux);
    res += ans;
  }
  cout << res << endl;
  return 0;
}
