import sys

from bisect import bisect_left

from itertools import accumulate

from operator import itemgetter



n, x = list(map(int, input().split()))

exams = []

norma = 0

for i, line in enumerate(sys.stdin):

    b, l, u = list(map(int, line.split()))

    exams.append((u * x - b * (u - l), b, l, u, i))

    norma += b * l

exams_sorted = sorted(exams, reverse=True)

exams_acc = list(accumulate(list(map(itemgetter(0), exams_sorted))))

exams_loc = {i: loc for loc, i in enumerate(map(itemgetter(4), exams_sorted))}

# print(norma)

# print(exams_sorted)

# print(exams_acc)



ans = 10 ** 10

base_loc = bisect_left(exams_acc, norma)

base_ans = base_loc * x

base_remain_norma = norma - exams_acc[base_loc - 1] if base_loc > 0 else norma

# print(f'base_remain_norma:{base_remain_norma}')

for d, b, l, u, i in exams:

    exam_loc = exams_loc[i]

    if base_loc <= exam_loc:

        curr_ans = base_ans

        curr_remain_norma = base_remain_norma

    else:

        tmp_norma = norma + d

        tmp_loc = bisect_left(exams_acc, tmp_norma)

        curr_ans = (tmp_loc - 1) * x

        curr_remain_norma = tmp_norma - exams_acc[tmp_loc - 1]

    if curr_remain_norma <= b * l:

        extra = (curr_remain_norma - 1) // l + 1

    else:

        extra = (curr_remain_norma + b * (u - l) - 1) // u + 1

    # print(d, b, l, u, i)

    # print(f'exl:{exam_loc}  {int(base_loc <= exam_loc)}  norma:{curr_remain_norma}  curans:{curr_ans}  '

    #       f'extra:{extra}')

    if extra > x:

        continue

    ans = min(ans, curr_ans + extra)



print(ans)

import sys



n, x = list(map(int, input().split()))

exams = []

norma = 0

for i, line in enumerate(sys.stdin):

    b, l, u = list(map(int, line.split()))

    exams.append((u * x - b * (u - l), b, l, u, i))

    norma += b * l

exams_sorted = sorted(exams, reverse=True)



remain_norma = norma

sub_d = -1

i = 0

used = set()

for i, (d, b, l, u, ei) in enumerate(exams_sorted):

    if remain_norma < d:

        sub_d = d

        break

    remain_norma -= d

    used.add(ei)



if sub_d == -1:

    print((n * x))

    exit()



base_ans = i * x

base_remain_norma = remain_norma



ans = 10 ** 10



for d, b, l, u, i in exams:

    if i in used:

        curr_remain_norma = base_remain_norma + d - sub_d

    else:

        curr_remain_norma = base_remain_norma

    if curr_remain_norma <= b * l:

        extra = (curr_remain_norma - 1) // l + 1

    else:

        extra = (curr_remain_norma + b * (u - l) - 1) // u + 1

    if extra > x:

        continue

    ans = min(ans, base_ans + extra)



print(ans)

import sys
from bisect import bisect_left
from itertools import accumulate
from operator import itemgetter

n, x = list(map(int, input().split()))
exams = []
norma = 0
for i, line in enumerate(sys.stdin):
    b, l, u = list(map(int, line.split()))
    exams.append((u * x - b * (u - l), b, l, u, i))
    norma += b * l
