#include using namespace std; int main() { int N, L, X[110], W[110], T[110]; cin >> N >> L; for (int i = 0; i < N; i++) { cin >> X[i] >> W[i] >> T[i]; } int now = 0; int t = 0; for (int i = 0; i < N; i++) { t += (X[i] - now); if ((t / T[i]) % 2 == 1) { ((t /= T[i]) += 1) *= T[i]; } else if (((t + W[i]) / T[i]) % 2 == 1) ((t /= T[i]) += 2) *= T[i]; t += W[i]; now = X[i] + W[i]; } t += (L - now); cout << t << endl; }