#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 100010;
int t[maxn], T[maxn], x[maxn], cost[maxn];
int n, m;
long long calc(int i, int cnt) {
  long long res = (long long)cost[i] * cnt;
  long long tm = m;
  long long p = T[i] - t[i];
  tm -= p * (cnt - 1);
  if (tm > p) res += x[i] * tm;
  return res;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d%d%d%d", &t[i], &T[i], &x[i], &cost[i]);
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    if (T[i] - t[i] <= 0) {
      ans += cost[i] + x[i] * (long long)m;
    } else {
      int l = 1;
      int r = m;
      while (r - l >= 3) {
        int m1 = l + (r - l) / 3;
        int m2 = r - (r - l) / 3;
        long long v1 = calc(i, m1);
        long long v2 = calc(i, m2);
        if (v1 < v2)
          r = m2;
        else
          l = m1;
      }
      long long best = calc(i, 1);
      int p = (T[i] - t[i]);
      best = min(best, calc(i, (m + p - 1) / p));
      for (int j = l; j <= r; ++j) best = min(best, calc(i, j));
      ans += best;
    }
  }
  cout << ans << endl;
  return 0;
}
