#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5, mod = 31, bit = 60;
long long int n, S, s[N], a[N], b[N], have = 0;
vector<pair<long long int, long long int> > v;
long long int solve(long long int fb) {
  fb *= S;
  long long int ans = have;
  for (auto u : v) {
    long long int take = min(u.second, fb);
    fb -= take;
    long long int change = u.first;
    ans += (take * change);
  }
  return ans;
}
void ternary(long long int l, long long int r) {
  long long int ans = have;
  long long int mid1, mid2;
  while (l <= r) {
    long long int x = (r - l) / 3;
    mid1 = (l + x);
    mid2 = r - x;
    long long int a1 = solve(mid1);
    long long int a2 = solve(mid2);
    if (a1 < a2) {
      ans = max(ans, a2);
      l = mid1 + 1;
    } else {
      ans = max(ans, a1);
      r = mid2 - 1;
    }
  }
  cout << ans << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  cin >> n >> S;
  long long int i, req = 0;
  for (i = 0; i < n; i++) {
    cin >> s[i] >> a[i] >> b[i];
    pair<long long int, long long int> p = {b[i] - a[i], s[i]};
    v.push_back(p);
    req += s[i];
    have += (a[i] * s[i]);
  }
  long long int total = (req + S - 1) / S;
  v.push_back({0, total * S - req});
  sort(v.begin(), v.end(), greater<pair<long long int, long long int> >());
  ternary(0, total);
  return 0;
}
