#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair i_i; typedef pair ll_i; typedef pair d_i; typedef pair ll_ll; typedef pair d_d; struct edge { int u, v; ll w; }; ll MOD = 1000000007; ll _MOD = 1000000009; double EPS = 1e-10; bool safe(int t, int W, int T) { int _t = t % (T * 2); return _t >= 0 && _t <= T - W; } int main() { int N, L; cin >> N >> L; int x = 0, t = 0; while (N--) { int X, W, T; cin >> X >> W >> T; t += X - x; x = X; if (!safe(t, W, T)) t = (t / (T * 2) + 1) * (T * 2); } t += L - x; cout << t << endl; }