#include <bits/stdc++.h>
using namespace std;
const int SI = 1e5 + 100;
struct node {
  long long a, b, c, num;
} W[SI];
int N;
long long S, tot, ans, need, BA;
bool comp(node X, node Y) { return X.c > Y.c; }
long long work(long long K) {
  if (K > need) return 0;
  long long last = (need - K) * S;
  long long MD = max(0ll, tot - last);
  long long top = K * S;
  long long have = 0;
  long long add = 0;
  for (int i = 1; i <= N; i++) {
    if (W[i].c > 0) {
      if (have + W[i].num < top) {
        add += W[i].c * W[i].num;
        have += W[i].num;
      } else {
        add += W[i].c * (top - have);
        break;
      }
    } else {
      if (have + W[i].num < MD) {
        add += W[i].c * W[i].num;
        have += W[i].num;
      } else {
        long long ff = max(0ll, MD - have);
        add += W[i].c * ff;
        break;
      }
    }
  }
  return BA + add;
}
int main() {
  scanf("%d %I64d", &N, &S);
  for (int i = (1); i <= (N); i++) {
    scanf("%I64d %I64d %I64d", &W[i].num, &W[i].a, &W[i].b);
    W[i].c = W[i].b - W[i].a;
    tot += W[i].num;
    BA += W[i].num * W[i].a;
  }
  sort(W + 1, W + 1 + N, comp);
  need = tot / S;
  if (tot % S != 0) need++;
  long long tt = 0;
  for (int i = (1); i <= (N); i++) {
    if (W[i].c <= 0) break;
    tt += W[i].num;
  }
  long long K = tt / S;
  ans = BA;
  ans = max(ans, work(K));
  ans = max(ans, work(K + 1));
  printf("%I64d ", ans);
  return 0;
}
