#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[110000];
int l[110000];
int r[110000];
pair<long long,int>ev[110000];

int main(){
	int a,b;scanf("%d%d",&a,&b);
	long long cur=0;
	for(int i=0;i<a;i++){
		scanf("%d%d%d",p+i,l+i,r+i);
		ev[i]=make_pair((long long)l[i]*p[i]+(long long)r[i]*(b-p[i]),i);
		cur+=(long long)l[i]*p[i];
	}
	std::sort(ev,ev+a);
	reverse(ev,ev+a);
	long long left=-1;
	long long right=(long long)b*a;
	while(left+1<right){
		long long M=(left+right)/2;
		long long req=M/b;
		long long val=0;
		for(int i=0;i<req;i++){
			val+=ev[i].first;
		}
		bool ok=false;
		for(int i=0;i<a;i++){
			long long tmp=val;
			if(i<req){
				tmp-=ev[i].first;
				tmp+=ev[req].first;
			}
			tmp+=min((long long)p[ev[i].second],M%b)*l[ev[i].second]+max(0LL,M%b-p[ev[i].second])*r[ev[i].second];
			if(tmp>=cur){
				ok=true;
			}
		}
		if(ok)right=M;
		else left=M;
	}
	printf("%lld\n",right);
}