#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const long long MAX = 5100000; const long long INF = 1LL << 60; const long long mod = 1000000007LL; //const long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll N, L; scanf("%lld %lld", &N, &L); ll now_x = 0; ll now_t = 0; for (ll i = 0; i < N; i++) { ll x, w, t; scanf("%lld %lld %lld", &x, &w, &t); now_t += x - now_x; ll q = (now_t + t - 1)/ t; ll r = now_t % t; if (q % 2 == 0) { now_t += t - r; } else { if (t - r < w) now_t += t - r + t; } now_t += w; now_x = x + w; } now_t += L - now_x; cout << now_t << endl; return 0; }