Good Night
시간 제한6초메모리 제한1024 MB
각 가로등은 A_i부터 주기 T마다 켜지고 꺼지며, Azber가 도달할 수 있는 한 계속 켜둘 수 있는지와 영구히 꺼진 경우 마지막으로 켜져 있던 시각을 구한다.
문제
There are streetlights on a straight road. The road can be represented as a number line. -th streetlight is located at and illuminates (). Initially, at the time , every streetlights are on. At time , -th streetlight goes out. After every time , if th streetlight is on, it goes out. Precisely, -th streetlight is turned off if it is on at time for all non-negative integer . ()
Azber lives at the origin of the road, i.e. at coordinate . 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.
...
출력
Print lines. For the -th line, if -th streetlight is not turned off permanently, i.e. for any there exists such that the light is on at , print . Otherwise, print the last time the light was turned on as an integer.