#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, s;
struct contestant {
  long long v, a, b, dif;
};
contestant c[maxn];
vector<contestant> va, vb;
int cmpg(contestant x, contestant y) { return x.dif < y.dif; }
int cmpl(contestant x, contestant y) { return x.dif > y.dif; }
long long f(long long x, long long y) {
  long long na = x * s, nb = y * s;
  long long res = 0;
  for (int i = 0; i < va.size(); i++) {
    if (na >= va[i].v) {
      na -= va[i].v;
      res += va[i].v * va[i].a;
    } else if (na != 0) {
      res += na * va[i].a;
      res += (va[i].v - na) * va[i].b;
      na = 0;
    } else {
      res += va[i].v * va[i].b;
    }
  }
  for (int i = 0; i < vb.size(); i++) {
    if (nb >= vb[i].v) {
      nb -= vb[i].v;
      res += vb[i].v * vb[i].b;
    } else if (nb != 0) {
      res += nb * vb[i].b;
      res += (vb[i].v - nb) * vb[i].a;
      nb = 0;
    } else {
      res += vb[i].v * vb[i].a;
    }
  }
  return res;
}
long long solve() {
  sort(va.begin(), va.end(), cmpg);
  sort(vb.begin(), vb.end(), cmpl);
  double sum = 0;
  for (int i = 1; i <= n; i++) sum += c[i].v;
  long long tot = ceil(sum / s);
  long long ans = f(tot, 0), l = 0, r = tot;
  while (l < r) {
    long long mid = (l + r) >> 1;
    long long fmid = f(mid, tot - mid);
    long long fmid1 = f(mid + 1, tot - mid - 1);
    if (fmid >= fmid1)
      r = mid, ans = max(ans, fmid);
    else
      l = mid + 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    cin >> c[i].v >> c[i].a >> c[i].b;
    c[i].dif = c[i].b - c[i].a;
    if (c[i].dif < 0)
      va.push_back(c[i]);
    else
      vb.push_back(c[i]);
  }
  cout << solve() << endl;
  return 0;
}
