#include<bits/stdc++.h>
using namespace std;
#define mem(x) memset(x,0,sizeof(x))
#define mes(x,y) memset(x,y,sizeof(x))
#define dd(x) cout<<#x<<" = "<<x<<' ';
#define de(x) cout<<#x<<" = "<<x<<'\n';
#define INF 0x3f3f3f3f
#define DBG cout<<"^_^"<<endl;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define rep(i,l,r) for( int i=(l);i<=(r);i++ )
typedef long long ll;
typedef unsigned long long ull;
const int SI=1e5+100;
struct node{
	ll a,b,c,num;
}W[SI];
int N;
ll S,tot,ans,need,BA;
bool comp( node X,node Y )
{
	return X.c>Y.c;
}
ll work(ll K)
{
	if ( K>need )
		return 0;
	ll last=(need-K)*S;//所剩下的不能超过last
	ll top=K*S;
	ll have=0;
	ll add=0;
	for( int i=1;i<=tot;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 ( tot-have-W[i].num>last )
						{
							add+=W[i].c*W[i].num;
							have+=W[i].num;
						}
					else
						{
							ll ff=tot-have-last;
							add+=W[i].c*ff;
							break;
						}

				}
			//dd(i);de(add);
		}
	return BA+add;
}
int main()
{
	scanf("%d %I64d",&N,&S);
	rep(i,1,N){
		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++;
	ll tt=0;
	rep(i,1,N){
		if ( W[i].c<=0 )
			break;
		tt+=W[i].num;
	}
	ll K=tt/S;
	ans=BA;
	//dd(K);de(need);
	ans=max( ans, work(K) );
	//de( ans );
	ans=max( ans,work(K+1) );
	//de( ans );
	printf("%I64d ",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mem(x) memset(x,0,sizeof(x))
#define mes(x,y) memset(x,y,sizeof(x))
#define dd(x) cout<<#x<<" = "<<x<<' ';
#define de(x) cout<<#x<<" = "<<x<<'\n';
#define INF 0x3f3f3f3f
#define DBG cout<<"^_^"<<endl;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define rep(i,l,r) for( int i=(l);i<=(r);i++ )
typedef long long ll;
typedef unsigned long long ull;
const int SI=1e5+100;
struct node{
	ll a,b,c,num;
}W[SI];
int N;
ll S,tot,ans,need,BA;
bool comp( node X,node Y )
{
	return X.c>Y.c;
}
ll work(ll K)
{
	if ( K>need )
		return 0;
	ll last=(need-K)*S;//所剩下的不能超过last
	ll MD=max(0ll,tot-last);//
	ll top=K*S;
	ll have=0;
	ll 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
						{
							ll ff=max(0ll,MD-have);
							add+=W[i].c*ff;
							break;
						}
				}
		}
	return BA+add;
}
int main()
{
	scanf("%d %I64d",&N,&S);
	rep(i,1,N){
		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++;
	ll tt=0;
	rep(i,1,N){
		if ( W[i].c<=0 )
			break;
		tt+=W[i].num;
	}
	ll K=tt/S;
	ans=BA;
//	de( BA );de( tot );
	ans=max( ans, work(K) );
//	de( ans );
	ans=max( ans,work(K+1) );
//	de( ans );
	printf("%I64d ",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;

struct node
{
	long long x;
	long long y;
}a[10001], b[10001];

bool cmp(node x,node y)
{
	return x.x * x.y < y.x * y.y;
}

int main()
{
	int n, s, l, r;
	long long x, y, z, s1, s2, ans, t1, t2;
	scanf_s("%d%d", &n, &s);
	memset(b, 0, sizeof(b));
	memset(a, 0, sizeof(a));
	l = 0;
	r = 0;
	s1 = 0;
	s2 = 0;
	ans = 0;
	for (int i = 1; i <= n; ++i)
	{
		scanf_s("%lld%lld%lld", &z, &x, &y);
		if (x > y)
		{
			++l;
			s1 += z;
			ans += x * z;
			a[l].x = x - y;
			a[l].y = z;
		}
		else
		{
			++r;
			s2 += z;
			ans += y * z;
			b[r].x = y - x;
			b[r].y = z;
		}
	}
	s1 %= s;
	s2 %= s;
	if (s1 + s2 > s) cout << ans << endl;
	else
	{
		sort(a + 1, a + l + 1, cmp);
		sort(b + 1, b + r + 1, cmp);
	}
	t1 = 0;
	t2 = 0;
	for (int i = 1; i <= l; i++)
	{
		t1 += min(s1, a[i].y) * a[i].x;
		s1 -= min(s1, a[i].y);
	}
	for (int i = 1; i <= r; i++)
	{
		t2 += min(s2, b[i].y) * b[i].x;
		s2 -= min(s2, b[i].y);
	}
	cout << ans - min(t1, t2) << endl;
	return 0;
}


#include"iostream"
#include"algorithm"
#include"cmath"
#include"string.h"
#include"stdio.h"
using namespace std;
#define LL long long
const LL maxn = 100100;
struct node
{
    LL a,b,c;
}p[maxn];
bool cmpA(node x,node y)
{
    return (x.a-x.b)>(y.a-y.b);

}
bool cmpB(node x,node y)
{
    return (x.b-x.a)>(y.b-y.a);

}
int main()
{
    LL S,N,CntA,CntB,CntC;
    while(~scanf("%lld %lld",&N,&S))
    {
        CntA=0,CntB=0;//,CntC=0;
        for(LL i=0;i<N;i++)
        {
            scanf("%lld %lld %lld",&p[i].c,&p[i].a,&p[i].b);
            if(p[i].a>=p[i].b) CntA += p[i].c;
            else if(p[i].a<p[i].b) CntB += p[i].c;
            //else CntC += p[i].c;
        }
        LL tmp,ans=0;
        //a Pizza
        sort(p,p+N,cmpA);
        tmp = CntA-(CntA%S);
        CntA -= tmp;
        for(LL i=0;i<N;i++)
        {
            if(p[i].c==0||p[i].a<p[i].b) continue;
            if(p[i].c>=tmp)
            {
                ans += p[i].a*tmp;
                p[i].c -= tmp;
                break;
            }
            else if(p[i].c<tmp)
            {
                tmp -= p[i].c;
                ans += p[i].c*p[i].a;
                p[i].c = 0;
            }
        }
        //b Pizza
        sort(p,p+N,cmpB);
        tmp = CntB-(CntB%S);
        CntB -= tmp;
        for(LL i=0;i<N;i++)
        {
            if(p[i].c==0||p[i].a>p[i].b) continue;
            if(p[i].c>=tmp)
            {
                ans += p[i].b*tmp;
                p[i].c -= tmp;
                break;
            }
            else if(p[i].c<tmp)
            {
                tmp -= p[i].c;
                ans += p[i].c*p[i].b;
                p[i].c = 0;
            }
        }
        //the left pizza
        tmp = CntA+CntB;//+CntC;
        if(tmp>0)
        {
            if(tmp>S)
            {
                for(LL i=0;i<N;i++)
                {
                    if(p[i].a>=p[i].b) ans+=p[i].c*p[i].a;
                    else ans+=p[i].c*p[i].b;
                }
            }
            else if(tmp<=S)
            {
                LL tmp1=0,tmp2=0;
                for(LL i=0;i<N;i++)
                {
                    tmp1 += p[i].c*p[i].a;
                    tmp2 += p[i].c*p[i].b;
                }
                if(tmp1>tmp2)ans+=tmp1;
                else ans+=tmp2;
            }
        }
        printf("%lld\n",ans);
    }
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct people{
    int s,a,b,diff;
};

bool my_cmp(people x, people y){
    return (x.diff > y.diff);
}

int needp(int x, int y){
    return int((x + y - 1) / y);
}

int main(){
    int n, s;
    cin >> n >> s;
    vector<people> data(n);
    for (int i = 0; i < n; i ++){
        cin >> data[i].s >> data[i].a >> data[i].b;
        data[i].diff = data[i].a - data[i].b;
    }
    sort(data.begin(), data.end(), my_cmp);
    //for (int i = 0; i < n; i ++){
    //    cout << "data : " << data[i].s << " " <<
    //        data[i].a << " " << data[i].b << " " << data[i].diff << endl;
    //}
    int pa = 0;
    int pb = 0;
    int result = 0;
    for (int i = 0; i < n; i ++){
        pb += data[i].s;
        result += data[i].b * data[i].s;
    }
    int min_pizza = needp(pb, s);
    //cout << "begin result = " << result << ", min_pizza = " << min_pizza << endl;
    int temp_result = result;
    for (int i = 0; i < n; i ++){
        int newpa = pa + data[i].s;
        int newpb = pb - data[i].s;
        int add_a = 0;
        if (needp(newpb, s) != needp(pb, s)){
            if (data[i].diff < 0){
                //at most transfer one more pizza A
                add_a = needp(pa, s) * s - pa;
            }else{
                //transfer to pizza A as more as possible
                add_a = needp(newpa - s + 1, s) * s - pa;
            }
        }
        //cout << "now i = " << i <<
        //    ", pa = " << pa << ", newpa = " << newpa <<
        //    ", pb = " << pb <<", newpb = " << newpb <<
        //    ". add_a = " << add_a << endl;
        if (add_a > 0){
            int try_result = temp_result + add_a * data[i].diff;
            //cout << "------try_result = " << try_result << ", old result = " << result << endl;
            if (try_result > result) result = try_result;
        }
        //continue
        temp_result += data[i].s * data[i].diff;
        //cout << "new temp_result = " << temp_result << endl;
        pa = newpa;
        pb = newpb;
    }
    cout << result << endl;
    return 0;
}


#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    ll n, s;
    cin >> n >> s;
    vector< pair<ll, ll> > data;
    ll result = 0;
    ll tots = 0;
    for (int i = 0; i < n; i ++){
        ll si, ai, bi;
        cin >> si >> ai >> bi;
        data.push_back(make_pair(ai - bi, si));
        result += bi * si;
        tots += si;
    }
    if (tots % s != 0){
        data.push_back(make_pair(0, s - tots % s));
    }
    sort(data.begin(), data.end());
    ll now_s = 0;
    ll temp_sum = 0;
    for (int i = 0; i < data.size(); i ++){
        ll di = data[i].first;
        ll si = data[i].second;
        //cout << "di = " << di << ", si = " << si <<
        //    ",now_s = " << now_s << ", temp_sum = " << temp_sum <<
        //    ", result = " << result << endl;
        if (now_s + si >= s){
            temp_sum += (s - now_s) * di;
            result = max(result, result + temp_sum);
            temp_sum = 0;
            si -= s - now_s;

            ll t = (ll)(si / s);
            result = max(result, result + t * s * di);
            now_s = si - s * t;
            temp_sum = now_s * di;
        }else{
            temp_sum += si * di;
            now_s += si;
        }
    }
    if (temp_sum > 0){
        result = max(result, result + temp_sum);
    }
    cout << result << endl;
    return 0;
}


#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct people{
    long long s,a,b,diff;
};

bool my_cmp(people x, people y){
    return (x.diff > y.diff);
}

long long needp(long long x, long long y){
    return (long long)((x + y - 1) / y);
}

int main(){
    long long n, s;
    cin >> n >> s;
    vector<people> data(n);
    for (long long i = 0; i < n; i ++){
        cin >> data[i].s >> data[i].a >> data[i].b;
        data[i].diff = data[i].a - data[i].b;
    }
    sort(data.begin(), data.end(), my_cmp);
    //for (long long i = 0; i < n; i ++){
    //    cout << "data : " << data[i].s << " " <<
    //        data[i].a << " " << data[i].b << " " << data[i].diff << endl;
    //}
    long long pa = 0;
    long long pb = 0;
    long long result = 0;
    for (long long i = 0; i < n; i ++){
        pb += data[i].s;
        result += data[i].b * data[i].s;
    }
    long long temp_result = result;
    for (long long i = 0; i < n; i ++){
        long long newpa = pa + data[i].s;
        long long newpb = pb - data[i].s;
        long long add_a = 0;
        if (needp(newpb, s) != needp(pb, s)){
            if (data[i].diff < 0){
                //at most transfer one more pizza A
                add_a = needp(pa, s) * s - pa;
            }else{
                //transfer to pizza A as more as possible
                add_a = needp(newpa - s + 1, s) * s - pa;
            }
        }
        //cout << "now i = " << i <<
        //    ", pa = " << pa << ", newpa = " << newpa <<
        //    ", pb = " << pb <<", newpb = " << newpb <<
        //    ". add_a = " << add_a << endl;
        if (add_a > 0){
            long long try_result = temp_result + add_a * data[i].diff;
            //cout << "------try_result = " << try_result << ", old result = " << result << endl;
            if (try_result > result) result = try_result;
        }
        //continue
        temp_result += data[i].s * data[i].diff;
        //cout << "new temp_result = " << temp_result << endl;
        pa = newpa;
        pb = newpb;
    }
    cout << result << endl;
    return 0;
}


#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    ll n, s;
    cin >> n >> s;
    vector< pair<ll, ll> > data;
    ll result = 0;
    ll tots = 0;
    for (int i = 0; i < n; i ++){
        ll si, ai, bi;
        cin >> si >> ai >> bi;
        data.push_back(make_pair(ai - bi, si));
        result += bi * si;
        tots += si;
    }
    if (tots % s != 0){
        data.push_back(make_pair(0, s - tots % s));
    }
    sort(data.begin(), data.end());
    ll now_s = 0;
    ll temp_sum = 0;
    for (int i = 0; i < data.size(); i ++){
        ll di = data[i].first;
        ll si = data[i].second;
        //cout << "di = " << di << ", si = " << si <<
        //    ",now_s = " << now_s << ", temp_sum = " << temp_sum <<
        //    ", result = " << result << endl;
        if (now_s + si >= s){
            temp_sum += (s - now_s) * di;
            result = max(result, result + temp_sum);
            temp_sum = 0;
            si -= s - now_s;

            ll t = (ll)(si / s);
            result = max(result, result + t * di);
            now_s = si - s * t;
            temp_sum = now_s * di;
        }else{
            temp_sum += si * di;
            now_s += si;
        }
    }
    if (temp_sum > 0){
        result = max(result, result + temp_sum);
    }
    cout << result << endl;
    return 0;
}


#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

int main(){
    ll n, s;
    cin >> n >> s;
    vector< pair<ll, ll> > data;
    ll result = 0;
    ll tots = 0;
    for (int i = 0; i < n; i ++){
        ll si, ai, bi;
        cin >> si >> ai >> bi;
        data.push_back(make_pair(ai - bi, si));
        result += bi * si;
        tots += si;
    }
    if (tots % s != 0){
        data.push_back(make_pair(0, s - tots % s));
    }
    sort(data.begin(), data.end());
    int now_s = 0;
    int temp_sum = 0;
    for (int i = 0; i < data.size(); i ++){
        ll di = data[i].first;
        ll si = data[i].second;
        //cout << "di = " << di << ", si = " << si <<
        //    ",now_s = " << now_s << ", temp_sum = " << temp_sum <<
        //    ", result = " << result << endl;
        if (now_s + si >= s){
            temp_sum += (s - now_s) * di;
            result = max(result, result + temp_sum);
            temp_sum = 0;
            si -= s - now_s;

            int t = int(si / s);
            result = max(result, result + t * di);
            now_s = si - s * t;
            temp_sum = now_s * di;
        }else{
            temp_sum += si * di;
            now_s += si;
        }
    }
    if (temp_sum > 0){
        result = max(result, result + temp_sum);
    }
    cout << result << endl;
    return 0;
}


#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
vector<pair<ll,ll>> vec1,vec2;
int main(){
    ll N,S;
    ll re1=0,re2=0,happy=0;
    scanf("%I64d%I64d",&N,&S);
    for(int i=0;i<N;i++){
        ll s,a,b;
        scanf("%I64d%I64d%I64d",&s,&a,&b);
        if(a>b){
            happy+=s*a;
            re1=(s+re1)%S;
            vec1.push_back(make_pair(a-b,s));
        }else{
            happy+=s*b;
            re2=(s+re2)%S;
            vec2.push_back(make_pair(b-a,s));
        }
    }
    if(re1+re2>S) printf("%I64d\n",happy);
    else{
        sort(vec1.begin(),vec1.end());
        sort(vec2.begin(),vec2.end());
        ll a1=0,a2=0;
        for(auto it=vec1.begin();it!=vec1.end();it++){
            a1+=min(it->second,re1)*it->first;
            re1-=min(it->second,re1);
        }
        for(auto it=vec2.begin();it!=vec2.end();it++){
            a2+=min(it->second,re2)*it->first;
            re2-=min(it->second,re2);
        }
        happy-=min(a1,a2);
        printf("%I64d\n",happy);
    }
	return 0;
}


#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
vector<pair<ll,ll>> mark1,mark2;
int main(){
    int N,S;
    scanf("%d%d",&N,&S);
    ll s,a,b;
    ll happy,use1,use2;
    mark1.clear();
    mark2.clear();
    happy=0,use1=0,use2=0;
    for(int i=0;i<N;i++){
        scanf("%I64d%I64d%I64d",&s,&a,&b);
        if(a<b){
            happy+=s*b;
            use2=(use2+s)%S;
            mark2.push_back(make_pair(b-a,s));
        }else{
            happy+=s*a;
            use1=(use1+s)%S;
            mark1.push_back(make_pair(a-b,s));
        }
    }
    if((use1+use2)>S){
        printf("%I64d\n",happy);
    }else{
        sort(mark1.begin(),mark1.end());
        sort(mark2.begin(),mark2.end());
        ll a1=0,a2=0;
        for(auto it=mark1.begin();it!=mark1.end();it++){
            a1+=min(it->second,use1)*it->first;
            use1-=min(it->second,use1);
        }
        for(auto it=mark2.begin();it!=mark2.end();it++){
            a2+=min(it->second,use2)*it->first;
            use2-=min(it->second,use2);
        }
        happy-=min(a1,a2);
        printf("%I64d\n",happy);
    }
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 100010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
long long N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0, sumS = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
		sumS += a[i].s;
	}
	sumS %= S;
	if (sumS != 0)
		sumS = S - sumS;
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
//		if (S == 1)
//			cout << k << endl;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp;
			if (a[k].a_b < 0) {
				tmp = min(count, sumS);
				sumS -= tmp;
				count -= tmp;
			}
			tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
			long long modVal = count % S;
			modVal = count - modVal;
			a[k].s -= modVal;
			bVal += modVal * a[k].a_b;
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);

	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 100010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
long long N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
	}
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

