#include <bits/stdc++.h>
using namespace std;
long long t[100005], T[100005], x[100005], c[100005];
long long n, m;
int main() {
  while (scanf("%lld%lld", &n, &m) != EOF) {
    int i;
    int a, b;
    long long sum = 0;
    for (i = 1; i <= n; i++)
      scanf("%lld%lld%lld%lld", &t[i], &T[i], &x[i], &c[i]);
    for (i = 1; i <= n; i++) {
      if (t[i] >= T[i]) {
        sum += (c[i] + x[i] * m);
      } else {
        if (t[i] + m <= T[i])
          sum += c[i];
        else {
          long long a, b;
          long long cha = T[i] - t[i];
          long long d = m % (T[i] - t[i]);
          long long w = m / (T[i] - t[i]);
          if (d)
            a = (w + 1) * c[i];
          else
            a = (w * c[i]);
          b = x[i] * m + c[i];
          sum += min(a, b);
        }
      }
    }
    printf("%I64d\n", sum);
  }
}
