#include <bits/stdc++.h>
using namespace std;
int s[100005], a[100005], b[100005];
long long prefS[100005], suffS[100005];
long long prefA[100005], suffA[100005];
long long prefB[100005], suffB[100005];
pair<int, int> p[100005];
int main() {
  int n, S;
  long long sum = 0;
  scanf("%d%d", &n, &S);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &s[i], &a[i], &b[i]);
    p[i] = pair<int, int>(b[i] - a[i], i);
    sum += s[i];
  }
  long long mx = (sum + S - 1) / S;
  sort(p + 1, p + 1 + n);
  reverse(p + 1, p + 1 + n);
  for (int i = 1; i <= n; i++) {
    int j = p[i].second;
    prefS[i] = prefS[i - 1] + s[j];
    prefA[i] = prefA[i - 1] + a[j] * 1ll * s[j];
    prefB[i] = prefB[i - 1] + b[j] * 1ll * s[j];
  }
  for (int i = n; i >= 1; i--) {
    int j = p[i].second;
    suffS[i] = suffS[i + 1] + s[j];
    suffA[i] = suffA[i + 1] + a[j] * 1ll * s[j];
    suffB[i] = suffB[i + 1] + b[j] * 1ll * s[j];
  }
  long long ans = max(prefA[n], prefB[n]);
  for (int i = 1; i <= n; i++) {
    int j = p[i].second;
    long long pref = prefS[i - 1];
    long long suff = suffS[i + 1];
    long long res = prefB[i - 1] + suffA[i + 1];
    long long m1 = (pref + S - 1) / S;
    long long m2 = (suff + S - 1) / S;
    if (m1 + m2 > mx) continue;
    long long B = m1 * 1ll * S - pref;
    long long A = m2 * 1ll * S - suff;
    if (b[j] - a[j] >= 0)
      B += (mx - (m1 + m2)) * 1ll * S;
    else
      A += (mx - (m1 + m2)) * 1ll * S;
    if (b[j] - a[j] >= 0) {
      if (B >= s[j])
        res += s[j] * 1ll * b[j];
      else {
        res += B * 1ll * b[j];
        res += (s[j] - B) * 1ll * a[j];
      }
    } else {
      if (A >= s[j])
        res += s[j] * 1ll * a[j];
      else {
        res += A * 1ll * a[j];
        res += (s[j] - A) * 1ll * b[j];
      }
    }
    ans = max(ans, res);
  }
  printf("%lld\n", ans);
}
