#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct myst {
  long long cnt, a, b;
};
bool comp1(myst s1, myst s2) { return abs(s1.a - s1.b) > abs(s2.a - s2.b); }
int n, S;
vector<myst> x(N);
long long need;
long long get(long long cnt1) {
  long long ans = 0;
  long long cnt2 = need - cnt1;
  cnt1 *= (long long)S;
  cnt2 *= (long long)S;
  for (int i = 0; i < n; ++i) {
    if (x[i].a >= x[i].b) {
      if (cnt1 > 0) {
        if (cnt1 > x[i].cnt) {
          ans += x[i].cnt * x[i].a;
          cnt1 -= x[i].cnt;
        } else {
          ans += cnt1 * x[i].a;
          ans += (x[i].cnt - cnt1) * x[i].b;
          cnt2 -= (x[i].cnt - cnt1);
          cnt1 = 0;
        }
      } else {
        ans += x[i].cnt * x[i].b;
      }
    } else {
      if (x[i].a <= x[i].b) {
        if (cnt2 > 0) {
          if (cnt2 > x[i].cnt) {
            ans += x[i].cnt * x[i].b;
            cnt2 -= x[i].cnt;
          } else {
            ans += cnt2 * x[i].b;
            ans += (x[i].cnt - cnt2) * x[i].a;
            cnt1 -= (x[i].cnt - cnt2);
            cnt2 = 0;
          }
        } else {
          ans += x[i].cnt * x[i].a;
        }
      }
    }
  }
  return ans;
}
int main() {
  scanf("%d %d", &n, &S);
  long long sum = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%I64d %I64d %I64d", &x[i].cnt, &x[i].a, &x[i].b);
    sum += x[i].cnt;
  }
  need = (sum + (long long)S - 1LL) / (long long)S;
  sort(x.begin(), x.begin() + n, comp1);
  long long L = 0LL, R = need;
  while (L + 2 < R) {
    long long M1 = L + (R - L) / 3LL;
    long long M2 = R - (R - L) / 3LL;
    long long res1 = get(M1);
    long long res2 = get(M2);
    if (res1 < res2)
      L = M1;
    else
      R = M2;
  }
  long long ans = 0;
  for (long long i = L; i <= R; ++i) {
    ans = max(ans, get(i));
  }
  printf("%I64d", ans);
  return 0;
}
