#include using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, l; int ret = 0; int pos = 0; cin >> n >> l; REP (i, n) { int x, w, t; cin >> x >> w >> t; // move to crossroad ret += x - pos; pos += x - pos; // wait int r = ret % (2 * t); if (r < t) { // blue light if (t - r < w) { ret += 2 * t - r; } } else { // red light ret += 2 * t - r; } // cross crossroad ret += w; pos += w; } ret += l - pos; cout << ret << endl; return 0; }