#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, t, T, x, c, ans = 0;
  scanf("%lld %lld", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld %lld %lld", &t, &T, &x, &c);
    if (t >= T) {
      ans += x * m + c;
      continue;
    }
    long long limit = T - t, one = c;
    if (limit < m) one += x * m;
    long long cost = (m / limit + (m % limit > 0)) * c;
    ans += min(cost, one);
  }
  printf("%lld\n", ans);
  return 0;
}
