using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;


struct Myon2
{
    int a;
}

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long X = cin.nextInt();
        long[] b = new long[N];
        long[] l = new long[N];
        long[] u = new long[N];
        for (int i = 0; i < N; i++)
        {
            b[i] = cin.nextInt();
            l[i] = cin.nextInt();
            u[i] = cin.nextInt();
        }

        long need = 0;

        List<Tuple<long, int>> tp = new List<Tuple<long, int>>();
        for (int i = 0; i < N; i++)
        {
            need += b[i] * l[i];
            tp.Add(Tuple.Create((X - b[i]) * u[i] + b[i] * l[i], i));
        }

        long ans = 0;
        tp.Sort();
        tp.Reverse();

        bool[] used = new bool[N];
        int nexti = 0;
        foreach (var item in tp)
        {
            if (need < item.Item1) break;
            need -= item.Item1;
            ans += X;
            used[item.Item2] = true;
            nexti++;
        }


        if(need > 0)
        {
            long best = long.MaxValue / 10;

            for (int i = 0; i < N; i++)
            {
                long myNeed = need;

                if (used[i])
                {
                    myNeed -= tp[nexti].Item1;
                    myNeed += (X - b[i]) * u[i] + b[i] * l[i];
                }

                long tmp;
                if(myNeed <= l[i] * b[i])
                {
                    tmp = (myNeed + l[i] - 1) / l[i];
                }
                else
                {
                    long n2 = myNeed - l[i] * b[i];
                    tmp = b[i] + (n2 + u[i] - 1) / u[i];
                }
                best = Math.Min(best, tmp);
            }

            ans += best;
        }

        Console.WriteLine(ans);
    }
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 26728