Problem:
 Score : 300 points    Problem Statement A railroad running from west to east in Atcoder Kingdom is now complete.  There are N stations on the railroad, numbered 1 through N from west to east.  Tomorrow, the opening ceremony of the railroad will take place.  On this railroad, for each integer i such that 1≤i≤N-1 , there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.  The first train from Station i to Station i+1 will depart Station i  S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.  Here, it is guaranteed that F_i divides S_i .  That is, for each Time t satisfying S_i≤t and t％F_i=0 , there will be a train that departs Station i  t seconds after the ceremony begins and arrives at Station i+1  t+C_i seconds after the ceremony begins, where A％B denotes A modulo B , and there will be no other trains.  For each i , find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.      Constraints  1≤N≤500  1≤C_i≤100  1≤S_i≤10^5  1≤F_i≤10  S_i％F_i=0  All input values are integers.         Input Input is given from Standard Input in the following format:  N  C_1  S_1  F_1  :  C_{N-1}  S_{N-1}  F_{N-1}       Output Print N lines. Assuming that we are at Station i  (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i -th line should contain x .        Sample Input 1 3
6 5 1
1 10 1      Sample Output 1 12
11
0  We will travel from Station 1 as follows:   5 seconds after the beginning: take the train to Station 2 .  11 seconds: arrive at Station 2 .  11 seconds: take the train to Station 3 .  12 seconds: arrive at Station 3 .   We will travel from Station 2 as follows:   10 seconds: take the train to Station 3 .  11 seconds: arrive at Station 3 .   Note that we should print 0 for Station 3 .       Sample Input 2 4
12 24 6
52 16 4
99 2 2      Sample Output 2 187
167
101
0       Sample Input 3 4
12 13 1
44 17 17
66 4096 64      Sample Output 3 4162
4162
4162
0

Solution (Python):
N = int(input())
Cls = [0]
Sls = [0]
Fls = [0]
lsans = []
for i in range(1,N):
    c,s,f = map(int,input().split())
    Cls.append(c)
    Sls.append(s)
    Fls.append(f)
for i in range(1,N):
    t = 0
    for j in range(i,N):
        if t < Sls[j]:
            t = Sls[j] + Cls[j]
        elif t%Fls[j] == 0:
            t += Cls[j]
        else:
            t += Fls[j]-(t%Fls[j])+Cls[j]
    lsans.append(t)
lsans.append(0)
for i in lsans:
    print(i)

Solution (Python):
N = int(input())
T = 0
t = 0
ans = []
for i in range(N-1):
    C, S, F = map(int, input().split())
    for j in range(len(ans)):
        if ans[j] <= S:
            ans[j] = S+C
        elif ans[j]%F != 0:
            ans[j] = ans[j]+F-(ans[j] % F)+C
        else:
            ans[j] += C
    ans.append(S+C)
for a in ans:
    print(a)
print(0)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()
CSF = [tuple(MI()) for i_ in range(N-1)]

for i in range(N):
    time = 0
    for j in range(i,N-1):
        c,s,f = CSF[j]
        if time < s:
            time = s
        else:
            time = s+f*((time-s+f-1)//f)
        time += c
    print(time)

Solution (Python):
n = int(input())
stations = []
for i in range(n-1):
    stations.append(list(map(int, input().split())))

ans = [0]
time_matrix = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(i+1):
        if i < n-1:
            if time_matrix[i][j] % stations[i][2] == 0:
                waiting = 0
            else:
                waiting = stations[i][2] - (time_matrix[i][j] % stations[i][2])
            time_matrix[i+1][j] = max(time_matrix[i][j] + stations[i][0] + waiting, stations[i][0] + stations[i][1])

for i in range(n):
    print(time_matrix[n-1][i])

Solution (Python):
def LIHW(h):
    return [list(map(int, input().split())) for _ in range(h)]


N = int(input())
X = LIHW(N-1)

for i in range(N-1):
    time = [0]*N
    time[i] = X[i][1]+X[i][0]
    for j in range(i+1, N-1):
        if time[j-1] <= X[j][1]:
            time[j] = X[j][1]+X[j][0]
        else:
            if (time[j-1]-X[j][1]) % X[j][2] == 0:
                time[j] = time[j-1] + X[j][0]
            else:
                time[j] = time[j-1] + X[j][0]+X[j][2] - \
                    ((time[j-1]-X[j][1]) % X[j][2])
    print(time[j])
print(0)

Solution (Python):
from math import ceil

n = int(input())
csfl = [tuple(map(int, input().split())) for _ in range(n-1)]

for i in range(n-1):
    c,s,f = csfl[i]
    t = s+c
    for j in range(i+1,n-1):
        c,s,f = csfl[j]
        if t <= s:
            t = s
        else:
            t = ceil(t/f)*f
        t += c
    print(t)

print(0)

Solution (Python):
N = int(input())
Plan = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    c1,s1,f1 = Plan[i]
    time = s1+c1
    for j in range(i+1,N-1):
        c,s,f = Plan[j]
        if time <= s:
            time = s
        elif (time-s)%f != 0:
            time += f-(time-s)%f
        time += c
    print(time)
print(0)

Solution (Python):
import math
N = int(input())
A = [list(map(int,input().split())) for _ in range(N-1)]
A.insert(0,0)
for i in range(1,N):
    C,S,F = A[i]
    T = S+C
    j = i+1
    while j<N:
        C,S,F = A[j]
        T = max(S,math.ceil(T/F)*F)
        T += C
        j += 1
    print(T)
print(0)

Solution (Python):
import sys

N = int(sys.stdin.readline())

stations = []
for _ in range(N-1):
    c, s, f = map(int, sys.stdin.readline().split())
    stations.append((c, s, f))

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        c, s, f = stations[j]
        if t <= s:
            t = s + c
        else:
            tmp = t - s
            t = s + f * ((tmp - 1) // f + 1) + c

    print(t)
print(0)

Solution (Python):
N = int(input())
csf = [list(map(int, input().split())) for _ in range(N-1)]
ans = [None]*N
ans[-1] = 0
for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        if now <= csf[j][1]:
            now = csf[j][1]
        else:
            t  = (now - csf[j][1] + csf[j][2]-1)//csf[j][2]
            now = csf[j][1] + t*csf[j][2]
        now += csf[j][0]
    ans[i] = now
[print(a) for a in ans]

Solution (Python):
n = int(input())
csf = [tuple(map(int, input().split())) for _ in range(n - 1)]

for i in range(n - 1):
    c, s, f = csf[i]
    a = s + c
    now = i
    for j in range(i + 1, n - 1):
        nc, ns, nf = csf[j]
        
        if a <= ns:
            a = ns
        else:
            x = (a - ns + nf - 1) // nf
            a = ns + nf * x
        a += nc

    print(a)
print(0)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N = I()
CSF = [tuple(MI()) for i_ in range(N-1)]

for i in range(N):
    time = 0
    for j in range(i,N-1):
        c,s,f = CSF[j]
        if time < s:
            time = s
        else:
            time = s+f*((time-s+f-1)//f)
        time += c
    print(time)

Solution (Python):
n=int(input())
yo=[]
for _ in range(n-1):
  a=list(map(int,input().split()))
  yo.append(a)
  
def ans(x):
  if x==n-1:
    return 0
  else:
    t=0
    for i in range(x,n-1):
      if t<=yo[i][1]:
        t=yo[i][1]+yo[i][0]
      else:
        s=t-yo[i][1]
        if s%yo[i][2]==0:
          t=t+yo[i][0]
        else:
          mo=s%yo[i][2]
          t=t+yo[i][2]-mo+yo[i][0]
    return t
    
for j in range(n):
  print(ans(j))

Solution (Python):
N = int(input())
C, S, F = [], [], []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)
S.append(0)

import numpy as np
def theta(x): 
    return x if x > 0 else 0

def DptTimeAtNextSt(i, T): 
    global C, S, F
    arrT = T + C[i]
    if i == N-2: return arrT 
    return S[i+1] + np.ceil(theta(arrT-S[i+1])/F[i+1]) * F[i+1]

def solve(i, S): 
    if i == N-1:
        return int(S)
    else:
        return solve(i+1, DptTimeAtNextSt(i,S))

for i in range(N):
    print(solve(i,S[i]))

Solution (Python):
n = int(input())
ans = [0] * n

for i in range(1, n):
    c, s, f = list(map(int, input().split()))

    for j in range(i):
        ans[j] = max(ans[j], s)
        ans[j] = ((ans[j]+f-1)//f) * f
        ans[j] += c

for a in ans:
    print(a)

Solution (Python):
N = int(input())
station = [list(map(int, input().split())) for _ in range(N - 1)]

lst = []

for i in range(N - 1):
    c, s, f = station[i]

    for j in range(len(lst)):
        a = lst[j]

        if a >= s:
            if a % f == 0:
                a += c
            else:
                a += (f - a % f) + c
        else:
            a = s + c

        lst[j] = a

    lst.append(s + c)


lst.append(0)
for a in lst:
    print(a)

Solution (Python):
import math

n = int(input())
cL = []
sL = []
fL = []
for i in range(n - 1):
    c, s, f = map(int, input().split(" "))
    cL.append(c)
    sL.append(s)
    fL.append(f)

ans = 0
for i in range(n - 1):
    sm = 0
    for j in range(i, n - 1):
        c = cL[j]
        s = sL[j]
        f = fL[j]
        if sm < s:
            sm = s + c
            continue
        df = f - (sm - s) % f
        if df == f:
            df = 0
        sm += c + df
    print(sm)
print(0)

Solution (Python):
import sys
import itertools
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N =int(input())

    C =[]
    S =[]
    F =[]
    for i in range(N-1):
        c,s,f = map(int,input().split())
        C.append(c)
        S.append(s)
        F.append(f)

    for i in range(N-1):
        t = i
        time=0
        while t<N-1:

            if time <=S[t]:
                time =S[t]+C[t]
            else:
                if time %F[t] ==0:
                    time +=C[t]
                else:
                    div = time //F[t]
                    time = (div+1) *F[t] + C[t]
            t+=1

        print(time)

    print(0)





if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
C,S,F=map(list,zip(*[list(map(int,input().split())) for i in range(N-1)]))
r=[0]*N
for i in range(N-2,-1,-1):
    x=S[i]+C[i]
    for j in range(i+1,N-1):
        x=S[j]+C[j] if x<S[j] else -(-x//F[j])*F[j]+C[j]
    r[i]=x
print(*r,sep='\n')

Solution (Python):
N = int(input())
C = [0] * N
S = [0] * N
F = [0] * N

for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())

def arrive(st):
    time = C[st] + S[st]
    for i in range(st + 1, N-1):
        if time <= S[i]:
            time = C[i] + S[i]
        else:
            if time % F[i] != 0:
                time = time + C[i] + (F[i] - time % F[i])
            else:
                time = time + C[i]
    return time

for i in range(N-1):
    print(arrive(i))
print("0")

Solution (Python):
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(n-1):
    t = 0
    for c,s,f in csf[i:]:
        if s > t:
            
            t = s
        else:
            
            t += (s-t) % f
        t += c
    print(t)
print(0)

Solution (Python):
N=int(input())
C,S,F=[],[],[]

for i in range(N-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

T=[0]*N
for i in range(N):
    A=0
    for j in range(i,N-1):
        if A>=S[j]:
            A=((A+F[j]-1)//F[j])*F[j]
        else:
            A=S[j]
        A+=C[j]
    T[i]=A

print("\n".join(map(str,T)))

Solution (Python):
N = int(input())
from math import floor
C, S, F = [], [], []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for start in range(N):
    ans = 0
    if start == N-1:
        print(ans)
        break
    for i in range(start, N-1):
        if ans <= S[i]:
            ans = S[i]
            ans += C[i]
        else:
            if ans % F[i] == 0:
                ans += C[i]
            else:
                ans += (F[i] - ans % F[i])
                ans += C[i]
            
    print(ans)

Solution (Python):
n=int(input())
l=[0]*n
for i in range(1,n):
  c,s,f=map(int,input().split())
  for j in range(i):
    l[j]=max(-l[j]//f*-f,s)+c
for i in l: print(i)

Solution (Python):
n=int(input())
l=[]
for _ in range(n-1):
  c,s,f=map(int,input().split())
  for i,t in enumerate(l):
    if t>s: t=-(-t//f)*f
    else: t=s
    l[i]=t+c
  l+=[s+c]
for i in l+[0]:
  print(i)

Solution (Python):
from math import *

n = int(input()) - 1
c = [0] * n
s = [0] * n
f = [0] * n
for i in range(n):
  c[i], s[i], f[i] = map(int, input().split())
  
for i in range(n):
  a = s[i] + c[i]
  for j in range(i + 1, n):
    if a <= s[j]:
      a = s[j] + c[j]
    else:
      a = s[j] + f[j] * ceil((a-s[j])/f[j]) + c[j]
  print(a)
print(0)

Solution (Python):
N= int(input())
li = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    ci,si,fi = li[i]
    time = si+ci
    for j in range(i+1,N-1):
        cj,sj,fj = li[j]
        if time%fj != 0:
            time = ((time//fj)+1)*fj
        
        if time < sj:
            time = sj
        time += cj
    print(time)
print(0)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


n = int(readline())
csf = [tuple(map(int, readline().split())) for _ in range(n-1)]

for i in range(n):
    now = 0
    for c, s, f in csf[i::]:
        if now <= s:
            now = s
        else:
            if now % f == 0:
                pass
            else:
                now = (now // f + 1) * f
        now += c
    print(now)

Solution (Python):
N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    C[i], S[i], F[i] = map(int,input().split())

for i in range(N):
    t = 0
    for j in range(i,N - 1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] == 0:
            pass
        else:
            t = t + F[j] - (t % F[j])
        t += C[j]
    print(t)

Solution (Python):
n=int(input())
csf = [list(map(int,input().split())) for i in range(n-1)]
ans1=[]
for j in range(n-1):
  requ_time=csf[j][1]+csf[j][0]
  for i in range(j,n-1):
    if i!=j:
      if requ_time <= csf[i][1]:
        requ_time+=(csf[i][0]+(csf[i][1]-requ_time))
  
      else:
        requ_time+=(csf[i][0]+(csf[i][2]-(requ_time-csf[i][1])%csf[i][2])%csf[i][2])
  ans1.append(requ_time)
for i in ans1:
  print(i)
print(0)

Solution (Python):

n=int(input())
c=[]
sf=[]
for _ in range(n-1):
    ci,s,f=map(int,input().split())
    c.append(ci)
    sf.append([s,f])
for i in range(n):
    temp=0
    for j in range(i,n-1):
        if temp<=sf[j][0]:
            temp=sf[j][0]+c[j]
        else:
            if temp%sf[j][1]==0:
                temp=temp+c[j]
            else:
                temp=temp+(sf[j][1]-temp%sf[j][1])+c[j]
            
    print(temp)

Solution (Python):
import math
def main():
    n=int(input())
    csf=[list(map(int,input().split())) for _ in range(n-1)]
    for i in range(n):
        if i == n-1:
            print(0)
        else:
            t=0
            for c,s,f in csf[i:]:
                t = max(s,t)
                t = math.ceil(t/f)*f+c
                
            print(t)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
C = []
S = []
F = []
for i in range(n-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for start in range(n-1):
    time = S[start]
    for i in range(start,n-1):
        time += C[i]
        if i != n-2:
            if time <= S[i+1]:
                time = S[i+1]
            elif time%F[i+1] != 0:
                time += F[i+1]-time%F[i+1]
    print(time)
print(0)

Solution (Python):
import sys
import math

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    CSF = list(list(map(int, readline().split())) for _ in range(N-1))
    T = []
    for i in range(N-1):
        t = 0
        for c, s, f in CSF[i:]:
            t = max(math.ceil(t/f)*f, s) + c
        T.append(t)
    T.append(0)
    for t in T:
        print(t)


if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    '''
    code here
    '''
    N = int(input())
    starts = [[int(item) for item in input().split()] for _ in range(N-1)]

    for i in range(N):
        temp_time = 0
        if i == N-1:
            print(0)
        else:
            for j in range(i,N-1):
                c, s, f = starts[j]
                if temp_time <= s:
                    temp_time = s

                if temp_time % f == 0:
                    pass
                else:
                    temp_time = (temp_time // f + 1) * f
            
                temp_time += c
            print(temp_time)


if __name__ == "__main__":
    resolve()

Solution (Python):
n = int(input())
route, ans = [], []
for i in range(n-1):
    a = list(map(int, input().split()))
    route.append(a)

for i in range(n-1):
    c = route[i][0]+route[i][1]
    for j in range(i+1, n-1):
        if c < route[j][1]:
            c = route[j][0]+route[j][1]
        elif (c-route[j][1])%route[j][2] == 0:
            c += route[j][0]
        else:
            c += route[j][0]+route[j][2]-(c-route[j][1])%route[j][2]
    ans.append(c)
ans.append(0)
for i in ans:
    print(i)

Solution (Python):
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  c_, s_ , f_ = map(int, input().split())
  c.append(c_)
  s.append(s_)
  f.append(f_)
  
for i in range(n-1):
  res = s[i] + c[i]
  for j in range(i+1, n-1):
    if res >= s[j]:
      if (res-s[j]) % f[j] == 0:
        res = res + c[j] + ((res - s[j]) % f[j])
      else:
        res = res + c[j] + f[j] - ((res-s[j])%f[j])
    else:
      res = s[j] + c[j]
  print(res)
print(0)

Solution (Python):
import math
n=int(input())
c=[0]*(n-1)
s=[0]*(n-1)
f=[0]*(n-1)
for i in range(n-1):
  c[i],s[i],f[i] = map(int,input().split())

for i in range(n):
  ans=0
  for j in range(i,n-1):
    ans = max(s[j], math.ceil(ans/f[j])*f[j]) + c[j]
  print(ans)

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math







INF = 1 << 50

def eval(start, CSF):
    N = len(CSF)+1
    queue = []
    heappush(queue, (0, start))
    while queue:
        time, current = heappop(queue)
        
        if current == N-1:break
        for i in range(current, current+1):
            c,s,f = CSF[i]
            first_s = s + c * (current-i)
            if time <= first_s:
                next_leave = first_s
            else:
                next_leave = first_s + math.ceil((time - first_s) / f) * f
            
            heappush(queue, (next_leave + c, current+1))
    return time

def run():
    N = int(sysread())
    CSF = []
    for i in range(N-1):
        c,s,f = map(int, sysread().split())
        CSF.append((c,s,f))

    for i in range(N-1):
        print(eval(i, CSF))
    print(0)
    

if __name__ == "__main__":
    run()

Solution (Python):
N = int(input())
CSF = [[0] * 3 for i in range(N-1)]

for i in range(N-1):
    c, s, f = map(int, input().split())
    CSF[i][0] = c
    CSF[i][1] = s
    CSF[i][2] = f

for i in range(N-1):
    now = CSF[i][1]+CSF[i][0]
    for j in range(i+1, N-1):
        
        if now <= CSF[j][1]:
            now += CSF[j][0]+(CSF[j][1]-now)

        
        else:
            while (now - CSF[j][1]) % CSF[j][2] != 0:
                now += 1
            now += CSF[j][0]
    print(now)
print(0)

Solution (Python):
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
for TN in range(0,N-1):
    C[TN],S[TN],F[TN] = (int(T) for T in input().split())
for TN in range(0,N):
    Time = 0
    for TS in range(TN,N-1):
        if Time>=S[TS]:
            Time += C[TS]+(F[TS]-(Time%F[TS]))%F[TS]
        else:
            Time += C[TS]+(S[TS]-Time)
    print(Time)

Solution (Python):
N = int(input())
CSF = [[] for T in range(0,N-1)]
for TN in range(0,N-1):
    CSF[TN] = [int(T) for T in input().split()]
for TN in range(0,N):
    Time = 0
    for TT in range(TN,N-1):
        if Time>=CSF[TT][1]:
            Time += CSF[TT][0] + (CSF[TT][2]-(Time%CSF[TT][2]))%CSF[TT][2]
        else:
            Time += CSF[TT][0] + (CSF[TT][1]-Time)
    print(Time)

Solution (Python):
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]
ans = []
for i in range(n-1):
    time = 0
    for p in range(i, n - 1):
        c, s, f = csf[p]
        if s >= time:
            time = s+c
        else:
            d = time - s
            time = s + f * (-(-d // f)) + c
    ans.append(time)

ans.append(0)

for i in range(n):
    print(ans[i])

Solution (Python):

(n, ), *q = [[*map(int, i.split())] for i in open(0)]
ans = [0] * n
for i, p in enumerate(q):
    c, s, f = p
    for j in range(i):
        ans[j] = c + max(s, -(-ans[j] // f) * f)
    ans[i] = c + s
print(*ans, sep="\n")

Solution (Python):
N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < S[j]:
            t = S[j]
        elif t % F[j] != 0:
            t += F[j]-t%F[j]
        t += C[j]
    print(t)

Solution (Python):
N=int(input())
csf=[list(map(int,input().split()))for _ in range(N-1)]
i=0
while i<N:
    ans=0
    j=i
    while j<N-1:
        c,s,f=list(csf[j])
        ans=max(ans,s)
        if ans%f:
            ans+=f-ans%f
        ans+=c
        j+=1
    print(ans)
    i+=1

Solution (Python):
n = int(input())
graph =[]
time = 0
for i in range(n-1):
    c,s,f = map(int,input().split())
    graph.append([i,c,s,f])

def shortest_path(start,end,times):
    if start == end:
        return times
    elif times<=graph[start][2]:
        times = (graph[start][2]+graph[start][1])
        return shortest_path(start+1,end,times)
    elif times%graph[start][3]==0:
        times += (graph[start][1])
        return shortest_path(start+1,end,times)
    else:
        times = times+graph[start][3]-times%graph[start][3]+graph[start][1]
        return shortest_path(start+1,end,times)


for i in range(n):
    print(shortest_path(i,n-1,0))

Solution (Python):
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)


input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    
    
    
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    
    return X.flatten().tolist()[0]

class TwoDimGrid:
    
    def __init__(self, h, w, wall="
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        
        
        
        
        


def soinsu(n):
    ret = defaultdict(int)
    for i in range(2, int(math.sqrt(n) + 2)):
        if n % i == 0:
            while True:
                if n % i == 0:
                    ret[i] += 1
                    n //= i
                else:
                    break

    if not ret:
        return {n: 1}
    return ret


def solve():
    n = getN()
    den = []
    ans = [0 for i in range(n)]
    for i in range(n-1):
        den.append(getList())

    den.append([0,0,0])

    
    
    
    
    
    
    for i in range(n-1):
        cur = 0
        for j in range(i, n-1):
            if cur <= den[j][1]:
                cur = den[j][1]
            cur = int(math.ceil(cur/den[j][2]) * den[j][2])
            cur += den[j][0]
        ans[i] = cur

    print(*ans, sep="\n")


def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    
    solve()

Solution (Python):






N = int(input())
csf = []
for _ in range(N-1):
    csf.append(list(map(int, input().split())))





for i in range(N):
    if i < N-1:
        t = csf[i][1]
        for i in range(i,N-1):
            c,s,f = csf[i]
            if t >= s:
                if t%f == 0:
                    t += c
                else:
                    t = (-(-t//f))*f+c
            else:
                t = s+c
        print(t)
    else:
        print(0)

Solution (Python):
n=int(input())
csf=[tuple(map(int,input().split())) for _ in range(n-1)]

arrtime=lambda i,cs: max(csf[i][2]*(cs//csf[i][2]+(cs%csf[i][2]>0)),csf[i][1])+csf[i][0]
for i in range(n-1):
  arrivN=csf[i][1]
  for j in range(i,n-1):
    arrivN=arrtime(j,arrivN)
  print(arrivN)
print(0)

Solution (Python):

N=int(input())
CSF = [None]*(N-1)
for i in range(N-1):
    CSF[i] = list(map(int, input().split()) )

for I in range(N):
    now = 0
    for csf in CSF[I:]:
        now = max( -(-now//csf[2])*csf[2] , csf[1]) + csf[0]
    print(now)

Solution (Python):
def est_time(sta,N,csf_list):
  SUM = 0
  for i in range(sta,N):
    if i == sta:
      SUM += csf_list[i-1][0] + csf_list[i-1][1]
    else:
      if SUM >= csf_list[i-1][1]:
        SUM = ((SUM+csf_list[i-1][2]-1) // csf_list[i-1][2])*csf_list[i-1][2]
        SUM += csf_list[i-1][0]
      else:
        SUM = csf_list[i-1][1]
        SUM += csf_list[i-1][0]
  return SUM

N=int(input())
csf_list=[tuple(map(int,input().split())) for _ in range(N-1)]

for i in range(N):
  print(est_time(i+1,N,csf_list))

Solution (Python):
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N = int(input())
    
    CSF = [list(map(int,input().split())) for _ in range(N-1)]

    for i in range(N):
        t = 0
        for c,s,f in CSF[i:]:
            if t<=s:
                t=s
            else:
                t=((t-s)//f if (t-s)%f==0 else (t-s)//f+1)*f+s
            t+=c
        print(t)

if __name__=='__main__':
    main()

Solution (Python):
n = int(input())
csf = []
for i in range(n - 1):
    csf.append(list(map(int, input().split())))
for i in range(n):
    t = 0
    for j in range(n - i - 1):
        c, s, f = (csf[i + j][k] for k in range(3))
        t = (max(t - 1, s - 1) // f + 1) * f + c
    print(t)

Solution (Python):
N = int(input())
C = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        now = max(C[j][1], -(-now//C[j][2])*C[j][2])
        now += C[j][0]
    print(now)
print(0)

Solution (Python):
n = int(input())
inp = []
for i in range(n-1):
    inp.append(list(map(int, input().split())))

for i in range(n-1):
    total = 0
    for j in range(i, n-1):
        if total < inp[j][1]:
            total = inp[j][1]
        while total % inp[j][2] != 0:
            total += 1
        total += inp[j][0]
    print(total)
print(0)

Solution (Python):
import math
N = int(input())

C = []
S = []
F = []
for _ in range(N - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)


for i in range(N - 1):
    count = 0
    count += S[i]
    count += C[i]
    for j in range(i + 1, N - 1):
        if count < S[j]:
            count = S[j]
        else:
            count = math.ceil((count - S[j]) / F[j]) * F[j] + S[j]
        count += C[j]
    print(count)
print(0)

Solution (Python):
import math

N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]

for i in range(N):
    t = 0

    for c, s, f in CSF[i:]:
        
        if t < s:
            t = s
        else:
            t = math.ceil((t - s) / f) * f + s

        
        t += c

    print(t)

Solution (Python):
import sys

read = sys.stdin.buffer.read


def main():
    N, *CSF = map(int, read().split())
    train = [0] * (N - 1)
    for i, t in enumerate(zip(*[iter(CSF)] * 3)):
        train[i] = t

    ans = [0] * N
    for i in range(N - 1):
        t = 0
        for c, s, f in train[i:]:
            if t < s:
                t = s + c
            elif t % f == 0:
                t += c
            else:
                t += f - (t % f) + c
        ans[i] = t

    print('\n'.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *CSF = map(int, read().split())
    train = [0] * (N - 1)
    for i, t in enumerate(zip(*[iter(CSF)] * 3)):
        train[i] = t

    ans = [0] * N
    for i in range(N - 1):
        t = 0
        for c, s, f in train[i:]:
            if t < s:
                t = s + c
            else:
                t += f - ((t - 1) % f + 1) + c
        ans[i] = t

    ans[N - 1] = 0
    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
c,s,f=[],[],[]
for _ in range(n-1):
    x,y,z=map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

for i in range(n-1):
    temp=s[i]+c[i]
    for j in range(i+1,n-1):
        if temp<=s[j]: temp=s[j]+c[j]
        else:
            if (temp-s[j])%f[j]==0: temp+=c[j]
            else:
                k=(temp-s[j])//f[j]+1
                temp=s[j]+k*f[j]+c[j]
    print(temp)
print(0)