#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 1e5 + 55;
const int INF = 1e9 + 77;
const long long INFINF = 1e18 + 1e17;
const double PI = acos(-1.0);
long long Power(long long x, long long y) {
  if (!y) return 1;
  long long s = Power(x, y >> 1);
  s *= s;
  if (y & 1) s *= x;
  return s;
}
long long n, s;
pair<pair<long long, long long>, pair<long long, long long>> x[MAX];
long long Check(long long type1, long long how) {
  long long type2 = how - type1;
  type1 *= s;
  type2 *= s;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long a, b;
    tie(a, b) = x[i].second;
    long long eat = x[i].first.second;
    if (a >= b) {
      long long howType1 = min(eat, type1);
      type1 -= howType1;
      long long howType2 = eat - howType1;
      type2 -= howType2;
      ans += (a * howType1);
      ans += (b * howType2);
    } else if (b > a) {
      long long howType2 = min(eat, type2);
      type2 -= howType2;
      long long howType1 = eat - howType2;
      type1 -= howType1;
      ans += (a * howType1);
      ans += (b * howType2);
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  long long how = 0;
  for (int i = 0; i < n; i++) {
    cin >> x[i].first.second;
    how += x[i].first.second;
    long long a, b;
    cin >> a >> b;
    x[i].first.first = abs(a - b);
    x[i].second.first = a;
    x[i].second.second = b;
  }
  sort(x, x + n);
  reverse(x, x + n);
  how = (how / s) + (bool)(how % s);
  long long st = 0;
  long long en = how - 1;
  long long ans = Check(how, how);
  while (st <= en) {
    long long mid = (st + en) >> 1;
    if (Check(mid, how) == Check(mid + 1, how)) {
      ans = Check(mid, how);
      break;
    } else if (Check(mid, how) < Check(mid + 1, how)) {
      ans = Check(mid + 1, how);
      st = mid + 1;
    } else {
      ans = Check(mid, how);
      en = mid - 1;
    }
  }
  cout << ans;
  return 0;
}
