#include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ll long long #define INF (1 << 30) #define INFLL (1LL << 60) ll n,l; ll ans = 0,now = 0; ll x,w,t; int main() { cin >> n >> l; for(int i = 0;i < n;i++){ cin >> x >> w >> t; ans += x - now; now += x - now; if((ans / t) % 2 == 0){ if(t - ans % t >= w) { ans += w; now += w; }else{ ans += t - ans % t + t + w; now += w; } }else{ ans += t - ans % t + w; now += w; } } ans += l - now; cout << ans << endl; return 0; }