#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, tc, tl, sc, bsc, mxstud, bsnum;
  long long totalcost = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> tc >> tl >> sc >> bsc;
    if (tl <= tc) {
      totalcost += bsc + m * sc;
      continue;
    }
    mxstud = (tl - tc);
    bsnum = (m + mxstud - 1) / mxstud;
    if (bsnum * bsc < bsc + m * sc)
      totalcost += bsnum * bsc;
    else
      totalcost += bsc + m * sc;
  }
  cout << totalcost << endl;
  return 0;
}
