#include #define MOD 1000000007 using namespace std; typedef pair P; typedef pair> PP; typedef long long LL; const double EPS = 1e-8; const int INF = 1e9; int dy[] = {0,1,0,-1}; int dx[] = {1,0,-1,0}; int main(void) { int N,L; cin >> N >> L; vector x(N),w(N),t(N); for(int i=0;i> x[i] >> w[i] >> t[i]; } int dist = 0,tm = 0,i = 0; while(dist != L){ if(dist == x[i]){ int cnt = tm/t[i]; //blue if(cnt%2 == 0){ //残り時間足りる if((t[i]-tm%t[i]) > w[i]){ dist += w[i]+1; tm += w[i] + 1; }else{ dist += w[i]+1; tm += w[i] + 1 + (t[i]-tm%t[i]) + t[i]; } }else{ dist += w[i] + 1; tm += w[i] + 1 + (t[i]-tm%t[i]) + t[i]; } i++; continue; } dist++; tm++; } cout << tm << endl; return 0; }