#include <bits/stdc++.h>
const int MAX = 1000000;
using namespace std;
long long ans = 0;
int N, M;
int t[MAX];
int T[MAX];
int x[MAX];
int cost[MAX];
int main(void) {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    scanf("%d %d %d %d", t + i, T + i, x + i, cost + i);
    int k = T[i] - t[i];
    if (M <= k) {
      ans += cost[i];
    } else {
      long long b1c = cost[i] + (long long)M * x[i];
      long long a = b1c;
      if (k > 0) {
        long long b2c = (M + k - 1) / k * (long long)cost[i];
        a = min(a, b2c);
      }
      ans += a;
    }
  }
  cout << ans;
  return 0;
}
