#include <bits/stdc++.h>
using namespace std;
const int Size = 1024;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 15;
struct node {
  long long num, v1, v2;
} a[maxn];
bool cmp(node a, node b) { return a.v1 - a.v2 > b.v1 - b.v2; }
long long k, n, s;
long long check(long long p) {
  long long tot1 = p * s;
  long long tot2 = (k - p) * s;
  long long cnt = 0, i, j;
  for (i = 1; n >= i; i++) {
    if (a[i].v1 < a[i].v2) break;
    if (tot1 >= a[i].num) {
      tot1 -= a[i].num;
      cnt += a[i].num * a[i].v1;
    } else {
      cnt += tot1 * a[i].v1;
      cnt += (a[i].num - tot1) * a[i].v2;
      tot2 -= a[i].num - tot1;
      tot1 = 0;
      i++;
      break;
    }
  }
  for (j = n; j >= i; j--) {
    if (a[j].v1 > a[j].v2) break;
    if (tot2 >= a[j].num) {
      tot2 -= a[j].num;
      cnt += a[j].num * a[j].v2;
    } else {
      cnt += tot2 * a[j].v2;
      cnt += (a[j].num - tot2) * a[j].v1;
      tot1 -= a[j].num - tot2;
      tot2 = 0;
      j--;
      break;
    }
  }
  for (; j >= i; i++) {
    if (tot1 >= a[i].num) {
      tot1 -= a[i].num;
      cnt += a[i].num * a[i].v1;
    } else {
      cnt += tot1 * a[i].v1;
      cnt += (a[i].num - tot1) * a[i].v2;
      tot2 -= a[i].num - tot1;
      tot1 = 0;
      i++;
      break;
    }
  }
  for (; j >= i; j--) {
    if (tot2 >= a[j].num) {
      tot2 -= a[j].num;
      cnt += a[j].num * a[j].v2;
    } else {
      cnt += tot2 * a[j].v2;
      cnt += (a[j].num - tot2) * a[j].v1;
      tot1 -= a[j].num - tot2;
      tot2 = 0;
      j--;
      break;
    }
  }
  return cnt;
}
int main() {
  long long tot = 0;
  scanf("%lld%lld", &n, &s);
  for (long long i = 1; n >= i; i++) {
    scanf("%lld%lld%lld", &a[i].num, &a[i].v1, &a[i].v2);
    tot += a[i].num;
  }
  k = tot / s + (tot % s != 0);
  sort(a + 1, a + n + 1, cmp);
  long long l = 0, r = k;
  long long ans = 0;
  ans = max(ans, max(check(l), check(r)));
  while (l + 1 < r) {
    long long mid = (l + r) >> 1;
    long long mmid = (mid + r) >> 1;
    if (check(mid) >= check(mmid))
      r = mmid;
    else
      l = mid;
    ans = max(ans, max(check(mid), check(mmid)));
  }
  printf("%lld\n", ans);
  return 0;
}
