using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N, X;
        public long[] B, L, U;
        public long MOD = 1000000007;
        private Data[] D;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                X = line[1];
            }

            B = new long[N];
            L = new long[N];
            U = new long[N];

            var lst = new List<Data>();

            for (int i = 0; i < N; i++)
            {
                var line = Input.ReadIntArray();
                B[i] = line[0];
                L[i] = line[1];
                U[i] = line[2];
                Data D = new Data(B[i], L[i], U[i]);
                lst.Add(D);
            }

            D = lst.ToArray();
            Array.Sort(D, (d1, d2) => Score(d1, X).CompareTo(Score(d2, X)) * (-1));

            long ret = Search();
            Console.WriteLine(ret);
        }

        public bool CanWin(long study)
        {
            // 相手
            long opponent = 0;
            for (int i = 0; i < D.Length; i++)
            {
                opponent += D[i].b * D[i].l;
            }

            // Z個をまず選択する
            int Z = (int)(study / X);
            long R = study - Z * X;

            // スコア
            long player = 0;

            // 上からZ個とる
            for (int i = 0; i < Z; i++)
            {
                Data d = D[i];
                long scoreX = d.b * d.l + (X - d.b) * d.u;
                player += scoreX;
            }

            long addition = 0;
            // 中途半端なものを決める
            for (int i = 0; i < D.Length; i++)
            {
                if (R == 0) break;

                if (i < Z)
                {
                    long scoreX = Score(D[i], X);
                    long scoreS = Score(D[Z], X);
                    long scoreR = Score(D[i], R);
                    addition = Math.Max(addition, scoreR - scoreX + scoreS);
                }
                else
                {
                    long scoreR = Score(D[i], R);
                    addition = Math.Max(addition, scoreR);
                }
            }

            player += addition;
            return player >= opponent;

        }

        public long Score(Data d, long v)
        {
            return Math.Min(d.b, v) * d.l + Math.Max(v - d.b, 0) * d.u;
        }

        public long Search()
        {
            long left = 0;
            long right = N * X;

            if (CanWin(0)) return 0;
            if (!CanWin(N * X)) return N * X;

            while (left + 1 < right)
            {
                long mid = (left + right) / 2;
                // Console.Error.WriteLine($"MID {mid}");
                if (!CanWin(mid))
                {
                    left = mid;
                }
                else
                {
                    right = mid;
                }
            }
            return right;
        }

    }

    // libs ----------
    // 比較のみ
    class Data
    {
        public long b;
        public long l;
        public long u;
        public Data(long b, long l, long u)
        {
            this.b = b;
            this.l = l;
            this.u = u;
        }

    }

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 28204