#include <bits/stdc++.h>
using namespace std;
ifstream fin("input.txt");
const long long inf = 1e15;
int main() {
  long long n, m, ans = 0, i;
  cin >> n >> m;
  for (i = 0; i < n; i++) {
    long long t, T, x, cost;
    long long ans1, ans2;
    cin >> t >> T >> x >> cost;
    if (t + m > T)
      ans1 = cost + m * x;
    else
      ans1 = cost;
    if (t >= T)
      ans2 = inf;
    else {
      long long num = (T - t);
      if (m % num == 0)
        ans2 = cost * (m / num);
      else
        ans2 = cost * (m / num + 1);
    }
    ans += min(ans1, ans2);
  }
  cout << ans;
  return 0;
}
