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())
CSF = [[int(_) for _ in input().split()] for _ in range(N-1)]

dp = [[0] * N for _ in range(N)]
for i in range(N):
    dp[i][i]=0
    for j in range(i,N-1):
        if dp[i][j] <= CSF[j][1]:
            dp[i][j+1] =CSF[j][0] + CSF[j][1]
        else:
            dp[i][j+1] = CSF[j][0] + CSF[j][2]*(1+(dp[i][j]-1)//CSF[j][2])

[print(dp[_][N-1]) for _ in range(N)]

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

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

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

for i in range(N-1):
    result = 0
    for j in range(i, N-1):
        if result <= CSF[j][1]:
            result = CSF[j][0] + CSF[j][1]
        else:
            result = CSF[j][0] + CSF[j][1] + ((-((-(result-CSF[j][1]))//CSF[j][2])) * CSF[j][2])

    print(result)

print(0)

Solution (Python):
import math

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


def nextArriveTime(station, start):
    """
    print("start:{} depart:{} arrive:{}"
          .format(start,
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station],
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station] + c[i]))
    """
    
    return s[station] \
           + max(0, math.ceil((start - s[station]) / f[station])) * f[station] \
           + c[station]

for i in range(n):
    time = s[i]
    for j in range(i, n):
        time = nextArriveTime(j, time)
        
    print(time)
print(0)

Solution (Python):
import math

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


def nextArriveTime(station, start):
    """
    print("start:{} depart:{} arrive:{}"
          .format(start,
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station],
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station] + c[i]))
    """
    
    if start >= s[station]:
        return s[station] \
               + math.ceil((start - s[station]) / f[station]) * f[station] \
               + c[station]
    else:
        return s[station] + c[station]

for i in range(n):
    time = s[i]
    for j in range(i, n):
        time = nextArriveTime(j, time)
        
    print(time)
print(0)

Solution (Python):
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
for j in range(n):
  c=0
  for k in range(j,n-1):
    if l[k][1]>=c:c=l[k][1]+l[k][0]
    else:c=l[k][1]+(((c-l[k][1]-1)//l[k][2])+1)*l[k][2]+l[k][0]
  print(c)

Solution (Python):

N=int(input())
C = []
S = []
F = []
for i in range(N-1):
    c,s,f = list(map(int,input().split()))
    C.append(c)
    S.append(s)
    F.append(f)
    
for i in range(N):
    time = 0
    for j in range(i,N-1):
        if time < S[j]:
            time = S[j]+C[j]
        else:
            itime=int(time/F[j])
            if itime*F[j]!=time:
                time=(itime+1)*F[j]+C[j]
            else:
                time+=C[j]
    print(time)

Solution (Python):
N = int(input())
s = []
for i in range(N-1):
    C,S,F = map(int,input().split(" "))
    s.append([C,S,F])
for i in range(N):
    if i == N-1:
        print(0)
    else:
        time = 0
        for j in range(i,N-1):
            C,S,F = s[j]
            if time < S:
                time = S + C
            else:
                if (time-S)%F == 0:
                    time += C
                else:
                    time += (F - (time-S)%F)
                    time += C
        print(time)

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

for i in range(n-1):
    s[i]=l[i][0]+l[i][1]
    
    for j in range(i):
        if s[j]<=l[i][1]:
            s[j]=s[i]
        else:
            if s[j]%l[i][2]==0:
                s[j]=l[i][0]+l[i][2]*(s[j]//l[i][2])
            else:
                s[j]=l[i][0]+l[i][2]*(s[j]//l[i][2]+1)
for i in range(n):
    print(s[i])

Solution (Python):
def ans(station,start):
    global c
    global s
    global f
    global n

    if(station==n-1):
        return start
    if(start<=s[station]):
        return ans(station+1,s[station]+c[station])
    else:
        if(start%f[station]==0):
            return ans(station+1,start+c[station])
        else:
            return ans(station+1,start + (f[station] - start%f[station]) + c[station])





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())

for i in range(n):
    print(ans(i,0))

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

Solution (Python):
n = int(input())
a = []
for i in range(n - 1):
    a.append([int(m) for m in input().split()])

cp = 0
for i in range(n):
    if i == n - 1:
        print(0)
    else:
        for j in range(i, n - 1):
            if cp == 0:
                k = a[j][1] + a[j][0]
            else:
                if k < a[j][1]:
                    k = a[j][1]
                    k += a[j][0]
                else:
                    if (k - a[j][1]) % a[j][2] == 0:
                        r = 0
                    else:
                        r = a[j][2] - (k - a[j][1]) % a[j][2]
                    k += a[j][0]
                    k += r
            cp = 1
        print(k)
        cp = 0

Solution (Python):
N = int(input())
c=[]
s=[]
f=[]
t=[0]*N
for i in range(N-1):
    ci, si, fi = map(int, input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)

t[N-1]=0
t[N-2]=s[N-2]+c[N-2]
for i in range(N-3,-1,-1):

    t[i]=c[i]+s[i]
    for j in range(i,N-2):
        if t[i]<=s[j+1]:
            t[i]=t[i+1]
            break
        else:
            if t[i]%f[j+1]!=0:
                t[i]=t[i]+(f[j+1]-t[i]%f[j+1])+c[j+1]
            else:
                t[i]=t[i]+c[j+1]
for i in range(len(t)):
    print(t[i])

Solution (Python):

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

times = [0] * N
for i_start in range(N - 1):
    time = 0
    for Ci, Si, Fi in CSF[i_start:]:
        
        time = max(Si, time)
        
        time += Fi - (time % Fi) if time % Fi > 0 else 0
        
        time += Ci
    
    times[i_start] = time

for time in times: print(time)

Solution (Python):
from math import ceil
import sys
def 解():
    iN = int(sys.stdin.readline())
    aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
    
    

    for i in range(iN-1):
        Tjb = aData[i][0] + aData[i][1]
        for j in range(i+1,iN-1):
            Cj = aData[j][0]
            Sj = aData[j][1]
            Fj = aData[j][2]
        
            Tjb = max( ceil(Tjb/Fj),Sj//Fj)*Fj+Cj
        print(Tjb)
    print(0)
解()

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

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

Solution (Python):
N = int(input())
src = [tuple(map(int, input().split())) for i in range(N-1)]

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

Solution (Python):
n = int(input())
csf = []

for i in range(n - 1):
    csf.append(list(map(int, input().split())))

for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        t = max(t, csf[j][1])
        if t % csf[j][2] > 0:
            t += csf[j][2] - t % csf[j][2]
        t += csf[j][0]
    print(t)
print(0)

Solution (Python):
n = int(input())
c = [None for _ in range(n - 1)]
s = [None for _ in range(n - 1)]
f = [None for _ in range(n - 1)]
for i in range(n - 1):
    c[i], s[i], f[i] = map(int, input().split())
for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        if t < s[j]:
            t = s[j] + c[j]
        elif t % f[j] == 0:
            t += c[j]
        else:
            t += f[j] - t % f[j] + c[j]
    print(t)
print(0)

Solution (Python):
def head(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

N = int(input())
Info = [[int(i) for i in input().split()] for j in range(N-1)]

for i in range(N):
    if i == N-1:
        print(0)
    else:
        now = 0
        for j in range(i, N-1):
            start = (Info[j][1] if now <= Info[j][1] else Info[j][1] + head(now-Info[j][1], Info[j][2]) * Info[j][2])
            now = start + Info[j][0]
        print(now)

Solution (Python):
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
  ci, si, fi=map(int, input().split())
  c.append(ci)
  s.append(si)
  f.append(fi)
for i in range(n):
  ans=0
  for j in range(i, n-1):
    if ans<s[j]:
      ans=s[j]
    ans=(ans+f[j]-1)//f[j]*f[j]+c[j]
  print(ans)

Solution (Python):

N = int(input())

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


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

    print(estime)

print(0)

Solution (Python):
class Station:
    def __init__(self, c, s, f):
        self.c = c
        self.s = s
        self.f = f


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

for i in range(N):
    arrive_time = 0
    for j in range(i, N-1):
        current_station = stations[j]
        next_time = current_station.c + arrive_time
        if arrive_time > current_station.s:
            next_time += (current_station.f - (arrive_time -
                                               current_station.s
                                               )) % current_station.f
        else:
            next_time += (current_station.s - arrive_time)
        arrive_time = next_time
    print(arrive_time)

Solution (Python):

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

for i in range(N-1):
    t=0
    for j in range(N-1):
        if j<i:
            continue
        if t<=CSF[j][1]:
            t=CSF[j][1]+CSF[j][0]
        elif (t-CSF[j][1])%CSF[j][2]==0:
            t=CSF[j][0]+CSF[j][1]+((t-CSF[j][1])//CSF[j][2])*CSF[j][2]
        else:
            t = CSF[j][0] + CSF[j][1] + ((t - CSF[j][1]) // CSF[j][2]+1) * CSF[j][2]
    ans[i]=t

for i in range(N):
    print(ans[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 j in range(N) :
    if j != N-1 :
        answer = 0
        for k in range(j,N-1) :
            if answer < S[k] :
                answer = S[k]
            if answer % F[k] != 0 :
                answer = (answer // F[k] + 1) * F[k]
            answer += C[k]
        print(answer)
    else :
        print(0)

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

for i in range(N):
    time=0
    for j in range(i,N-1):

        if time<CSF[j][1]:
            time=CSF[j][1]
        x=-((-time)//CSF[j][2])
        time=x*CSF[j][2]
        time+=CSF[j][0]
        

    print(time)

Solution (Python):
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N-1)]

for i in range(N-1):
    t = 0
    for c,s,f in src[i:]:
        t = max(t,s)
        t = -(-t//f)*f
        t += c
    print(t)
print(0)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
csf = [tuple(li()) for _ in range(n-1)]

for start in range(n-1):
    time = csf[start][1]
    for station in range(start,n-1):
        if time >= csf[station][1]:
            time = (-(-time//csf[station][2]))*csf[station][2]
            time += csf[station][0]
            
        else:
            time = csf[station][1]
            time += csf[station][0]
            
    print(time)
    
print(0)

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

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

for i in range(n-1):
    j = i
    ans = 0
    ans += list_prob[j][1]
    ans += list_prob[j][0]
    j += 1
    while j < n-1:
        if ans < list_prob[j][1]:
            ans = list_prob[j][1]
        else:
            if ans % list_prob[j][2] != 0:
                ans += (list_prob[j][2] - (ans % list_prob[j][2]))
            else:
                pass
        ans += list_prob[j][0]
        j += 1
    print(ans)
print(0)

Solution (Python):
n=int(input())

c=[]
s=[]
f=[]

for i 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):
    ans=0
    if i<n-2:
        j=i
        ans=c[j]+s[j]
        while j<n-2:
            if ans>=s[j+1]:
                if ans%f[j+1]==0:
                    ans+=c[j+1]
                else:
                    ans+=c[j+1]+f[j+1]-ans%f[j+1]
            else:
                ans=c[j+1]+s[j+1]                
            j+=1
        print(ans)
    elif i==n-2:
        print(c[n-2]+s[n-2])
    elif i==n-1:
        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)
for i in range(n - 1):
    ans = 0
    for j in range(i, n - 1):
        if ans < s[j]:
            ans = s[j]
        elif ans % f[j] == 0:
            pass
        else:
            ans += f[j] - ans % f[j]
        ans += c[j]
    print(ans)
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)
for j in range(N) :
    if j != N-1 :
        answer = 0
        for k in range(j,N-1) :
            if answer < S[k] :
                answer = S[k]
            if answer % F[k] != 0 :
                answer = (answer // F[k] + 1) * F[k]
            answer += C[k]
        print(answer)
    else :
        print(0)

Solution (Python):
n=int(input())
a=[]
for i in range(n-1):
    x,y,z=map(int, input().split())
    a.append([x,y,z])
for i in range(n):
    t=0
    for j in range(i,n-1):
        if t<=a[j][1] :t=a[j][1] + a[j][0]
        else:t=((t - a[j][1] + a[j][2]-1) // a[j][2]) * a[j][2] + a[j][1] + a[j][0]
    print(t)

Solution (Python):
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
    t = 0
    for j in range(i, N - 1):
        C = CSF[j][0]
        S = CSF[j][1]
        F = CSF[j][2]
        if t <= S:
            t = S
        elif t % F == 0:
            1
        else:
            t += F - t % F
        t += C
    print(t)
print(0)

Solution (Python):
import math

n = int(input())
c, s, f = [], [], []
for i in range(n-1):
    c_, s_, f_ = list(map(int, input().split()))
    c.append(c_)
    s.append(s_)
    f.append(f_)

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

Solution (Python):


def main():
    n = int(input())
    station_list = list(tuple(map(int, input().split())) for _ in range(n-1))
    for i in range(n-1):
        ans = 0
        for j in range(i, n-1):
            c, s, f = station_list[j]
            if ans <= s:
                ans = s
            elif ans % f != 0:
                ans += f - (ans % f)
            ans += c
        print(ans)
    print(0)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    tmp = [int(v) for v in input().split()]
    c.append(tmp[0])
    s.append(tmp[1])
    f.append(tmp[2])

ans = []
for i in range(n-1):
    t = s[i] + c[i]
    j = i + 1
    while j <= n - 2:
        if t <= s[j]:
            t = s[j] + c[j]
        else:
            if t % f[j] == 0:
                t += c[j]
            else:
                t += f[j] - (t % f[j]) + c[j]
        j += 1
    ans.append(t)

ans.append(0)
for line in ans:
    print(line)

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

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

C = [0]
S = [0]
F = [0]

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

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

Solution (Python):
li = lambda: list(map(int,input().split()))

n = int(input())
A = [li() for _ in range(n-1)]
c,s,f = [i for i in zip(*A)]
for k in range(n-1):
    t = s[k]+c[k]
    for i in range(k+1, n-1):
        if t < s[i]:
            t = s[i]
        else:
            t = -(-t//f[i]) * f[i]
        t += c[i]
    print(t)
print(0)

Solution (Python):


if __name__ == "__main__":
    N = int(input())
    Cs = []
    Ss = []
    Fs = []
    for i in range(N-1):
        C, S, F = list(map(int, input().split()))
        Cs.append(C)
        Ss.append(S)
        Fs.append(F)

    for i in range(N-1):
        ans = 0
        for j in range(i, N-1):
            if ans <= Ss[j]:
                
                ans = Ss[j] + Cs[j]
            else:
                
                if (ans - Ss[j]) % Fs[j] == 0:
                    
                    ans += Cs[j]
                else:
                    
                    ans += Cs[j] + Fs[j] - (ans - Ss[j]) % Fs[j]
        print(ans)
    print(0)

Solution (Python):
n = int(input())

if n == 1:
    print('0')
    exit()

c = [tuple(int(x) for x in input().split()) for _ in range(n - 1)]

c.append((0,0,1))

ans = [0 for _ in range(n)]

ans[n - 1] = 0

for i in range(n - 2, -1, -1):
    temp = c[i][0] + c[i][1]
    if temp <= c[i + 1][1]:
        ans[i] = 0 + ans[i + 1]
    else:
        for j in range(i + 1, n - 1):
            if c[j][1] >= temp:
                temp = c[j][1] + c[j][0]
            else:
                d = (temp - c[j][1]) // c[j][2]
                if ((temp - c[j][1]) % c[j][2]) != 0:
                    d += 1
                temp = c[j][1] + c[j][2] * d + c[j][0]
        ans[i] = temp

for x in ans:
    print(x)

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())

for i in range(n - 1):
    total = 0
    for j in range(i, n - 1):
        if total < s[j]:
            total = s[j]
        elif (total - s[j]) % f[j]:
            total += f[j] - total % f[j]
        total += c[j]
    print(total)
print(0)

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

for i in range(N - 1):
    sec = 0
    for j in range(i, N - 1):
        if sec < S[j][1]:
            sec = S[j][1]
        elif (sec - S[j][1]) % S[j][2]:
            sec += S[j][2] - sec % S[j][2]
        sec += S[j][0]
    print(sec)
print(0)

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] = list(map(int, input().split()))
T = [0] * N
Time = 0
for i in range(N-1):
    for j in range(0, i+1):
        tmp = 0
        if T[j] < S[i]:
            T[j] = S[i] + C[i]
        else:
            tmp = -(-(T[j] - S[i]) // F[i])
            T[j] = S[i] + F[i] * tmp + C[i]
for i in range(N):
    print(T[i])

Solution (Python):
n = int(input())

arr = [map(int,raw_input().split()) for i in range(n-1)]

def ceil(n,d):
	if n%d==0:
		return n/d

	else:
		return n/d+1

for i in range(n):
	t = 0

	for j in range(i,n-1):
		c,s,f = arr[j]
		t = max(ceil(t,f)*f, s) + c


	print t

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



for i in range(1, n + 1):
    
    t = 0

    if i == n:
        print(0)
    else:
        for j in range(i, n):
            
            C_j, S_j, F_j = train_info[j - 1]
            if t <= S_j:
                t = S_j + C_j
            elif t % F_j == 0:
                t += C_j
            else:
                t += F_j - t % F_j
                t += C_j

        print(t)

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

trains = []
for i in range(1, N):
    trains.append(list(map(int, input().split())))

for i in range(1, N+1):
    if i == N:
        print(0)
        continue
    result_time = 0
    for j, train in enumerate(trains):
        if j + 1 < i:
            continue
        c, s, f = train
        if result_time < s:
            result_time = s
        else:
            while result_time % f != 0:
                result_time += 1
        result_time += c

    print(result_time)

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


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

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

    for i in range(len(L)):
        x = 0
        for c, s, f in L[i:]:
            if x <= s:
                x = s + c
            else:
                x = s + f * ceil(x - s, f) + c
        print(x)
    print(0)


if __name__ == '__main__':
    main()

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

def f(i):
	s = 0
	while i < N-1:
		
		if s <= S[i]:
			s = S[i]+C[i]
		else:
			m = (s-S[i]) % F[i]
			if m == 0:
				s = s + C[i]
			else:
				s = s + (F[i]-m) + C[i]
			
		i += 1
	return s

for i in range(N):
	print(f(i))

Solution (Python):



def main():
    N = input()
    C = [0] * (N - 1)
    S = [0] * (N - 1)
    F = [0] * (N - 1)

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

    t = 0
    for j in xrange(N - 1):
        for i in xrange(N - 1):
            if i + j == N - 1:
                break
            t = spend_waited_time(t, S[i + j], F[i + j])
            t += C[i + j]

        print(t)
        t = 0

    print(0)


def spend_waited_time(t, S, F):
    if t <= S:  
        t = S
    elif S < t:  
        a = (t - S) % F
        if a == 0:
            pass
        else:
            t += F - abs(a)

    return t


if __name__ == "__main__":
    main()

Solution (Python):
import math
import sys

input = sys.stdin.readline

N = int(input())
trains = [[int(x) for x in input().split()] for _ in range(N - 1)]

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

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, s, f = map(int, input().split())
  C[i] = c
  S[i] = s
  F[i] = f
T = [0] * N
for i in range(N - 1):
  for j in range(i + 1):
    T[j] = max(S[i], T[j])
    T[j] = math.ceil(T[j] / F[i]) * F[i]
    T[j] += C[i]
for t in T:
  print(t)

Solution (Python):
N = int(input())
csf = [[int(x) for x in input().split()] for _ in range(N - 1)]

from math import ceil
def f(t, i):
    for j in range(i, N - 1):
        c, s, f = csf[j]
        d, m = divmod(t, f)
        t = max(s, ceil(t / f) * f) + c
    return t

for i in range(N):
    print(f(0, i))

Solution (Python):
from math import ceil
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())

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

  print(t)

print(0)

Solution (Python):
n=int(input())
c, s, f=[] ,[],[]
ans = []
for i in range(n-1):
    pc, ps, pf = map(int, input().split())
    c.append(pc)
    s.append(ps)
    f.append(pf)

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=t+f[j]-t%f[j]
        t+=c[j]
    print(t)

Solution (Python):
import math

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

for i in range(n):
    res = 0
    for t in range(i,n-1):
        c,s,f = csf[t]
        if res<=s:
            res = s + c
        else:
            s += f*math.ceil((res-s)/f)
            res = s + c
        
    print(res)

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

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

Solution (Python):

"""
Created on Fri Aug 10 02:27:58 2018

@author: Yuki
"""

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

def train_time(start_time=0, data_list=[12, 24, 6]):
    if data_list[1] <= start_time:
        return start_time + (data_list[2] - start_time%data_list[2])%data_list[2] + data_list[0]
    else:
        return data_list[1] + data_list[0]




res = []
for i in range(N-1):
    need_time = 0
    for ii in range(i, N-1):
        need_time = train_time(need_time, data[ii])
    res.append(need_time)

for i in range(N-1):
    print(res[i])
print(0)

Solution (Python):

n = int(input())
c = []
s = []
f = []

for _ in range(n-1):
    line = input().split(" ")
    c.append(int(line[0]))
    s.append(int(line[1]))
    f.append(int(line[2]))

def calc(idx, t):
    
    ret = 0
    if idx==n-1:
        return t

    if t<s[idx]:
        t = s[idx]

    if t%f[idx]==0:
        return calc(idx+1, t+c[idx])
    else:
        return calc(idx+1, (t//f[idx]+1)*f[idx]+c[idx])


for i in range(n):
    
    print(calc(i, 0))

Solution (Python):
import math
n = int(input())
x = []
for i in range(n-1):
    x1,y1,z1=[int(i) for i in input().split()]
    x.append([x1,y1,z1])
dp = [0 for i in range(n)]
for i in range(0,n):
  ans = 0
  j = i+0
  while j < n-1:
    a = x[j]
    b = math.ceil(ans/x[j][2]) * x[j][2]
    if b < x[j][1]:
      b = x[j][1]
    ans = b + x[j][0]
    j += 1
  dp[i] = ans
for i in dp:
  print(i)

Solution (Python):
N=int(input())
list1=[]
for i in range(N-1):
    A=input()
    A=A.rstrip().split(" ")
    list1.append([int(A[0]),int(A[1]),int(A[2])])


t=0
for k in range(N-1):
    for j in range(N-1-k):
        if t<list1[j+k][1]:
            t=list1[j+k][1]
        if (t-list1[j+k][1])%list1[j+k][2]==0:
            pass
        else:
            t+=list1[j+k][2]-(t-list1[j+k][1])%list1[j+k][2]
        t+=list1[j+k][0]
    print(t)
    t=0
print(0)

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


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