#include <bits/stdc++.h>
using namespace std;
bool cmp(tuple<int, int, int> a, tuple<int, int, int> b) {
  int x = get<1>(a) - get<2>(a);
  int y = get<1>(b) - get<2>(b);
  return (x > y);
}
long long f(long long a, long long b) { return (a + b - 1) / b; }
int main() {
  int n, S;
  cin >> n >> S;
  vector<tuple<int, int, int> > x;
  x.resize(n);
  for (int i = 0; i < n; ++i) {
    int s, a, b;
    cin >> s >> a >> b;
    x[i] = make_tuple(s, a, b);
  }
  sort(x.begin(), x.end(), cmp);
  long long sa = 0, sb = 0;
  for (int i = 0; i < n; ++i) {
    int s = get<0>(x[i]);
    int a = get<1>(x[i]);
    int b = get<2>(x[i]);
    if (a > b) {
      sa += s;
    } else {
      sb += s;
    }
  }
  long long k = f(sa + sb, S);
  if (f(sa, S) + f(sb, S) == k) {
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
      int s = get<0>(x[i]);
      int a = get<1>(x[i]);
      int b = get<2>(x[i]);
      ans += 1LL * s * max(a, b);
    }
    cout << ans << endl;
    return 0;
  }
  long long answer = 0;
  long long pa = sa - f(sa, S) * S + S;
  int j = n;
  for (int i = 0; i < n; ++i) {
    if (get<1>(x[i]) <= get<2>(x[i])) {
      j = i;
      break;
    }
  }
  long long sum = 0;
  k = 0;
  for (int i = j - 1; i >= 0; --i) {
    int s = get<0>(x[i]);
    int a = get<1>(x[i]);
    int b = get<2>(x[i]);
    sum += s;
    if (sum >= pa) {
      long long z = sum - pa;
      long long value = (s - z) * 1LL * b + z * 1LL * a + k;
      for (int p = 0; p < i; ++p) value += get<0>(x[p]) * 1LL * get<1>(x[p]);
      for (int p = j; p < n; ++p) value += get<0>(x[p]) * 1LL * get<2>(x[p]);
      answer = max(answer, value);
      break;
    }
    k += s * 1LL * b;
  }
  long long pb = sb - f(sb, S) * S + S;
  sum = 0;
  k = 0;
  for (int i = j; i < n; ++i) {
    int s = get<0>(x[i]);
    int a = get<1>(x[i]);
    int b = get<2>(x[i]);
    sum += s;
    if (sum >= pb) {
      long long z = sum - pb;
      long long value = (s - z) * 1LL * a + z * 1LL * b + k;
      for (int p = 0; p < j; ++p) value += get<0>(x[p]) * 1LL * get<1>(x[p]);
      for (int p = i + 1; p < n; ++p)
        value += get<0>(x[p]) * 1LL * get<2>(x[p]);
      answer = max(answer, value);
      break;
    }
    k += s * 1LL * a;
  }
  cout << answer << endl;
  return 0;
}
