#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void amin(X& x, const Y& y) {
  if (x > y) {
    x = y;
  }
}
template <class X, class Y>
void amax(X& x, const Y& y) {
  if (x < y) {
    x = y;
  }
}
const int INF = 0x3f3f3f3f;
const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 1e5 + 10;
struct Person {
  int s, a, b;
};
int n, s;
Person p[MAX];
vector<Person> type1, type2;
long long res, sum, s1, s2;
long long getPizza(long long sum) { return (sum - 1) / s + 1; }
bool comp(const Person& p1, const Person& p2) {
  return p1.a - p1.b < p2.a - p2.b;
}
bool comp2(const Person& p1, const Person& p2) {
  return p1.b - p1.a < p2.b - p2.a;
}
long long removeType1() {
  sort(type1.begin(), type1.end(), comp);
  long long val = res;
  int rm = s1 - (long long)(getPizza(s1) - 1) * s;
  for (int i = 0; i < type1.size(); i++) {
    if (type1[i].s >= rm) {
      val += (long long)rm * (type1[i].b - type1[i].a);
      rm = 0;
      break;
    } else {
      val += (long long)type1[i].s * (type1[i].b - type1[i].a);
      rm -= type1[i].s;
    }
  }
  return val;
}
long long removeType2() {
  sort(type2.begin(), type2.end(), comp2);
  long long val = res;
  int rm = s2 - (long long)(getPizza(s2) - 1) * s;
  for (int i = 0; i < type2.size(); i++) {
    if (type2[i].s >= rm) {
      val += (long long)rm * (type2[i].a - type2[i].b);
      rm = 0;
      break;
    } else {
      val += (long long)type2[i].s * (type2[i].a - type2[i].b);
      rm -= type2[i].s;
    }
  }
  return val;
}
void process() {
  cin >> n >> s;
  for (int i = 1; i <= n; i++) cin >> p[i].s >> p[i].a >> p[i].b;
  for (int i = 1; i <= n; i++) {
    if (p[i].a == p[i].b)
      res += (long long)p[i].s * p[i].a;
    else if (p[i].a > p[i].b) {
      type1.push_back(p[i]);
      s1 += p[i].s;
      res += (long long)p[i].s * p[i].a;
    } else {
      type2.push_back(p[i]);
      s2 += p[i].s;
      res += (long long)p[i].s * p[i].b;
    }
    sum += p[i].s;
  }
  long long maxp = getPizza(sum);
  if (getPizza(s1) + getPizza(s2) <= maxp) {
    cout << res;
    return;
  }
  res = max(removeType1(), removeType2());
  cout << res;
}
int main() {
  ios_base::sync_with_stdio(false);
  process();
}
