#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline _T sqr(const _T& x) {
  return x * x;
}
template <class _T>
inline string tostr(const _T& a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
const long double EPS = 1e-11;
char TEMPORARY_CHAR;
const long long INF = 1e10;
const int N = 1 << 16;
inline void input(int& a) {
  a = 0;
  while ((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') {
  }
  while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0') {
    a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0';
    TEMPORARY_CHAR = getchar();
  }
}
inline int nxt() {
  int(ret);
  input((ret));
  ;
  return ret;
}
int main() {
  int(n);
  input((n));
  ;
  int(m);
  input((m));
  ;
  long long ans = 0;
  for (int i = 0; i < (int)(n); i++) {
    int(t);
    input((t));
    ;
    int(T);
    input((T));
    ;
    int(u);
    input((u));
    ;
    int(cost);
    input((cost));
    ;
    int first = T - t;
    if (first <= 0) {
      ans += (long long)u * (long long)m + cost;
      continue;
    } else {
      int k = (m - 1) / first + 1;
      ans += min(cost + (long long)u * (long long)m,
                 (long long)k * (long long)cost);
    }
  }
  cout << ans;
  return 0;
}
