#include <bits/stdc++.h>
using namespace std;
struct person {
  int s, a, b;
  bool operator<(const person &i) const { return abs(a - b) > abs(i.a - i.b); }
};
int n, s;
long long m;
person p[100010];
long long f(long long l1, long long l2) {
  long long res = 0;
  for (int i = 0; i < n; i++) {
    if (p[i].a > p[i].b) {
      if (p[i].s <= l1) {
        res += 1LL * p[i].a * p[i].s;
        l1 -= p[i].s;
      } else {
        res += 1LL * p[i].a * l1;
        res += 1LL * p[i].b * (p[i].s - l1);
        l2 -= p[i].s - l1;
        l1 = 0;
      }
    } else {
      if (p[i].s <= l2) {
        res += 1LL * p[i].b * p[i].s;
        l2 -= p[i].s;
      } else {
        res += 1LL * p[i].b * l2;
        res += 1LL * p[i].a * (p[i].s - l2);
        l1 -= p[i].s - l2;
        l2 = 0;
      }
    }
  }
  return res;
}
long long g(long long low, long long high) {
  if (low == high - 1)
    return max(f(low * s, (m - low) * s), f(high * s, (m - high) * s));
  if (low == high - 2)
    return max(
        max(f(low * s, (m - low) * s), f((low + 1) * s, (m - low - 1) * s)),
        f(high * s, (m - high) * s));
  long long diff = (high - low) / 3;
  long long val1 = f((low + diff) * s, (m - low - diff) * s);
  long long val2 = f((high - diff) * s, (m - high + diff) * s);
  if (val1 > val2)
    return g(low, high - diff - 1);
  else
    return g(low + diff + 1, high);
}
int main() {
  scanf("%d %d", &n, &s);
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d %d", &p[i].s, &p[i].a, &p[i].b);
    cnt += p[i].s;
  }
  m = (cnt + s - 1) / s;
  sort(p, p + n);
  printf("%lld\n", g(0, m));
  return 0;
}
