#include <bits/stdc++.h>
using namespace std;
void problem() {
  long long n, m, t, T, x, cost, nbuses, mini, maxi, temp;
  long long total = 0;
  cin >> n >> m;
  while (n--) {
    cin >> t >> T >> x >> cost;
    if (T >= (t + m)) {
      total += cost;
    } else {
      mini = cost + (m * x);
      if (T - t <= 0) {
        temp = mini;
      } else {
        if (m % (T - t) > 0) {
          maxi = min(cost * ((m / (T - t)) + 1),
                     cost * (m / (T - t)) + x * ((m % (T - t)) + (T - t)));
        } else {
          maxi = cost * ((m / (T - t)));
        }
        temp = min(maxi, mini);
      }
      total += temp;
    }
  }
  cout << total;
}
int main() { problem(); }
