#include <bits/stdc++.h>
using namespace std;
long long n, s;
long long p;
vector<long long> a, b, k;
long long f(long long x) {
  if (x < 0) return -1;
  long long ans = 0;
  long long y = p - x;
  x *= s;
  y *= s;
  for (long long i = 0; i < n; ++i) {
    long long t = k[i];
    if (a[i] > b[i]) {
      long long d = min(t, x);
      ans += d * a[i];
      x -= d;
      t -= d;
      ans += t * b[i];
      y -= t;
    } else {
      long long d = min(t, y);
      ans += d * b[i];
      y -= d;
      t -= d;
      ans += t * a[i];
      x -= t;
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> s;
  a.resize(n);
  b.resize(n);
  k.resize(n);
  long long c = 0;
  vector<pair<int, pair<int, int> > > v(n);
  vector<int> a1(n), k1(n), b1(n);
  for (long long i = 0; i < n; ++i) {
    cin >> k[i] >> a[i] >> b[i];
    a1[i] = a[i];
    b1[i] = b[i];
    k1[i] = k[i];
    v[i] = {abs(b[i] - a[i]), {max(a[i], b[i]), i}};
    c += k[i];
  }
  sort(v.rbegin(), v.rend());
  for (int i = 0; i < n; ++i) {
    k[i] = k1[v[i].second.second];
    a[i] = a1[v[i].second.second];
    b[i] = b1[v[i].second.second];
  }
  for (int i = 0; i < n; ++i) {
  }
  p = ceil(1.0 * c / s);
  long long l = -1, r = p + 1, EPS = 1;
  while (r - l >= EPS) {
    long long m1 = l + (r - l) / 3, m2 = r - (r - l) / 3;
    if (f(m1) < f(m2)) {
      l = m1 + 1;
    } else
      r = m2 - 1;
  }
  cout << max(f(l), f(r));
  return 0;
}
