import times, strutils, sequtils, math, algorithm, tables, sets, lists, intsets import critbits, future, strformat, deques template `max=`(x,y) = x = max(x,y) template `min=`(x,y) = x = min(x,y) template `mod=`(x,y) = x = x mod y template scan2 = (scan(), scan()) template scan3 = (scan(), scan()) let read* = iterator: string {.closure.} = while true: (for s in stdin.readLine.split: yield s) proc scan(): int = read().parseInt proc scanf(): float = read().parseFloat proc toInt(c:char): int = return int(c) - int('0') proc solve():int= var n = scan() l = scan() xwt = newseqwith(n,(scan(),scan(),scan())) pos = 0 clock = 0 for (x,w,t) in xwt: clock += x-pos pos = x var n = clock.div(2*t) if 2*n*t <= clock and clock <= 2*n*t+t and clock+w<=2*n*t+t: pos = x+w clock+=w else: pos = x+w clock = 2*(n+1)*t+w return clock+(l-pos) echo solve()