#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, pair<long long, long long> > > v;
bool comp(pair<long long, pair<long long, long long> > &lhs,
          pair<long long, pair<long long, long long> > &rhs) {
  return (lhs.second.first - lhs.second.second) <
         (rhs.second.first - rhs.second.second);
}
long long calchp(long long a, long long b, long long sum) {
  long long i = 0, maxhp = 0;
  for (i = 0; i < v.size(); i++) {
    if (v[i].second.second >= v[i].second.first) {
      if (b >= v[i].first) {
        maxhp += v[i].first * v[i].second.second;
        b -= v[i].first;
      } else {
        maxhp += b * v[i].second.second + (v[i].first - b) * v[i].second.first;
        a -= v[i].first - b;
        b = 0;
      }
      sum -= v[i].first;
    } else {
      break;
    }
  }
  long long j = i;
  for (i = v.size() - 1; i >= 0; i--) {
    if (sum == 0) break;
    if (a >= v[i].first) {
      maxhp += v[i].first * v[i].second.first;
      a -= v[i].first;
    } else {
      maxhp += a * v[i].second.first + (v[i].first - a) * v[i].second.second;
      b -= v[i].first - a;
      a = 0;
    }
    sum -= v[i].first;
  }
  assert(j == i + 1);
  return maxhp;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, s, nop, sum = 0;
  long long maxhp = 0;
  cin >> n >> s;
  v.resize(n);
  for (auto &i : v) {
    cin >> i.first >> i.second.first >> i.second.second;
    sum += i.first;
  }
  sort(v.begin(), v.end(), comp);
  nop = (sum / s) + ((sum % s) ? 1 : 0);
  maxhp = calchp(0, s * nop, sum);
  long long start = 1, end = nop, mid;
  while (start <= end) {
    mid = (start + end) / 2;
    long long curr = calchp(mid * s, (nop - mid) * s, sum);
    long long prev = calchp((mid - 1) * s, (nop - mid + 1) * s, sum);
    maxhp = max(maxhp, curr);
    if (curr > prev)
      start = mid + 1;
    else
      end = mid - 1;
  }
  cout << maxhp;
  return 0;
}
