#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const int MAXN = 1e6 + 5;
const int mod = 1e9 + 7;
struct nodes {
  int s, a, b;
  bool operator<(const nodes& x) const { return a - b > x.a - x.b; }
} nd[MAXN];
long long totnum;
int n, S;
long long suf[MAXN];
long long calc(long long n) {
  long long ans = 0;
  long long n1 = n * S, n2 = (totnum - n) * S;
  for (int i = 1; i <= ::n; i++) {
    if (nd[i].b >= nd[i].a && suf[i] > n2 && suf[i] - n2 <= nd[i].s) {
      ans += (long long)nd[i].a * (suf[i] - n2);
      ans += (long long)nd[i].b * (nd[i].s - suf[i] + n2);
      n1 -= suf[i] - n2;
      n2 -= (nd[i].s - suf[i] + n2);
    } else if (nd[i].b >= nd[i].a && suf[i] <= n2) {
      n2 -= nd[i].s;
      ans += (long long)nd[i].b * nd[i].s;
    } else if (n1) {
      if (n1 < nd[i].s) {
        ans += (long long)nd[i].b * (nd[i].s - n1);
        ans += (long long)nd[i].a * n1;
        n2 -= nd[i].s - n1;
        n1 = 0;
      } else {
        ans += (long long)nd[i].a * nd[i].s;
        n1 -= nd[i].s;
      }
    } else {
      ans += (long long)nd[i].b * nd[i].s;
      n2 -= nd[i].s;
    }
  }
  return ans;
}
long long solve(long long l, long long r) {
  while (l < r) {
    long long m1 = floor(1.0 * (2 * l + r) / 3),
              m2 = floor(1.0 * (l + 2 * r + 2) / 3);
    if (calc(m1) < calc(m2))
      l = m1 + 1;
    else
      r = m2 - 1;
  }
  long long vl = calc(l), vr = calc(r);
  return max(vl, vr);
}
int main() {
  scanf("%d %d", &n, &S);
  long long tot = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d %d", &nd[i].s, &nd[i].a, &nd[i].b);
    tot += nd[i].s;
  }
  sort(nd + 1, nd + 1 + n);
  for (int i = n; i >= 1; i--) suf[i] = nd[i].s + suf[i + 1];
  totnum = (tot + S - 1) / S;
  long long l = 0, r = totnum;
  printf("%lld\n", solve(l, r));
  return 0;
}
