#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef _MSC_VER #include #endif #define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i) #define rep(i, n) FOR(i, 0, n) #define ALL(v) v.begin(), v.end() #define REV(v) v.rbegin(), v.rend() #define MEMSET(v, s) memset(v, s, sizeof(v)) #define UNIQUE(v) (v).erase(unique(ALL(v)), (v).end()) #define MP make_pair #define MT make_tuple using namespace std; typedef long long ll; typedef long double ld; typedef pair P; const int N = 110; int x[N], w[N], t[N]; int check(int i, int ct){ int k = ct / t[i]; if (k & 1) return (k+1)*t[i]; return t[i] - ct % t[i] >= w[i] ? ct : (k + 2)*t[i]; } int main(){ cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); int n, l; cin >> n >> l; rep(i, n) cin >> x[i] >> w[i] >> t[i]; x[n] = l; int ct = x[0]; rep(i, n){ ct = check(i, ct); ct += x[i + 1] - x[i]; } cout << ct << endl; }