It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices.

It is known that the i-th contestant will eat si slices of pizza, and gain ai happiness for each slice of type 1 pizza they eat, and bi happiness for each slice of type 2 pizza they eat. We can order any number of type 1 and type 2 pizzas, but we want to buy the minimum possible number of pizzas for all of the contestants to be able to eat their required number of slices. Given that restriction, what is the maximum possible total happiness that can be achieved?

Input

The first line of input will contain integers N and S (1 ≤ N ≤ 105, 1 ≤ S ≤ 105), the number of contestants and the number of slices per pizza, respectively. N lines follow.

The i-th such line contains integers si, ai, and bi (1 ≤ si ≤ 105, 1 ≤ ai ≤ 105, 1 ≤ bi ≤ 105), the number of slices the i-th contestant will eat, the happiness they will gain from each type 1 slice they eat, and the happiness they will gain from each type 2 slice they eat, respectively.

Output

Print the maximum total happiness that can be achieved.

Examples

Input

3 12
3 5 7
4 6 7
5 9 5


Output

84


Input

6 10
7 4 7
5 8 8
12 5 8
6 11 6
3 3 7
5 9 6


Output

314

Note

In the first example, you only need to buy one pizza. If you buy a type 1 pizza, the total happiness will be 3·5 + 4·6 + 5·9 = 84, and if you buy a type 2 pizza, the total happiness will be 3·7 + 4·7 + 5·5 = 74.
import java.io.*;
import java.util.*;
import java.math.*;
import java.util.concurrent.*;

public final class memf_c
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();
	
    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long s=sc.nextLong();
		
		Pair[] a=new Pair[n+1];long tot=0;
		
		for(int i=1;i<=n;i++)
		{
			a[i]=new Pair(sc.nextInt(),sc.nextInt(),sc.nextInt());
			
			tot+=a[i].val;
		}
		
		long xx=(tot/s)+(tot%s==0?0:1),max=0;
	
		for(int v=0;v<2;v++)
		{
			Arrays.sort(a,1,n+1);long res=0;
			
			for(int i=1;i<=n;i++)
			{
				res=res+(a[i].first*a[i].val);
			}

			max=Math.max(max,res);long now=0;

			long[] pre=new long[n+1];

			long sum1=0,sum2=0;

			for(int i=1;i<=n;i++)
			{
				sum1=sum1+(a[i].val*a[i].second);

				sum2=sum2+(a[i].val*a[i].first);

				pre[i]=sum1-sum2;
			}

			long[] sums=new long[n+1];sum1=0;

			for(int i=1;i<=n;i++)
			{
				sum1=sum1+a[i].val;

				sums[i]=sum1;
			}

			for(int i=1;i<=n;i++)
			{
				now+=a[i].val;long curr=tot-now;

				long yy=(curr/s)+(curr%s==0?0:1);

				long left=(xx-yy)*s;

				int low=0,high=i;

				while(low<high)
				{
					int mid=(low+high+1)>>1;

					if(sums[mid]<=left)
					{
						low=mid;
					}
					else
					{
						high=mid-1;
					}
				}

				left-=(sums[low]);long add=0;

				if(left>0 && low+1<=i)
				{
					add=(Math.min(left,a[low+1].val)*a[low+1].second)-(Math.min(left,a[low+1].val)*a[low+1].first);
				}

				long zz=res+pre[low]+add;max=Math.max(max,zz);
			}
			
			for(int i=1;i<=n;i++)
			{
				long temp=a[i].first;a[i].first=a[i].second;a[i].second=temp;
			}
		}
	
		out.println(max);out.close();
    }
	
	private static class Pair implements Comparable<Pair>
	{
		long val,first,second;
		
		public Pair(long val,long first,long second)
		{
			this.val=val;this.first=first;this.second=second;
		}
		
		public int compareTo(Pair x)
		{
			return -(Long.compare(this.second-this.first,x.second-x.first));
		}
	}
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }
	
    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
	
	public String next() throws Exception {
		return nextToken().toString();
	}
	
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}