typedef long long ll; typedef long double ld; #include using namespace std; // #define int long long #include using namespace __gnu_pbds; template using ordered_set = tree, rb_tree_tag, tree_order_statistics_node_update>; // std::cout << *s.find_by_order(1) << std::endl; // 2 signed main(){ // これがないと落ちることがある ios_base::sync_with_stdio(false); cin.tie(0); ll n,l; cin >> n>>l; ll cnt = 0; ll now = 0; for (ll i = 0; i < n; i++){ ll x,w,t; cin >> x>>w>>t; cnt += x-now; now = x; auto c = cnt%(2*t); if(w+c<=t){ cnt+=w; now=x+w; }else{ cnt+=2*t-c+w; now=x+w; } } cout << cnt+l-now << endl; }