#include <bits/stdc++.h>
using namespace std;
long long add(long long a, long long b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
long long mul(long long a, long long b) {
  return ((a % 1000000007) * (b % 1000000007)) % 1000000007;
}
long long binary_expo(long long base, long long expo) {
  long long res = 1;
  while (expo) {
    if (expo % 2) {
      res = mul(res, base);
      expo /= 2;
    }
    base = mul(base, base);
  }
  return res;
}
const long long N = 100002;
long long A[N], B[N], S[N];
long long get1(long long n, long long sum, long long s) {
  vector<pair<long long, long long> > v;
  long long aa = 0, ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (A[i] > B[i]) {
      ans += A[i] * S[i];
      aa += S[i];
    } else {
      v.push_back({B[i] - A[i], i});
    }
  }
  long long tot = (sum + s - 1) / s;
  long long ta = (aa + s - 1) / s;
  long long tb = (tot - ta) * s;
  sort((v).begin(), (v).end(), greater<pair<long long, long long> >());
  for (long long i = 0; i < v.size(); i++) {
    if (tb >= S[v[i].second]) {
      ans += S[v[i].second] * B[v[i].second];
      tb -= S[v[i].second];
    } else {
      ans += tb * B[v[i].second] + (S[v[i].second] - tb) * A[v[i].second];
      tb = 0;
    }
  }
  return ans;
}
long long get2(long long n, long long sum, long long s) {
  vector<pair<long long, long long> > v;
  long long aa = 0, ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (B[i] > A[i]) {
      ans += B[i] * S[i];
      aa += S[i];
    } else {
      v.push_back({A[i] - B[i], i});
    }
  }
  long long tot = (sum + s - 1) / s;
  long long ta = (aa + s - 1) / s;
  long long tb = (tot - ta) * s;
  sort((v).begin(), (v).end(), greater<pair<long long, long long> >());
  for (long long i = 0; i < v.size(); i++) {
    if (tb >= S[v[i].second]) {
      ans += S[v[i].second] * A[v[i].second];
      tb -= S[v[i].second];
    } else {
      ans += tb * A[v[i].second] + (S[v[i].second] - tb) * B[v[i].second];
      tb = 0;
    }
  }
  return ans;
}
void solve() {
  long long n, s;
  cin >> n >> s;
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> S[i] >> A[i] >> B[i];
    sum += S[i];
  }
  cout << max(get1(n, sum, s), get2(n, sum, s)) << endl;
}
signed main() {
  long long t;
  ios_base::sync_with_stdio(false);
  t = 1;
  while (t--) solve();
  return 0;
}