exams_sorted = sorted(exams, reverse=True)
exams_acc = list(accumulate(list(map(itemgetter(0), exams_sorted))))
exams_loc = {i: loc for loc, i in enumerate(map(itemgetter(4), exams_sorted))}
# print(norma)
# print(exams_sorted)
# print(exams_acc)
ans = 10**10
base_loc = bisect_left(exams_acc, norma)
base_ans = base_loc * x
base_remain_norma = norma - exams_acc[base_loc - 1] if base_loc > 0 else norma
# print(f'base_remain_norma:{base_remain_norma}')
for d, b, l, u, i in exams:
    exam_loc = exams_loc[i]
    if base_loc <= exam_loc:
        curr_ans = base_ans
        curr_remain_norma = base_remain_norma
    else:
        tmp_norma = norma + d
        tmp_loc = bisect_left(exams_acc, tmp_norma)
        curr_ans = (tmp_loc - 1) * x
        curr_remain_norma = tmp_norma - exams_acc[tmp_loc - 1]
    if curr_remain_norma <= b * l:
        extra = (curr_remain_norma - 1) // l + 1
    else:
        extra = (curr_remain_norma + b * (u - l) - 1) // u + 1
    # print(d, b, l, u, i)
    # print(f'exl:{exam_loc}  {int(base_loc <= exam_loc)}  norma:{curr_remain_norma}  curans:{curr_ans}  '
    #       f'extra:{extra}')
    if extra > x:
        continue
    ans = min(ans, curr_ans + extra)
print(ans)

import sys

n, x = list(map(int, input().split()))
exams = []
norma = 0
for i, line in enumerate(sys.stdin):
    b, l, u = list(map(int, line.split()))
    exams.append((u * x - b * (u - l), b, l, u, i))
    norma += b * l
exams_sorted = sorted(exams, reverse=True)
remain_norma = norma
sub_d = -1
i = 0
used = set()
for i, (d, b, l, u, ei) in enumerate(exams_sorted):
    if remain_norma < d:
        sub_d = d
        break
    remain_norma -= d
    used.add(ei)
if sub_d == -1:
    print((n * x))
    exit()
base_ans = i * x
base_remain_norma = remain_norma
ans = 10**10
for d, b, l, u, i in exams:
    if i in used:
        curr_remain_norma = base_remain_norma + d - sub_d
    else:
        curr_remain_norma = base_remain_norma
    if curr_remain_norma <= b * l:
        extra = (curr_remain_norma - 1) // l + 1
    else:
        extra = (curr_remain_norma + b * (u - l) - 1) // u + 1
    if extra > x:
        continue
    ans = min(ans, base_ans + extra)
print(ans)

-from bisect import bisect_left -from itertools import accumulate -from operator import itemgetter -exams_acc = list(accumulate(list(map(itemgetter(0), exams_sorted)))) -exams_loc = {i: loc for loc, i in enumerate(map(itemgetter(4), exams_sorted))} -# print(norma) -# print(exams_sorted) -# print(exams_acc) +remain_norma = norma +sub_d = -1 +i = 0 +used = set() +for i, (d, b, l, u, ei) in enumerate(exams_sorted): +    if remain_norma < d: +        sub_d = d +        break +    remain_norma -= d +    used.add(ei) +if sub_d == -1: +    print((n * x)) +    exit() +base_ans = i * x +base_remain_norma = remain_norma -base_loc = bisect_left(exams_acc, norma) -base_ans = base_loc * x -base_remain_norma = norma - exams_acc[base_loc - 1] if base_loc > 0 else norma -# print(f'base_remain_norma:{base_remain_norma}') -    exam_loc = exams_loc[i] -    if base_loc <= exam_loc: -        curr_ans = base_ans +    if i in used: +        curr_remain_norma = base_remain_norma + d - sub_d +    else: -    else: -        tmp_norma = norma + d -        tmp_loc = bisect_left(exams_acc, tmp_norma) -        curr_ans = (tmp_loc - 1) * x -        curr_remain_norma = tmp_norma - exams_acc[tmp_loc - 1] -    # print(d, b, l, u, i) -    # print(f'exl:{exam_loc}  {int(base_loc <= exam_loc)}  norma:{curr_remain_norma}  curans:{curr_ans}  ' -    #       f'extra:{extra}') -    ans = min(ans, curr_ans + extra) +    ans = min(ans, base_ans + extra)