__author__ = "Dmitry Philippov"
import sys

inputFile = "jumps"
outputFile = "jumps"

if inputFile == "":
    reader = sys.stdin
    writer = sys.stdout
else:
    reader = open(inputFile + ".in", "r")
    writer = open(outputFile + ".out", "w")

''' Solution '''
n, k = map(int, reader.readline().split())
penguins = [list(map(int, line.rstrip().split())) for line in reader.readlines()]
answer = 0
for i in range(n):
    if k < penguins[i][0]:  
        continue
    if (k - penguins[i][0]) % penguins[i][1] == 0:
        answer += penguins[i][2]
writer.write(str(answer) + '\n')