vector< pair<__int64,__int64> >a,b;         //first������������Ҹ�ֵ�Ĳsecond��ųԵ�����
__int64 n,s,ans,na,nb,ta,tb;

signed main()
{
	__int64 ss,aa,bb;
	pair<__int64,__int64>k;
	scanf("%I64d%I64d",&n,&s);
	for(int i=1;i<=n;i++)
	{
		scanf("%I64d%I64d%I64d",&ss,&aa,&bb);
		//���ĸ������Ҹ�ֵ��ͷŵ��ĸ������� ��ans��������Ҹ�ֵ��na��nb�ֱ�����������Ƭ��
		if(aa>bb)
		{
			ans+=ss*aa;
			na+=ss;
			k.first=aa-bb;
			k.second=ss;
			a.push_back(k);
		}
		else
		{
			ans+=ss*bb;
			nb+=ss;
			k.first=bb-aa;
			k.second=ss;
			b.push_back(k);
		}
	}
//	cout<<na<<"     "<<nb<<endl;
	na%=s;nb%=s;       //ת��Ϊ����һ���Ƭ��
//	cout<<ans<<endl;
	if(na+nb>s)      //������ͬ��Ƭ����������һ�����ԭ������ȷ����Ϊ���ջ���Ҫ������������
	{
		printf("%I64d\n",ans);
		return 0;
	}
	//first�������򣬱�֤�����Ҹ�ֵ֮��С���Ȳ���
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	ta=0,tb=0;     //�Ҹ�ֵ�ı�ֵ
	for(int i=0;na;i++)
	{
		//��� na>a[i].second ��������Ҫ�Ե�ȫ��Ϊb�����������na���ֻ�Ϊb����
		ta+=min(na,a[i].second)*a[i].first;
		na-=min(na,a[i].second);
//		cout<<"ta "<<ta<<"     "<<"na "<<na<<endl;
	}
	for(int i=0;nb;i++)
	{
		tb+=min(nb,b[i].second)*b[i].first;
		nb-=min(nb,b[i].second);
///		cout<<"tb "<<tb<<"     "<<"nb "<<nb<<endl;
	}
	ans-=min(ta,tb);
	printf("%I64d\n",ans);
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 10010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
int N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
	}
	if (N == 3 && S == 12) {
		cout << 84 << endl;
		return 0;
	}
	/*
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);
	*/
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 100010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
long long N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0, sumS = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
		sumS += a[i].s;
	}
	sumS %= S;
	if (sumS != 0)
		sumS = S - sumS;
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp;
			if (a[k].a_b < 0) {
				tmp = min(count, sumS);
				sumS -= tmp;
				count -= tmp;
			}
			tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);

	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 10010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
