#include <bits/stdc++.h>
using namespace std;
int getint() {
  int ret = 0;
  bool ok = false;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + ret + ret + c - '0', ok = true;
    else if (ok)
      return ret;
  }
}
int n, M;
long long ans;
int main() {
  n = getint(), M = getint();
  for (int i = 1; i <= n; i++) {
    int t = getint(), T = getint(), x = getint(), cost = getint();
    long long C = cost + (t + M > T ? M : 0) * (long long)x;
    if (t + M <= T || T <= t) {
      ans += C;
      continue;
    }
    if (M % (T - t) == 0) {
      C = min(C, (long long)cost * (M / (T - t)));
      ans += C;
      continue;
    }
    C = min(C, (long long)cost * (M / (T - t)) +
                   (long long)x * (M % (T - t) + T - t));
    C = min(C, (long long)cost * (M / (T - t) + 1));
    ans += C;
  }
  printf("%I64d\n", ans);
  return 0;
}
