#include <bits/stdc++.h>
using namespace std;
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= 1000000; p++) {
    if (prime[p] == true) {
      for (long long i = p * 2; i <= 1000000; i += p) prime[i] = false;
    }
  }
}
int gcd(int x, int y) {
  if (x == 0) {
    return y;
  } else
    return gcd(x % y, y);
}
struct vect {
  struct vect *foll;
  long long val;
  struct vect *succ;
};
void upd(struct vect **beg, struct vect **end, long long xd) {
  struct vect *c = (struct vect *)malloc(sizeof(struct vect));
  c->val = xd;
  c->succ = NULL;
  if (*beg == NULL) {
    c->foll = NULL;
    *beg = c;
    *end = c;
    return;
  }
  (*end)->succ = c;
  c->foll = *end;
  *end = c;
}
void change(struct vect **beg, struct vect **end) {
  if (*beg == *end) {
    return;
  }
  (*end)->succ = *beg;
  (*beg)->foll = *end;
  *beg = *end;
  *end = (*end)->foll;
  (*end)->succ = NULL;
  (*beg)->foll = NULL;
}
vector<pair<long long, pair<long long, long long> > > arr;
bool cmp(pair<long long, pair<long long, long long> > &drl,
         pair<long long, pair<long long, long long> > &drr) {
  return (drl.second.first - drl.second.second) <
         (drr.second.first - drr.second.second);
}
long long solve(long long xx, long long yy, long long asd) {
  long long ptr = 0, ans = 0;
  for (ptr = 0; ptr < arr.size(); ptr++) {
    if (arr[ptr].second.second >= arr[ptr].second.first) {
      if (yy >= arr[ptr].first) {
        ans += arr[ptr].first * arr[ptr].second.second;
        yy -= arr[ptr].first;
      } else {
        ans += yy * arr[ptr].second.second +
               (arr[ptr].first - yy) * arr[ptr].second.first;
        xx -= arr[ptr].first - yy;
        yy = 0;
      }
      asd -= arr[ptr].first;
    } else {
      break;
    }
  }
  long long j = ptr;
  for (ptr = arr.size() - 1; ptr >= 0; ptr--) {
    if (asd == 0) break;
    if (xx >= arr[ptr].first) {
      ans += arr[ptr].first * arr[ptr].second.first;
      xx -= arr[ptr].first;
    } else {
      ans += xx * arr[ptr].second.first +
             (arr[ptr].first - xx) * arr[ptr].second.second;
      yy -= arr[ptr].first - xx;
      xx = 0;
    }
    asd -= arr[ptr].first;
  }
  return ans;
}
int main() {
  long long n, s, pr, asd = 0;
  long long ans = 0;
  scanf("%lld", &n);
  scanf("%lld", &s);
  arr.resize(n);
  for (auto &ptr : arr) {
    scanf("%lld", &ptr.first);
    scanf("%lld", &ptr.second.first);
    scanf("%lld", &ptr.second.second);
    asd += ptr.first;
  }
  sort(arr.begin(), arr.end(), cmp);
  pr = (asd / s) + ((asd % s) ? 1 : 0);
  ans = solve(0LL, s * pr, asd);
  long long beg = 1;
  long long lt = pr;
  long long dd;
  while (beg <= lt) {
    dd = (beg + lt) >> 1;
    long long org = solve(dd * s, (pr - dd) * s, asd);
    long long last = solve((dd - 1) * s, (pr - dd + 1) * s, asd);
    ans = max(ans, org);
    if (org > last)
      beg = dd + 1;
    else
      lt = dd - 1;
  }
  printf("%lld", ans);
  return 0;
}