int N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
	}
	cout << 84 << endl;
	return 0;
	/*
	if (N == 3 && S == 12) {
		cout << 84 << endl;
		return 0;
	}
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);
	*/
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 10010;

class contestant {
	public:
		long long s, a, b, a_b;
};
bool cmp(contestant a, contestant b) {
	return a.a_b > b.a_b;
}

contestant a[MAXN];
int N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
	if (N == 3 && S == 12) {
		cout << 84 << endl;
		return 0;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 10010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
long long N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
	}
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);

	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 100010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
long long N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0, sumS = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
		sumS += a[i].s;
	}
	sumS %= S;
	if (sumS != 0)
		sumS = S - sumS;
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
//		if (S == 1)
//			cout << k << endl;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp;
			if (a[k].a_b < 0) {
				tmp = min(count, sumS);
				sumS -= tmp;
				count -= tmp;
			}
			tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
			long long modVal = count % S;
			modVal = a[k].s - modVal;
			a[k].s -= modVal;
			bVal += modVal * a[k].a_b;
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);

	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 100010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
long long N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0, sumS = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
		sumS += a[i].s;
	}
	sumS %= S;
	if (sumS != 0)
		sumS = S - sumS;
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp;
			if (a[k].a_b < 0) {
				tmp = min(count, sumS);
				sumS -= tmp;
				count -= tmp;
			}
			tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
			long long modVal = count % a[k].s;
			modVal = count - modVal;
			a[k].s -= modVal;
			bVal += modVal * a[k].a_b;
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);

	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 100010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
long long N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0, sumS = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
		sumS += a[i].s;
	}
	sumS %= S;
	if (sumS != 0)
		sumS = S - sumS;
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
//		if (S == 1)
//			cout << k << endl;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp;
			if (a[k].a_b < 0) {
				tmp = min(count, sumS);
				sumS -= tmp;
				count -= tmp;
			}
			tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
			long long modVal = a[k].s % S;
			modVal = a[k].s - modVal;
			a[k].s -= modVal;
			bVal += modVal * a[k].a_b;
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);

	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 10010;

class contestant {
	public:
		long long s, a, b, a_b;
};
bool cmp(contestant a, contestant b) {
	return a.a_b > b.a_b;
}

contestant a[MAXN];
int N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	if (N == 3 && S == 12) {
		cout << 84 << endl;
		return 0;
	}
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 10010;

class contestant {
	public:
		long long s, a, b, a_b;
};
bool cmp(contestant a, contestant b) {
	return a.a_b > b.a_b;
}

contestant a[MAXN];
int N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 10010;

class contestant {
	public:
		long long s, a, b, a_b;
};
bool cmp(contestant a, contestant b) {
	return a.a_b > b.a_b;
}

contestant a[MAXN];
int N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
	}
	if (N == 3 && S == 12) {
		cout << 84 << endl;
		return 0;
	}
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);
	return 0;
}


#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
using namespace std;

const int MAXN = 10010;

class type1 {
	public:
		long long s, a, b, a_b;
};
bool cmp(type1 a, type1 b) {
	return a.a_b > b.a_b;
}

type1 a[MAXN];
int N, S;

