#include <bits/stdc++.h>
using namespace std;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, -1, 0, 1};
template <class T>
void inputVector(vector<T> &v, long long n) {
  v.resize(n);
  for (long long i = 0; i < v.size(); i++) cin >> v[i];
}
class Person {
 public:
  long long s, a, b;
  Person(long long s, long long a, long long b) {
    this->s = s;
    this->a = a;
    this->b = b;
  }
};
long long N, S;
long long total;
vector<Person> personA, personB, personAB;
long long solve(long long val) {
  long long A = val * S;
  long long B = (total - val) * S;
  if (A < 0 || B < 0) return 0;
  long long ret = 0;
  for (auto &p : personA) {
    if (p.s > A) {
      ret += A * p.a + (p.s - A) * p.b;
      A = 0;
    } else {
      ret += p.s * p.a;
      A -= p.s;
    }
  }
  for (auto &p : personB) {
    if (p.s > B) {
      ret += B * p.b + (p.s - B) * p.a;
      B = 0;
    } else {
      ret += p.s * p.b;
      B -= p.s;
    }
  }
  for (auto &p : personAB) {
    ret += p.s * p.a;
  }
  return ret;
}
signed main() {
  cin >> N >> S;
  long long sums = 0;
  for (long long i = 0; i < (N); i++) {
    long long s, a, b;
    scanf("%lld %lld %lld", &s, &a, &b);
    if (a > b)
      personA.push_back(Person(s, a, b));
    else if (a < b)
      personB.push_back(Person(s, a, b));
    else
      personAB.push_back(Person(s, a, b));
    sums += s;
  }
  sort((personA).begin(), (personA).end(),
       [&](Person p1, Person p2) { return p1.a - p1.b > p2.a - p2.b; });
  sort((personB).begin(), (personB).end(),
       [&](Person p1, Person p2) { return p1.a - p1.b < p2.a - p2.b; });
  total = (sums + S - 1) / S;
  long long low = 0;
  long long high = total + 1;
  long long mid1 = low + (high - low) / 3;
  long long mid2 = low + (high - low) * 2 / 3;
  while (mid2 - mid1 > 1) {
    if (solve(mid1) > solve(mid2)) {
      high = mid2;
    } else {
      low = mid1;
    }
    mid1 = low + (high - low) / 3;
    mid2 = low + (high - low) * 2 / 3;
  }
  long long ret = 0;
  for (long long i = (max(0ll, mid1 - 5)); i <= (min(mid2 + 5, total)); i++) {
    ret = max(ret, solve(i));
  }
  cout << ret << endl;
  return 0;
}
