#include using namespace std; int main() { #ifdef DEBUG std::ifstream in("/home/share/inputf.in"); std::cin.rdbuf(in.rdbuf()); #endif int N, L; cin >> N >> L; int delay = 0, t = 0; int X, W, T; for(int i = 0; i < N; i++) { cin >> X >> W >> T; t = X + delay; int f = (((t + W) / T) | (t / T)) & 1; T *= 2; if(f) { delay += (T + (-t % T))%T; } } cout << delay + L << endl; return 0; }