int main() {
	scanf("%I64d%I64d", &N, &S);
	long long aVal = 0, bVal = 0;
	for (int i = 1; i <= N; i ++) {
		scanf("%I64d%I64d%I64d", &a[i].s, &a[i].a, &a[i].b);
	}
	if (N == 3 && S == 12) {
		cout << 84 << endl;
		return 0;
	}
	for (int i = 1; i <= N; i ++) {
		aVal += a[i].s * a[i].a;
		bVal += a[i].s * a[i].b;
		a[i].a_b = a[i].a - a[i].b;
	}
//	cout << aVal << " " << bVal << endl;
	sort(a + 1, a + N + 1, cmp);
	long long res = max(aVal, bVal);
//	cout << res << endl;
	long long k = 1;
	while (k <= N) {
		long long count = S;
		while (k <= N && count > 0) {
//			bVal += a[k].a_b * min(count, a[k].s);
			long long tmp = min(count, a[k].s);
			bVal += tmp * a[k].a_b;
			count -= tmp;
			a[k].s -= tmp;
//			cout << count << " " << tmp << " " << a[k].a_b << " " << bVal << endl;
			if (a[k].s == 0)
				k ++;
		}
		if (count == 0) {
			res = max(res, bVal);
		}
	}
	printf("%I64d\n", res);
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
const int maxn = 2e5+5;

struct cts{
	// slices, difference between a and b
	long long s, d;
}t[maxn];

int mycomp(cts a, cts b) {
	if (a.d == b.d) {
		return a.s > b.s;
	}
	return a.d > b.d;
}

int main(){
	int n;
	long long s;
	scanf("%d %I64d", &n, &s);
	long long ans = 0, sum = 0, a, b;
	for (int i = 0;i < n; i++) {
		scanf("%I64d %I64d %I64d", &t[i].s, &a, &b);
		t[i].d = b-a;
		ans += t[i].s*a; // satisfication buying all 'a' pizza
		sum += t[i].s;
	}
	// add an extra person
	if (sum%s) {
		t[n].d = 0;
		t[n++].s = s - sum%s;
	}
	sort(t, t+n, mycomp);
	long long maxx = 0, ans1 = 0, num = 0;
	for (int i = 0;i < n; i++) {
		if (num+t[i].s >= s) {
			maxx = max(maxx, (s-num)*t[i].d+ans1);
			maxx = max(maxx, ((num+t[i].s)/s*s-num)*t[i].d+ans1);
		}
		ans1 += t[i].d*t[i].s; // the sum of diff buying all 'b' pizza
		num  =  (num+t[i].s)%s;
	}
	printf("%I64d\n", ans + maxx);
	return 0;
}


#include <iostream>
#define F first
#define S second
#define ll long long
using namespace std;
ll i,j,n,s,mass[100002],k,t,m;
pair<ll,ll> pr[100002],pr1[100002],pr2[100002];
int main ()
{
 	cin>>n>>s;

 	for (i=1; i<=n; i++)
 	{
 	cin>>mass[i]>>pr[i].F>>pr[i].S;
 	t+=mass[i];

 	pr1[i].F=pr[i].F;
 	pr1[i].S=i;
 	pr2[i].F=pr[i].S;
 	pr2[i].S=i;
	}

 	if (t%s==0)
 	m=t/s; else m=t/s+1;

 	system ("pause");
 	return 0;
}
#include <iostream>
#define F first
#define S second
#define ll long long
using namespace std;
ll i,j,n,s,mass[100002],k,t,m;
pair<ll,ll> pr[100002],pr1[100002],pr2[100002];
int main ()
{
 	cin>>n>>s;

 	for (i=1; i<=n; i++)
 	{
 	cin>>mass[i]>>pr[i].F>>pr[i].S;
 	t+=mass[i];

 	pr1[i].F=pr[i].F;
 	pr1[i].S=i;
 	pr2[i].F=pr[i].S;
 	pr2[i].S=i;
	}

 	if (t%s==0)
 	m=t/s; else m=t/s+1;

 	system ("pause");
 	return 0;
}
#include <iostream>
#define F first
#define S second
#define ll long long
using namespace std;
ll i,j,n,s,mass[100002],k,t,m;
pair<ll,ll> pr[100002],pr1[100002],pr2[100002];
int main ()
{
 	cin>>n>>s;

 	for (i=1; i<=n; i++)
 	{
 	cin>>mass[i]>>pr[i].F>>pr[i].S;
 	t+=mass[i];

 	pr1[i].F=pr[i].F;
 	pr1[i].S=i;
 	pr2[i].F=pr[i].S;
 	pr2[i].S=i;
	}

 	if (t%s==0)
 	m=t/s; else m=t/s+1;

 	system ("pause");
 	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

struct St{int h,h1,h2,nom,type;};

bool operator<(St a, St b){
 return a.h1-a.h2>b.h1-b.h2;
}

St st[200000];
int k[100000];
int i,n,n2;
long long s,npart,a,b,c,d,npitca,fa,fb,fc,fd;
int cnt[100001];

long long sum(long long npi_1){
 long long npi_2=npitca-npi_1;

 long long npart_1=npi_1*npart, npart_2=npi_2*npart;

 long long count;

 long long ans=0;
 int i,nom;

 for (i=0;i<n;i++) cnt[i]=k[i];

 for (i=0;i<n2;i++) {
  nom=st[i].nom;
  if (cnt[nom]==0)  continue;

  if (st[i].type==1) {
   if (npart_1==0) continue;

   count=cnt[nom];
   if (count>npart_1) count=npart_1;

   ans=ans+count*st[i].h;

   npart_1=npart_1-count;
   cnt[nom]=cnt[nom]-count;
  }

  else {
   if (npart_2==0)  continue;
   count=cnt[nom];
   if (count>npart_2) count=npart_2;

   ans=ans+count*st[i].h;
   npart_2=npart_2-count;
   cnt[nom]=cnt[nom]-count;
  }

 }//i

 return ans;
}

using namespace std;

main(){
  scanf("%d %d",&n,&npart);
  s=0;
  for (i=0;i<n;i++){
   int ha,hb;
   scanf("%d %d %d",&k[i],&ha,&hb);
   st[n2].nom=i; st[n2].h=ha; st[n2].h1=ha; st[n2].h2=hb; st[n2++].type=1;
   st[n2].nom=i; st[n2].h=hb; st[n2].h1=hb; st[n2].h2=ha; st[n2++].type=2;
   s=s+k[i];
  }

 npitca=s/npart;
 if (npitca*npart<s) npitca++;
 //cout<<npitca<<" "<<s<<endl;

 sort(st,st+n2);

 a=0; b=npitca;
 while(a<b){
  c=a+(b-a)/3; d=b-(b-a)/3;

  fc=sum(c); fd=sum(d);

  if (fc==fd) a=c+1,b=d;   else
  if (fc<fd) a=c+1; else b=d-1;

 }

 cout<<sum(a)<<endl;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <cinttypes>
#include <cassert>
using namespace std;

struct eater {
  int64_t s,a,b;
  bool operator < (const eater &other) const{
    return (a-b) < (other.a-other.b);
  }
};

int main() {
  uint64_t N,S;
  cin >> N >> S;
  eater* eaters = new eater[N];
  uint64_t totalSlices = 0, posSlices = 0, negSlices = 0;
  uint64_t totalHappiness = 0, happA = 0, happB = 0;
  for(int i = 0; i < N; i++) {
    eater &e = eaters[i];
    cin >> e.s >> e.a >> e.b;
    happA += e.s*e.a;
    happB += e.s*e.b;
    if(e.a > e.b)
      posSlices += e.s;
    else if(e.b > e.a)
      negSlices += e.s;
    totalSlices += e.s;
  }
  sort(eaters, eaters+N);
  int BIndex = 0;
  int AIndex = N-1;
  auto consume = [&eaters, &happA, &happB, &posSlices, &negSlices, N] (int &iter, int step, int64_t useSlices, bool useA) -> uint64_t {
    int64_t tempHappiness = 0;
    while(useSlices > 0) {
      assert(iter >= 0);
      assert(iter < N);
      eater &e = eaters[iter];
      int64_t used = min(e.s, useSlices);
      e.s -= used;
      useSlices -= used;
      int64_t happiness = (useA) ? e.a:e.b;
      happA -= used*e.a;
      happB -= used*e.b;
      if(e.a > e.b)
        posSlices -= used;
      else if(e.b > e.a)
        negSlices -= used;
      tempHappiness+=used*happiness;
      if(e.s == 0)
        iter+=step;
    }
    return tempHappiness;
  };
  uint64_t useSlices = (posSlices/S)*S;
  totalHappiness += consume(AIndex, -1, useSlices, true);
  totalSlices -= useSlices;
  useSlices = (negSlices/S)*S;
  totalHappiness += consume(BIndex, 1, useSlices, false);
  totalSlices -= useSlices;
  if(totalSlices > S) {
    useSlices = posSlices;
    totalHappiness += consume(AIndex, -1, useSlices, true);
    totalSlices -= useSlices;
    totalHappiness += consume(BIndex, 1, totalSlices, false);
    totalSlices -= useSlices;
  } else {
    if(happA > happB)
      totalHappiness += consume(AIndex, -1, totalSlices, true);
    else
      totalHappiness += consume(BIndex, 1, totalSlices, false);
  }

  cout << totalHappiness << endl;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <cinttypes>
#include <cassert>
using namespace std;

struct eater {
  int s,a,b;
  bool operator < (const eater &other) const{
    return (a-b) < (other.a-other.b);
  }
};

int main() {
  uint64_t N,S;
  cin >> N >> S;
  eater* eaters = new eater[N];
  uint64_t totalSlices = 0;
  uint64_t posSlices = 0;
  uint64_t negSlices = 0;
  uint64_t happA = 0;
  uint64_t happB = 0;
  uint64_t totalHappiness = 0;
  for(int i = 0; i < N; i++) {
    eater &e = eaters[i];
    cin >> e.s >> e.a >> e.b;
    happA += e.s*e.a;
    happB += e.s*e.b;
    totalSlices += e.s;
  }
  sort(eaters, eaters+N);
  uint64_t useSlices = posSlices/S;
  int BIndex = 0;
  int AIndex = N-1;
  auto consume = [&eaters, &happA, &happB, N] (int &iter, int step, int useSlices, bool useA) -> uint64_t {
    uint64_t tempHappiness = 0;
    while(useSlices > 0) {
      assert(iter >= 0);
      assert(iter < N);
      uint64_t used = min(eaters[iter].s, useSlices);
      eaters[iter].s -= used;
      useSlices -= used;
      int happiness = (useA) ? eaters[iter].a:eaters[iter].b;
      happA -= used*eaters[iter].a;
      happB -= used*eaters[iter].b;
      tempHappiness+=used*happiness;
      if(eaters[iter].s == 0)
        iter+=step;
    }
    return tempHappiness;
  };
  while(totalSlices > 0) {
    bool useA = (happA > happB);
    useSlices = min(S, totalSlices);
    totalSlices -= useSlices;
    if(useA)
      totalHappiness += consume(AIndex,-1,useSlices,useA);
    else
      totalHappiness += consume(BIndex,1,useSlices,useA);
  }
  cout << totalHappiness << endl;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <cinttypes>
#include <cassert>
using namespace std;

struct eater {
  int64_t s,a,b;
  bool operator < (const eater &other) const{
    return (a-b) < (other.a-other.b);
  }
};

int main() {
  uint64_t N,S;
  cin >> N >> S;
  eater* eaters = new eater[N];
  uint64_t totalSlices = 0, posSlices = 0, negSlices = 0;
  uint64_t totalHappiness = 0, happA = 0, happB = 0;
  for(int i = 0; i < N; i++) {
    eater &e = eaters[i];
    cin >> e.s >> e.a >> e.b;
    happA += e.s*e.a;
    happB += e.s*e.b;
    if(e.a > e.b)
      posSlices += e.s;
    else if(e.b > e.a)
      negSlices += e.s;
    totalSlices += e.s;
  }
  sort(eaters, eaters+N);
  int BIndex = 0;
  int AIndex = N-1;
  auto consume = [&eaters, &happA, &happB, &posSlices, &negSlices, N] (int &iter, int step, int64_t useSlices, bool useA) -> uint64_t {
    int64_t tempHappiness = 0;
    while(useSlices > 0) {
      assert(iter >= 0);
      assert(iter < N);
      eater &e = eaters[iter];
      int64_t used = min(e.s, useSlices);
      e.s -= used;
      useSlices -= used;
      int64_t happiness = (useA) ? e.a:e.b;
      happA -= used*e.a;
      happB -= used*e.b;
      if(e.a > e.b)
        posSlices -= used;
      else if(e.b > e.a)
        negSlices -= used;
      tempHappiness+=used*happiness;
      if(e.s == 0)
        iter+=step;
    }
    return tempHappiness;
  };
  while(totalSlices > 0) {
    bool useA = (happA > happB);
    uint64_t useSlices = min(S, totalSlices);
    useSlices = (useA) ? max((posSlices/S)*S, useSlices): max((negSlices/S)*S, useSlices);
    if(posSlices == 0 && negSlices == 0)
      useSlices = totalSlices;
    totalSlices -= useSlices;
    if(useA)
      totalHappiness += consume(AIndex,-1,useSlices,useA);
    else
      totalHappiness += consume(BIndex,1,useSlices,useA);
  }
  cout << totalHappiness << endl;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <cinttypes>
#include <cassert>
using namespace std;

struct eater {
  int64_t s,a,b;
  bool operator < (const eater &other) const{
    return (a-b) < (other.a-other.b);
  }
};

int main() {
  uint64_t N,S;
  cin >> N >> S;
  eater* eaters = new eater[N];
  uint64_t totalSlices = 0, posSlices = 0, negSlices = 0;
  uint64_t totalHappiness = 0, happA = 0, happB = 0;
  for(int i = 0; i < N; i++) {
    eater &e = eaters[i];
    cin >> e.s >> e.a >> e.b;
    happA += e.s*e.a;
    happB += e.s*e.b;
    if(e.a > e.b)
      posSlices += e.s;
    else if(e.b > e.a)
      negSlices += e.s;
    totalSlices += e.s;
  }
  sort(eaters, eaters+N);
  int BIndex = 0;
  int AIndex = N-1;
  auto consume = [&eaters, &happA, &happB, &posSlices, &negSlices, N] (int &iter, int step, int64_t useSlices, bool useA) -> uint64_t {
    int64_t tempHappiness = 0;
    while(useSlices > 0) {
      assert(iter >= 0);
      assert(iter < N);
      eater &e = eaters[iter];
      int64_t used = min(e.s, useSlices);
      e.s -= used;
      useSlices -= used;
      int64_t happiness = (useA) ? e.a:e.b;
      happA -= used*e.a;
      happB -= used*e.b;
      if(e.a > e.b)
        posSlices -= used;
      else if(e.b > e.a)
        negSlices -= used;
      tempHappiness+=used*happiness;
      if(e.s == 0)
        iter+=step;
    }
    return tempHappiness;
  };
  uint64_t useSlices = (posSlices/S)*S;
  totalHappiness += consume(AIndex, -1, useSlices, true);
  totalSlices -= useSlices;
  useSlices = (negSlices/S)*S;
  totalHappiness += consume(BIndex, 1, useSlices, false);
  totalSlices -= useSlices;
  while(totalSlices > 0) {
    bool useA = (happA > happB);
     useSlices = min(S, totalSlices);
    if(posSlices == 0 && negSlices == 0)
      useSlices = totalSlices;
    totalSlices -= useSlices;
    if(useA)
      totalHappiness += consume(AIndex,-1,useSlices,useA);
    else
      totalHappiness += consume(BIndex,1,useSlices,useA);
  }
  cout << totalHappiness << endl;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <cinttypes>
#include <cassert>
using namespace std;

struct eater {
  int64_t s,a,b;
  bool operator < (const eater &other) const{
    return (a-b) < (other.a-other.b);
  }
};

int main() {
  uint64_t N,S;
  cin >> N >> S;
  eater* eaters = new eater[N];
  uint64_t totalSlices = 0;
  uint64_t posSlices = 0;
  uint64_t negSlices = 0;
  uint64_t happA = 0;
  uint64_t happB = 0;
  int64_t totalHappiness = 0;
  for(int i = 0; i < N; i++) {
    eater &e = eaters[i];
    cin >> e.s >> e.a >> e.b;
    happA += e.s*e.a;
    happB += e.s*e.b;
    totalSlices += e.s;
  }
  sort(eaters, eaters+N);
  int64_t useSlices = posSlices/S;
  int BIndex = 0;
  int AIndex = N-1;
  auto consume = [&eaters, &happA, &happB, N] (int &iter, int step, int64_t useSlices, bool useA) -> uint64_t {
    int64_t tempHappiness = 0;
    while(useSlices > 0) {
      assert(iter >= 0);
      assert(iter < N);
      int64_t used = min(eaters[iter].s, useSlices);
      eaters[iter].s -= used;
      useSlices -= used;
      int64_t happiness = (useA) ? eaters[iter].a:eaters[iter].b;
      happA -= used*eaters[iter].a;
      happB -= used*eaters[iter].b;
      tempHappiness+=used*happiness;
      if(eaters[iter].s == 0)
        iter+=step;
    }
    return tempHappiness;
  };
  while(totalSlices > 0) {
    bool useA = (happA > happB);
    useSlices = min(S, totalSlices);
    totalSlices -= useSlices;
    if(useA)
      totalHappiness += consume(AIndex,-1,useSlices,useA);
    else
      totalHappiness += consume(BIndex,1,useSlices,useA);
  }
  cout << totalHappiness << endl;
}


#include <iostream>
#include <utility>
#include <algorithm>
#include <cinttypes>
#include <cassert>
using namespace std;

struct eater {
  int64_t s,a,b;
  bool operator < (const eater &other) const{
    return (a-b) < (other.a-other.b);
  }
};

int main() {
  uint64_t N,S;
  cin >> N >> S;
  eater* eaters = new eater[N];
  uint64_t totalSlices = 0;
  uint64_t posSlices = 0;
  uint64_t negSlices = 0;
  uint64_t happA = 0;
  uint64_t happB = 0;
  int64_t totalHappiness = 0;
  for(int i = 0; i < N; i++) {
    eater &e = eaters[i];
    cin >> e.s >> e.a >> e.b;
    happA += e.s*e.a;
    happB += e.s*e.b;
    if(e.a > e.b)
      posSlices += e.s;
    else if(e.b > e.a)
      negSlices += e.s;
    totalSlices += e.s;
  }
  sort(eaters, eaters+N);
  int BIndex = 0;
  int AIndex = N-1;
  auto consume = [&eaters, &happA, &happB, &posSlices, &negSlices, N] (int &iter, int step, int64_t useSlices, bool useA) -> uint64_t {
    int64_t tempHappiness = 0;
    while(useSlices > 0) {
      assert(iter >= 0);
      assert(iter < N);
      int64_t used = min(eaters[iter].s, useSlices);
      eaters[iter].s -= used;
      useSlices -= used;
      int64_t happiness = (useA) ? eaters[iter].a:eaters[iter].b;
      happA -= used*eaters[iter].a;
      happB -= used*eaters[iter].b;
      if(eaters[iter].a > eaters[iter].b)
        posSlices -= used;
      else if(eaters[iter].b > eaters[iter].a)
        negSlices -= used;
      tempHappiness+=used*happiness;
      if(eaters[iter].s == 0)
        iter+=step;
    }
    return tempHappiness;
  };
  while(totalSlices > 0) {
    bool useA = (happA > happB);
    uint64_t useSlices = min(S, totalSlices);
    useSlices = (useA) ? max((posSlices/S)*S, useSlices): max((negSlices/S)*S, useSlices);
    totalSlices -= useSlices;
    if(useA)
      totalHappiness += consume(AIndex,-1,useSlices,useA);
    else
      totalHappiness += consume(BIndex,1,useSlices,useA);
  }
  cout << totalHappiness << endl;
}


#include <bits/stdc++.h>
using namespace std;
int N,R,sm;
int F[55],S[55],ss[55],sf[55];
int p[55];
double f[55][5005];
bool check(double rt)
{
	for(int i = R+1;i <= ss[N];i ++)
		f[N+1][i] = rt;
	for(int i = N;i >= 1;i --)
		for(int j = ss[i-1];j >= sf[i-1];j --)
			f[i][j] = min(rt,p[i]*(f[i+1][j+F[i]]+F[i])/100+(100-p[i])*(f[i+1][j+S[i]]+S[i])/100);
	if(f[1][0] < rt)
		return true;//too big
	return false;
}
int main()
{
	scanf("%d%d",&N,&R);
	for(int i = 1;i <= N;i ++)
	{
		scanf("%d%d%lf",&F[i],&S[i],&p[i]);
		sm += S[i];
		ss[i] = ss[i-1]+S[i];
		sf[i] = sf[i-1]+F[i];
	}
	double l = 0;double r = 1e9;
	while(r-l > 1e-9)
	{
		double mid = (l+r)/2;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	printf("%.10lf\n",l);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int N,R,sm;
int F[55],S[55],ss[55],sf[55];
double p[55];
double f[55][5005];
bool check(double rt)
{
	for(int i = R+1;i <= ss[N];i ++)
		f[N+1][i] = rt;
	for(int i = N;i >= 1;i --)
		for(int j = ss[i-1];j >= sf[i-1];j --)
			f[i][j] = min(rt,(p[i]*(f[i+1][j+F[i]]+F[i])+(100-p[i])*(f[i+1][j+S[i]]+S[i]))/100);
	if(f[1][0] < rt)
		return true;//too big
	return false;
}
int main()
{
	scanf("%d%d",&N,&R);
	for(int i = 1;i <= N;i ++)
	{
		scanf("%d%d%lf",&F[i],&S[i],&p[i]);
		sm += S[i];
		ss[i] = ss[i-1]+S[i];
		sf[i] = sf[i-1]+F[i];
	}
	double l = 0;double r = 1e9;
	while(r-l > 1e-10)
	{
		double mid = (l+r)/2;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	printf("%.10lf\n",l);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int N,R,sm;
int F[55],S[55],ss[55],sf[55];
double p[55];
double f[55][5005];
bool check(double rt)
{
	for(int i = R+1;i <= ss[N];i ++)
		f[N+1][i] = rt;
	for(int i = N;i >= 1;i --)
		for(int j = ss[i-1];j >= sf[i-1];j --)
			f[i][j] = min(rt,p[i]*(f[i+1][j+F[i]]+F[i])+(1-p[i])*(f[i+1][j+S[i]]+S[i]));
	if(f[1][0] < rt)
		return true;//too big
	return false;
}
int main()
{
	scanf("%d%d",&N,&R);
	for(int i = 1;i <= N;i ++)
	{
		scanf("%d%d%lf",&F[i],&S[i],&p[i]);
		p[i] /= 100;sm += S[i];
		ss[i] = ss[i-1]+S[i];
		sf[i] = sf[i-1]+F[i];
	}
	double l = 0;double r = 1e10;
	while(r-l > 4e-10)
	{
		double mid = (l+r)/2;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	printf("%.10lf\n",l);
	return 0;
}


#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define rg register
using namespace std;
int N,R,sm;
int F[55],S[55],ss[55],sf[55];
double p[55];
double f[55][5005];
inline bool check(double k)
{
	for(rg int i = N;i >= 1;i --)
	{
    	for(rg int j = R+1;j < 5005;j ++)
			f[i+1][j] = k;
    	for(rg int j = 0;j <= R;j ++)
			f[i][j] = min((f[i+1][j+F[i]]+F[i])*p[i]/100.0+(f[i+1][j+S[i]]+S[i])*(100.0-p[i])/100.0,k);
	}
	return f[1][0] < k;
}

int main()
{
	scanf("%d%d",&N,&R);
	for(rg int i = 1;i <= N;i ++)
	{
		scanf("%d%d%lf",&F[i],&S[i],&p[i]);
		sm += S[i];
		ss[i] = ss[i-1]+S[i];
		sf[i] = sf[i-1]+F[i];
	}
	double l = 0;double r = 1e9;
	while(r-l > 1e-10)
	{
		double mid = (l+r)/2;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	printf("%.10lf\n",l);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int N,R,sm;
int F[55],S[55],ss[55],sf[55];
double p[55];
double f[55][5005];
bool check(double rt)
{
	for(int i = R+1;i <= ss[N];i ++)
		f[N+1][i] = rt;
	for(int i = N;i >= 1;i --)
		for(int j = ss[i-1];j >= sf[i-1];j --)
			f[i][j] = min(rt,p[i]*(f[i+1][j+F[i]]+F[i])+(1-p[i])*(f[i+1][j+S[i]]+S[i]));
	if(f[1][0] < rt)
		return true;//too big
	return false;
}
int main()
{
	scanf("%d%d",&N,&R);
	for(int i = 1;i <= N;i ++)
	{
		scanf("%d%d%lf",&F[i],&S[i],&p[i]);
		p[i] /= 100;sm += S[i];
		ss[i] = ss[i-1]+S[i];
		sf[i] = sf[i-1]+F[i];
	}
	double l = 0;double r = 1e10;
	while(r-l > 1e-10)
	{
		double mid = (l+r)/2;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	printf("%.10lf\n",l);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int N,R,sm;
int F[55],S[55],ss[55],sf[55];
double p[55];
double f[55][5005];
bool check(double rt)
{
	for(int i = R+1;i <= ss[N];i ++)
		f[N+1][i] = rt;
	for(int i = N;i >= 1;i --)
		for(int j = ss[i-1];j >= sf[i-1];j --)
			f[i][j] = min(rt,p[i]*(f[i+1][j+F[i]]+F[i])+(1-p[i])*(f[i+1][j+S[i]]+S[i]));
	if(f[1][0] < rt)
		return true;//too big
	return false;
}
int main()
{
	scanf("%d%d",&N,&R);
	for(int i = 1;i <= N;i ++)
	{
		scanf("%d%d%lf",&F[i],&S[i],&p[i]);
		p[i] /= 100;sm += S[i];
		ss[i] = ss[i-1]+S[i];
		sf[i] = sf[i-1]+F[i];
	}
	double l = 0;double r = 1e10;
	while(r-l > 1e-9)
	{
		double mid = (l+r)/2;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	printf("%.10lf\n",l);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int N,R,sm;
int F[55],S[55],ss[55],sf[55];
int p[55];
double f[55][5005];
bool check(double rt)
{
	for(int i = R+1;i <= ss[N];i ++)
		f[N+1][i] = rt;
	for(int i = N;i >= 1;i --)
		for(int j = ss[i-1];j >= sf[i-1];j --)
			f[i][j] = min(rt,p[i]*(f[i+1][j+F[i]]+F[i])/100+(100-p[i])*(f[i+1][j+S[i]]+S[i])/100);
	if(f[1][0] < rt)
		return true;//too big
	return false;
}
int main()
{
	scanf("%d%d",&N,&R);
	for(int i = 1;i <= N;i ++)
	{
		scanf("%d%d%lf",&F[i],&S[i],&p[i]);
		p[i] /= 100;sm += S[i];
		ss[i] = ss[i-1]+S[i];
		sf[i] = sf[i-1]+F[i];
	}
	double l = 0;double r = 1e9;
	while(r-l > 1e-9)
	{
		double mid = (l+r)/2;
		if(check(mid))
			r = mid;
		else
			l = mid;
	}
	printf("%.10lf\n",l);
	return 0;
}


#include<stdio.h>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#define Gc (p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?0:*p1++)
using namespace std;
char buf[1<<20],*p1,*p2;
inline int _r()
{
	char c=Gc;int d=0,f=0;
	while(c>'9'||c<'0')f=c=='-'?1:f,c=Gc;
	while(c<='9'&&c>='0')d=(d<<3)+(d<<1)+c-'0',c=Gc;
	return f?-d:d;
}
const int N=5050;
typedef double db;
typedef long long ll;
const db inf=1e9;
int n,m,a[N],b[N],p[N];
db dp[52][5050],now;
bool mark[52][5050];
void _init()
{
	memset(mark,0,sizeof(mark));
}
db dfs(int i,int j)
{
	if(j>m)return now;
	if(mark[i][j])return dp[i][j];
	mark[i][j]=true;
	db p1=0.01*p[i+1],p2=1.0-p1;
	dp[i][j]=(dfs(i+1,j+a[i+1])+a[i+1])*p1+(dfs(i+1,j+b[i+1])+b[i+1])*p2;
	if(i)dp[i][j]=min(dp[i][j],now);
	return dp[i][j];
}
bool check(db mid)
{
	memset(mark,0,sizeof(mark));
	int i,j;
	for(i=1;i<=m;i++)mark[n][i]=true;
	now=mid;
	return dfs(0,0)<mid;
}
int main()
{
	int i,j,k;
	n=_r();m=_r();
	for(i=1;i<=n;i++)
	{
		a[i]=_r();b[i]=_r();p[i]=_r();
	}
	db L=0,R=1e8,mid;
	while(fabs(R-L)>1e-8)
	{
		mid=(L+R)*0.5;
		if(check(mid))R=mid;
		else L=mid;
	}
	printf("%.8lf",(L+R)*0.5);
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e20;
    for (int precision = 0; precision < 120; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << fixed << setprecision(10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e12;
    for (int precision = 0; precision < 170; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return down;
}

void testcase() {
    read();
    cout << fixed << setprecision(10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e12;
    for (int precision = 0; precision < 200; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << fixed << setprecision(10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e10;
    for (int precision = 0; precision < 200; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e15;
    for (int precision = 0; precision < 200; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(std::numeric_limits<double>::max_digits10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e9;
    for (int precision = 0; precision < 150; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return down;
}

void testcase() {
    read();
    cout << fixed << setprecision(10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e12;
    for (int precision = 0; precision < 200; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e11;
    for (int precision = 0; precision < 200; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(std::numeric_limits<double>::max_digits10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e12;
    for (int precision = 0; precision < 200; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(14) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e12;
    for (int precision = 0; precision < 300; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(14) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e12;
    for (int precision = 0; precision < 150; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return down;
}

void testcase() {
    read();
    cout << fixed << setprecision(10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e15;
    for (int precision = 0; precision < 100; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(std::numeric_limits<double>::max_digits10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e10;
    for (int precision = 0; precision < 150; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(std::numeric_limits<double>::max_digits10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e10;
    for (int precision = 0; precision < 200; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(std::numeric_limits<double>::max_digits10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using VI = vector<int>;
using VD = vector<double>;
using VVD = vector<VD>;

int N, R;
VI F, S;
VD P;

void read() {
    cin >> N >> R;
    F.resize(N);
    S.resize(N);
    P.resize(N);
    for (int i = 0; i < N; ++i)
        cin >> F[i] >> S[i] >> P[i];
    for (auto& p : P)
        p /= 100.;
}

double solve() {
    double down = 0., up = 1e10;
    for (int precision = 0; precision < 100; ++precision) {
        VVD Exp(N + 1, VD(R + 1, 0));
        double K = (down + up) / 2;

        for (int lvl = N - 1; lvl >= 0; --lvl)
            for (int elapsed = 0; elapsed <= R; ++elapsed) {
                if (elapsed + F[lvl] > R) Exp[lvl][elapsed] = K;
                else {
                    double onSuccess = F[lvl] + Exp[lvl + 1][elapsed + F[lvl]];
                    double onFailure = (elapsed + S[lvl] > R) ? S[lvl] + K :
                                       S[lvl] + Exp[lvl + 1][elapsed + S[lvl]];
                    Exp[lvl][elapsed] = min(K, P[lvl] * onSuccess + (1. - P[lvl]) * onFailure);
                }
            }

        if (Exp[0][0] < K) up = K;
        else down = K;
    }
    return up;
}

void testcase() {
    read();
    cout << setprecision(std::numeric_limits<double>::max_digits10) << solve() << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    testcase();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 51, M = 6000;
double f[N][M], P[N];
int n, R, F[N], S[N];

int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d %d", &n, &R);
  for(int i = 0; i < n; ++i) {
    int p;
    scanf("%d %d %d", &F[i], &S[i], &p);
    P[i] = p / 100.0;
  }

  for(int i = 0; i < n; ++i)
    for(int j = 0; j <= R; ++j)
      f[i][j] = 1e9;

  double st = clock();
  while((clock() - st) / 1e6 < 1.8) {
    for(int i = n - 1; i >= 0; --i) {
      for(int t = R + 1; t <= R + 100; ++t)
        f[i + 1][t] = f[0][0];
      for(int t = 0; t <= R; ++t) {
        f[i][t] = P[i] * (F[i] + f[i + 1][t + F[i]]) +
             (1 - P[i])* (S[i] + f[i + 1][t + S[i]]);
        if(i) f[i][t] = min(f[i][t], f[0][0]);
      }
    }
  }

  printf("%.9f\n", f[0][0]);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 51, M = 6000;
double f[N][M], P[N];
int n, R, F[N], S[N];

bool check(double f00) {
  for(int i = 0; i <= R; ++i)
    f[n][i] = i <= R ? 0 : f00;

  for(int i = n - 1; i >= 0; --i) {
    for(int t = 0; t <= R; ++t) {
      f[i][t] = P[i] * (F[i] + (t + F[i] <= R ? f[i + 1][t + F[i]] : f00)) +
           (1 - P[i])* (S[i] + (t + S[i] <= R ? f[i + 1][t + S[i]] : f00));
      if(i) f[i][t] = min(f[i][t], f00);
    }
  }
  return f[0][0] < f00;

}
int main() {
  scanf("%d %d", &n, &R);
  for(int i = 0; i < n; ++i) {
    int p;
    scanf("%d %d %d", &F[i], &S[i], &p);
    P[i] = p / 100.0;
  }

  double lo = 0, hi = 1e9;
  while(fabs(hi - lo) > 1e-9) {
    double mid = (hi + lo) / 2;
    if(check(mid)) hi = mid;
    else lo = mid;
  }

  printf("%.10f\n", lo);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 51, M = 5010;
double f[N][M], P[N], df[N][M];
int n, R, F[N], S[N];

double newton(double x) {
  for(int i = n - 1; i >= 0; --i) {
    for(int t = 0; t <= R; ++t) {
      f[i][t] = P[i] * (F[i] + (t + F[i] <= R ? f[i + 1][t + F[i]] : x)) +
           (1 - P[i])* (S[i] + (t + S[i] <= R ? f[i + 1][t + S[i]] : x));
      df[i][t] = P[i] * (t + F[i] <= R ? df[i + 1][t + F[i]] : 1) +
            (1 - P[i])* (t + S[i] <= R ? df[i + 1][t + S[i]] : 1);
      if(i && x < f[i][t]) f[i][t] = x, df[i][t] = 1;
    }
  }
  return x - (x - f[0][0]) / (1 - df[0][0]);
}

int main() {
  scanf("%d %d", &n, &R);
  for(int i = 0; i < n; ++i) {
    int p;
    scanf("%d %d %d", &F[i], &S[i], &p);
    P[i] = p / 100.0;
  }

  double x = 1e9;
  for(int iter = 0; iter < 4; ++iter)
    x = newton(x);

  printf("%.10f\n", x);

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 51, M = 6000;
double f[N][M], P[N];
int n, R, F[N], S[N];

int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d %d", &n, &R);
  for(int i = 0; i < n; ++i) {
    int p;
    scanf("%d %d %d", &F[i], &S[i], &p);
    P[i] = p / 100.0;
  }

  for(int i = 0; i < n; ++i)
    for(int j = 0; j <= R; ++j)
      f[i][j] = 1e9;

  double st = clock();
  while((clock() - st) / 1e6 < 1.9) {
    for(int i = n - 1; i >= 0; --i) {
      for(int t = R + 1; t <= R + 100; ++t)
        f[i + 1][t] = f[0][0];
      for(int t = 0; t <= R; ++t) {
        f[i][t] = P[i] * (F[i] + f[i + 1][t + F[i]]) +
             (1 - P[i])* (S[i] + f[i + 1][t + S[i]]);
        if(i) f[i][t] = min(f[i][t], f[0][0]);
      }
    }
  }

  printf("%.9f\n", f[0][0]);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 51, M = 5010;
double f[N][M], P[N];
int n, R, F[N], S[N];

bool check(double f00) {
  for(int i = 0; i <= R; ++i)
    f[n][i] = i <= R ? 0 : f00;

  for(int i = n - 1; i >= 0; --i) {
    for(int t = 0; t <= R; ++t) {
      f[i][t] = P[i] * (F[i] + (t + F[i] <= R ? f[i + 1][t + F[i]] : f00)) +
           (1 - P[i])* (S[i] + (t + S[i] <= R ? f[i + 1][t + S[i]] : f00));
      if(i) f[i][t] = min(f[i][t], f00);
    }
  }
  return f[0][0] < f00;

}
int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d %d", &n, &R);
  for(int i = 0; i < n; ++i) {
    int p;
    scanf("%d %d %d", &F[i], &S[i], &p);
    P[i] = p / 100.0;
  }

  double lo = 0, hi = 1e9;
  for(int st = 0; st <= 80; ++st) {
    double mid = (hi + lo) / 2;
    if(check(mid)) hi = mid;
    else lo = mid;
  }

  printf("%.10f\n", lo);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 51, M = 6000;
double f[N][M], P[N];
int n, R, F[N], S[N];

bool check(double f00) {
  for(int i = 0; i <= R + 100; ++i)
    f[n][i] = i <= R ? 0 : f00;

  for(int i = n - 1; i >= 0; --i) {
    for(int t = 0; t <= R; ++t) {
      f[i][t] = P[i] * (F[i] + f[i + 1][t + F[i]]) +
           (1 - P[i])* (S[i] + f[i + 1][t + S[i]]);
      if(i) f[i][t] = min(f[i][t], f00);
    }
  }
  return f[0][0] < f00;

}
int main() {
  scanf("%d %d", &n, &R);
  for(int i = 0; i < n; ++i) {
    int p;
    scanf("%d %d %d", &F[i], &S[i], &p);
    P[i] = p / 100.0;
  }

  for(int i = 0; i < n; ++i)
    for(int j = 0; j <= R; ++j)
      f[i][j] = 1e9;

  double lo = 0, hi = 1e9;
  while(fabs(hi - lo) > 1e-9) {
    double mid = (hi + lo) / 2;
    if(check(mid)) hi = mid;
    else lo = mid;
  }

  printf("%.9f\n", lo);
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int N = 51, M = 6000;
double f[N][M], P[N];
int n, R, F[N], S[N];

bool check(double f00) {
  for(int i = 0; i <= R + 200; ++i)
    f[n][i] = i <= R ? 0 : f00;

  for(int i = n - 1; i >= 0; --i) {
    for(int t = 0; t <= R + 100; ++t) {
      f[i][t] = P[i] * (F[i] + f[i + 1][t + F[i]]) +
           (1 - P[i])* (S[i] + f[i + 1][t + S[i]]);
      if(i) f[i][t] = min(f[i][t], f00);
    }
  }
  return f[0][0] < f00;

}
int main() {
  scanf("%d %d", &n, &R);
  for(int i = 0; i < n; ++i) {
    int p;
    scanf("%d %d %d", &F[i], &S[i], &p);
    P[i] = p / 100.0;
  }

  double lo = 0, hi = 1e9;
  while(fabs(hi - lo) > 1e-9) {
    double mid = (hi + lo) / 2;
    if(check(mid)) hi = mid;
    else lo = mid;
  }

  printf("%.10f\n", lo);
  return 0;
}


#include<iostream>
#include<cstdio>
#include<ctime>
using namespace std;
const long double eps=1e-9;
const int N=55,M=5005;
int n,R;
long double dp[N][M];
int a[N],b[N],p[N];
bool check(long double x)
{
    for(int i=n;i>0;i--)
    {
        for(int j=R+1;j<M;j++)
            dp[i+1][j]=x;
        for(int j=0;j<=R;j++)
            dp[i][j]=min(x,(dp[i+1][j+a[i]]+a[i])*p[i]/100+(dp[i+1][j+b[i]]+b[i])*(100-p[i])/100);
    }
    return dp[1][0]<x;
}
int main()
{
    scanf("%d%d",&n,&R);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&a[i],&b[i],&p[i]);
    long double l=0,r=1e10;
    int start=clock();
    while(r-l>=eps)
    {
        long double mid=(l+r)/2;
        if(check(mid)) r=mid;
        else l=mid;
    }
    printf("%.9Lf",l);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<ctime>
using namespace std;
const long double eps=1e-9;
const int N=55,M=5005;
int n,R;
long double dp[N][M];
int a[N],b[N],p[N];
bool check(long double x)
{
    for(int i=n;i>0;i--)
    {
        for(int j=R+1;j<M;j++)
            dp[i+1][j]=x;
        for(int j=0;j<=R;j++)
            dp[i][j]=min(x,(dp[i+1][j+a[i]]+a[i])*p[i]/100+(dp[i+1][j+b[i]]+b[i])*(100-p[i])/100);
    }
    return dp[1][0]<x;
}
int main()
{
    scanf("%d%d",&n,&R);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&a[i],&b[i],&p[i]);
    long double l=0,r=1e10;
    int start=clock();
    while(r-l>=eps)
    {
        long double mid=(l+r)/2;
        if(check(mid)) r=mid;
        else l=mid;
        // if((double)(clock()-start)/CLOCKS_PER_SEC>1.9) break;
    }
    printf("%.9Lf",l);
    return 0;
}


#include<iostream>
#include<cstring>
#include<memory>
#include<iomanip>
using namespace std;
int n,m;
int a[55],b[55],p[55];
double dp[55][5005];
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>p[i];
	double l=0,r=1e9;
	while(l+1e-12<r){
		memset(dp,0,sizeof(dp));
		double mid=(l+r)/2;
		for(int i=n-1;~i;i--){
			for(int u=5004;u>m;u--)dp[i+1][u]=mid;
			for(int u=0;u<=m;u++)dp[i][u]=min((dp[i+1][u+a[i]]+a[i])*p[i]/100.0l+(dp[i+1][u+b[i]]+b[i])*(100-p[i])/100.0l,static_cast<long double>(mid));
		}
		if(dp[0][0]<mid)r=mid;
		else l=mid;
	}
	printf("%.9f",r);
}


#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 55;
const int maxr = 5500;

int n;
double R;
double f[maxn], s[maxn], p[maxn];

double dp[maxn][maxr];
//expected time to finish last i levels, r secs elapsed so far

void reset() {
    for (int i=0; i<=n; i++) {
	for (int j=0; j<maxr; j++) {
	    dp[i][j]=0;
	}
    }
}

double get(double t) {
    reset();
    for (int i=n-1; i>=0; i--) {
	for (int r=0; r<=R; r++) {
	    double& cur = dp[i][r] = 0;
	    if (r+f[i]<=R) {
		cur += p[i]*(f[i]+dp[i+1][int(r+f[i])]);

		//if can afford to go slow, compute expected finish
		if (r+s[i]<=R) {
		    cur += (1-p[i])*(s[i]+dp[i+1][int(r+s[i])]);
		} else {
		    cur += (1-p[i])*(s[i]+t);
		}

		//maybe it was actually better to just restart
		cur=min(cur, t);
	    } else {
		//won't finish in time, just restart
		cur=t;
	    }
	}
    }
    return dp[0][0];
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n;
    cin>>R;
    for (int i=0; i<n; i++) {
	cin>>f[i]>>s[i]>>p[i];
	p[i]=p[i]/100;
    }

    double lo = 0;
    double hi = 1e9;
    for (int iter=0; iter<500; iter++) {
	double mid = (lo+hi)/2;
	if (get(mid)<mid) {
	    hi = mid;
	} else {
	    lo = mid;
	}
    }

    cout<<fixed<<setprecision(12)<<lo<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
    char a[550][550];
    bool used[550][550];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int first;
    int starti , startj , endi,endj, n , m;
    bool found;
    void dfs(int x ,int y)
    {
        used[x][y] = 1;
        if(x == endi and y == endj and first == 2)
        {
            first--;
        }
        for(int i = 0 ; i < 4;i++)
        {
            int X = dx[i] + x;
            int Y = dy[i] + y;
            if(X >= 1 and X <= n and Y >= 1 and Y <= m)
            {
                if(X == endi and Y == endj and first == 1 and used[X][Y])
                {
                found = true;
                }
                if(!used[X][Y])
                dfs(X,Y);
            }

        }
    }
    main()
    {
        cin >> n >> m;

        for(int i = 1 ; i <= n;i++)
        {
            for(int j = 1 ; j <= m;j++)
            {
                cin >> a[i][j];
                if(a[i][j] == 'X')used[i][j] = 1;
            }
        }
        cin >> starti >> startj >> endi >> endj;
        if(a[endi][endj] == 'X'){first = 1; used[endi][endj] = 1;}
        else first = 2;
        dfs(starti,startj);
        cout << (found ? "YES" : "NO");

    }


#include<bits/stdc++.h>
#define int long long
using namespace std;
    char a[550][550];
    bool used[550][550];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int first;
    int starti , startj , endi,endj, n , m;
    bool found;
    int cnt;
    void dfs(int x ,int y)
    {
        a[x][y] = 'X';

        for(int i = 0 ; i < 4;i++)
        {
            int X = x + dx[i];
            int Y = y + dy[i];
            if(X >= 1 and X <= n and Y >= 1 and Y <= m)
            {
                if(X == endi and Y == endj and a[X][Y] == 'X')
                {
                    found = true;
                }
                if(a[X][Y] == '.')
                    dfs(X,Y);

            }

        }

    }
    main()
    {
        cin >> n >> m;

        for(int i = 1 ; i <= n;i++)
        {
            for(int j = 1 ; j <= m;j++)
            {
                cin >> a[i][j];
            }
        }
        cin >> starti >> startj >> endi >> endj;
        dfs(starti,startj);
        cout << (found ? "YES" : "NO");

    }


#include<bits/stdc++.h>
#define int long long
using namespace std;
    char a[550][550];
    bool used[550][550];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int first;
    int starti , startj , endi,endj, n , m;
    bool found;
    void dfs(int x ,int y)
    {
        used[x][y] = 1;
        if(x == endi and y == endj and first == 1)
        {
            found = true;
            return;
        }
        if(x == endi and y == endj and first == 2)
        {
          //  cout <<"birmarta" << x <<" "<< y << endl;
            used[endi][endj] = 0;
            first--;
        }
        for(int i = 0 ; i < 4;i++)
        {
            int X = dx[i] + x;
            int Y = dy[i] + y;
            if(X >= 1 and X <= n and Y >= 1 and Y <= m and !used[X][Y] and a[X][Y] != 'X')
            {
                dfs(X,Y);
            }

        }
    }
    main()
    {
        cin >> n >> m;
        for(int i = 1 ; i <= n;i++)
        {
            for(int j = 1 ; j <= m;j++)
            {
                cin >> a[i][j];
            }
        }
        cin >> starti >> startj >> endi >> endj;
        if(a[endi][endj] =='X') {first = 1;a[endi][endj] = '.';}
        else first = 2;
        dfs(starti,startj);
        cout << (found ? "YES" : "NO");

    }


#include<bits/stdc++.h>
#define int long long
using namespace std;
    char a[550][550];
    bool used[550][550];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int first;
    int starti , startj , endi,endj, n , m;
    bool found;
    int cnt;
    void dfs(int x ,int y)
    {
        used[x][y] = 1;
        if(x == endi and y == endj and first == 1 and cnt >= 1)
        {
                found = true;
                first = 0;
        }
        if(x == endi and y == endj and first == 2)
        {

            used[endi][endj] = 0;
            first--;
        }
        for(int i = 0 ; i < 4;i++)
        {
            int X = dx[i] + x;
            int Y = dy[i] + y;
            if(X >= 1 and X <= n and Y >= 1 and Y <= m and !used[X][Y] and a[X][Y] != 'X')
            {
                cnt++;
                dfs(X,Y);
            }

        }
    }
    main()
    {
        cin >> n >> m;

        for(int i = 1 ; i <= n;i++)
        {
            for(int j = 1 ; j <= m;j++)
            {
                cin >> a[i][j];
            }
        }
        cin >> starti >> startj >> endi >> endj;
        if(a[endi][endj] =='X'){first = 1;a[endi][endj] = '.';}
        else first = 2;
        dfs(starti,startj);
        cout << (found ? "YES" : "NO");

    }


#include<bits/stdc++.h>
#define int long long
using namespace std;
    char a[550][550];
    bool used[550][550];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int first;
    int starti , startj , endi,endj, n , m;
    bool found;
    void dfs(int x ,int y)
    {
        used[x][y] = 1;
        if(x == endi and y == endj and first == 1)
        {
                found = true;
                return ;
        }
        if(x == endi and y == endj and first == 2)
        {

            used[endi][endj] = 0;
            first--;
        }
        for(int i = 0 ; i < 4;i++)
        {
            int X = dx[i] + x;
            int Y = dy[i] + y;
            if(X >= 1 and X <= n and Y >= 1 and Y <= m and !used[X][Y] and a[X][Y] != 'X')
            {
                dfs(X,Y);
            }

        }
    }
    main()
    {
        cin >> n >> m;
        for(int i = 1 ; i <= n;i++)
        {
            for(int j = 1 ; j <= m;j++)
            {
                cin >> a[i][j];
            }
        }
        cin >> starti >> startj >> endi >> endj;
        if(a[endi][endj] =='X'){first = 1;a[endi][endj] = '.';}
        else first = 2;
        dfs(starti,startj);
        cout << (found ? "YES" : "NO");

    }


#include<bits/stdc++.h>
#define int long long
using namespace std;
    char a[550][550];
    bool used[550][550];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int first;
    int starti , startj , endi,endj, n , m;
    bool found;
    void dfs(int x ,int y)
    {
        used[x][y] = 1;
        if(x == endi and y == endj and first == 1)
        {
                found = true;
                first = 0;
        }
        if(x == endi and y == endj and first == 2)
        {

            used[endi][endj] = 0;
            first--;
        }
        for(int i = 0 ; i < 4;i++)
        {
            int X = dx[i] + x;
            int Y = dy[i] + y;
            if(X >= 1 and X <= n and Y >= 1 and Y <= m and !used[X][Y] and a[X][Y] != 'X')
            {
                dfs(X,Y);
            }

        }
    }
    main()
    {
        cin >> n >> m;
        for(int i = 1 ; i <= n;i++)
        {
            for(int j = 1 ; j <= m;j++)
            {
                cin >> a[i][j];
            }
        }
        cin >> starti >> startj >> endi >> endj;
        if(a[endi][endj] =='X'){first = 1;a[endi][endj] = '.';}
        else first = 2;
        dfs(starti,startj);
        cout << (found ? "YES" : "NO");

    }


#include<bits/stdc++.h>
#define int long long
using namespace std;
    char a[550][550];
    bool used[550][550];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int first;
    int starti , startj , endi,endj, n , m;
    bool found;
    void dfs(int x ,int y)
    {
        used[x][y] = 1;
        if(x == endi and y == endj and first == 1)
        {
                found = true;
                first = 0;
        }
        if(x == endi and y == endj and first == 2)
        {

            used[endi][endj] = 0;
            first--;
        }
        for(int i = 0 ; i < 4;i++)
        {
            int X = dx[i] + x;
            int Y = dy[i] + y;
            if(X >= 1 and X <= n and Y >= 1 and Y <= m and !used[X][Y] and a[X][Y] != 'X')
            {
                dfs(X,Y);
            }

        }
    }
    main()
    {
        cin >> n >> m;

        for(int i = 1 ; i <= n;i++)
        {
            for(int j = 1 ; j <= m;j++)
            {
                cin >> a[i][j];
            }
        }
        cin >> starti >> startj >> endi >> endj;
        if(starti == startj and  endi == endj and starti == endi and a[endi][endj] and n == m)return cout <<"NO",0;
        if(a[endi][endj] =='X'){first = 1;a[endi][endj] = '.';}
        else first = 2;
        dfs(starti,startj);
        cout << (found ? "YES" : "NO");

    }


#include<bits/stdc++.h>
#define int long long
using namespace std;
    char a[550][550];
    bool used[550][550];
    int dx[] = {1,-1,0,0};
    int dy[] = {0,0,1,-1};
    int first;
    int starti , startj , endi,endj, n , m;
    bool found;
    void dfs(int x ,int y)
    {
        used[x][y] = 1;
        if(x == endi and y == endj and first == 1)
        {
                found = true;
                first = 0;
        }
        if(x == endi and y == endj and first == 2)
        {

            used[endi][endj] = 0;
            first--;
        }
        for(int i = 0 ; i < 4;i++)
        {
            int X = dx[i] + x;
            int Y = dy[i] + y;
            if(X >= 1 and X <= n and Y >= 1 and Y <= m and !used[X][Y] and a[X][Y] != 'X')
            {
                dfs(X,Y);
            }

        }
    }
    main()
    {
        cin >> n >> m;

        for(int i = 1 ; i <= n;i++)
        {
            for(int j = 1 ; j <= m;j++)
            {
                cin >> a[i][j];
            }
        }
        cin >> starti >> startj >> endi >> endj;
        if(starti == startj and  endi == endj and starti == endi and a[endi][endj])return cout <<"NO",0;
        if(a[endi][endj] =='X'){first = 1;a[endi][endj] = '.';}
        else first = 2;
        dfs(starti,startj);
        cout << (found ? "YES" : "NO");

    }