package coder; import java.util.ArrayList; import java.util.Scanner; public class Main { static int N, L; static int[] X, W, T; public static int solve(){ int t = 0; int d = 0; for (int i = 0; i < N; i++) { t += X[i] - d; d = X[i]; int tmp = (t + W[i] - 1) / T[i]; if((t / T[i]) % 2 == 1) { t = ((t/T[i]) + 1) * T[i]; }else if(tmp % 2 == 1) { t = (tmp + 1) * T[i]; } t += W[i]; d += W[i]; } t += L - d; System.out.println(t); return 0; } public static void main(String[] args){ Scanner S = new Scanner(System.in); N = S.nextInt(); L = S.nextInt(); X = new int[N]; W = new int[N]; T = new int[N]; for (int i = 0; i < N; i++) { X[i] = S.nextInt(); W[i] = S.nextInt(); T[i] = S.nextInt(); } solve(); } }