#include #include #include using namespace std; using ll = long long; int f(int nt, int w, int T){ int k=nt/T, r=nt%T; //cout << "? " << k << ' ' << r << ' ' << nt << endl; if(k&1) nt+=T-r; else if(T-r> n >> l; int ans=0, pre=0; for(int i=0; i> x >> w >> t; ans+=x-pre; ans=f(ans, w, t); //cout << "! " << ans << endl; pre=x+w; } ans+=l-pre; cout << ans << endl; return 0; }