Good Night

아직 제출이 없습니다시간 제한6초메모리 제한1024 MB

문제

There are NN streetlights on a straight road. The road can be represented as a number line. ii-th streetlight is located at X_iX\_{i} and illuminates \[L_i,R_i]\[L\_{i}, R\_{i}] (X_i>0X\_{i} > 0). Initially, at the time 00, every streetlights are on. At time A_iA\_i, ii-th streetlight goes out. After every time TT, if iith streetlight is on, it goes out. Precisely, ii-th streetlight is turned off if it is on at time A_i+kTA\_{i} + kT for all non-negative integer kk. (0<A_iT0 < A\_i \leq T)

Azber lives at the origin of the road, i.e. at coordinate 00. Azber is too scared to pass the point which is not illuminated by any streetlight. (Except for origin he lives) If Azber notices a turned-off streetlight that he can reach from the origin, he runs very fast and turns the streetlight back on. After he turns on a light, he directly comes back to the origin. The speed that Azber moves and lights up streetlights is so fast that the time Azber spent by movement can be ignored.

Over time, some streetlights goes out and is never turned on again. Our challenge is to figure out if each streetlight is permanently turned off. And for the lights which are turned off permanently, calculate the last time the light was on. Let's help timid Azber!

입력

Read the following data from the standard input. All the values in the input are integers.

NN TT

X_1X\_1 L_1L\_1 R_1R\_1 A_1A\_1

...

X_NX\_N L_NL\_N R_NR\_N A_NA\_N

출력

Print NN lines. For the ii-th line, if ii-th streetlight is not turned off permanently, i.e. for any t>0t>0 there exists t>tt' > t such that the light is on at tt', print 1-1. Otherwise, print the last time the light was turned on as an integer.

제한

  • 1N3000001 \leq N \leq 300000
  • 1T1091 \leq T \leq 10^9
  • 0L_i<R_i1090 \leq L\_i < R\_i \leq 10^9
  • 0<X_i1090 < X\_i \leq 10^9
  • 0<A_iT0 < A\_i \leq T