#include #define rep(i,a,b) for(int i=int(a);i> N >> L; int nx = 0, nt = 0; rep(i,0,N){ int x,w,t; cin >> x >> w >> t; nt += x - nx; nx = x; //赤のとき if(nt / t % 2 == 1){ nt = (nt + t) / t * t + w; nx += w; }else{ //渡りきれるとき if(nt + w <= (nt + t) / t * t){ nt += w; }else{ nt = (nt + t * 2) / t * t + w; } nx += w; } } nt += L - nx; cout << nt << endl; }