#include <bits/stdc++.h>
int prime[1000000 + 5], in;
bool isp[1000000 + 5];
using namespace std;
int d4[] = {-1, 0, 1, 0};
int y4[] = {0, -1, 0, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
int dy[] = {1, -1, 1, -1, 0, 0, -1, 1};
int dxh[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dyh[] = {2, 2, -2, -2, 1, -1, 1, -1};
int mat[1005][1005], val[1005][1005];
void reset() {
  for (int i = 0; i < 1005; i++) {
    memset(mat[i], 0, sizeof(mat[i]));
    memset(val[i], 0, sizeof(val[i]));
  }
}
int main() {
  long long n, m;
  while (cin >> n >> m) {
    long long res = 0;
    for (int i = 0; i < n; i++) {
      long long t, T, x, c;
      cin >> t >> T >> x >> c;
      if (t >= T)
        res += (m * x + c);
      else {
        long long tm = T - t;
        long long re = (tm + m - 1) / tm;
        re = re * c;
        res += min(re, m * x + c);
      }
    }
    cout << res << endl;
  }
  return 0;
}
