local n, l = io.read("*n", "*n") local curpos, curtime = 0, 0 for i = 1, n do local x, w, t = io.read("*n", "*n", "*n") curtime = curtime + x - curpos curpos = x local rem = curtime % (2 * t) if t - w < rem then curtime = curtime + 2 * t - rem end curpos = curpos + w curtime = curtime + w end print(curtime + l - curpos)