#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAX = LONG_LONG_MAX, MIN = LONG_LONG_MIN;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
long long mod(long long n) {
  while (n < 0) n += MOD;
  return n % MOD;
}
const long long N = 5e5 + 20;
vector<pair<long long, long long> > p;
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  long long n, h;
  cin >> n >> h;
  long long sum = 0, res = 0;
  for (long long i = 0; i < n; i++) {
    long long s, a, b;
    cin >> s >> a >> b;
    sum += s;
    res += s * a;
    p.push_back(make_pair(b - a, s));
  }
  if (sum % h) p.push_back(make_pair(0, h - (sum % h)));
  sort(p.begin(), p.end());
  long long ans = 0, remain = 0, happy = 0;
  for (long long i = p.size() - 1; i >= 0; i--) {
    long long slices = p[i].second, point = p[i].first;
    if (remain + slices >= h)
      ans = max(ans, max(happy + point * (h - remain),
                         happy + point * ((remain + slices) / h * h - remain)));
    happy += point * slices;
    remain += slices;
    remain %= h;
  }
  cout << res + ans << "\n";
  return 0;
}
