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):
import math

N = int(input())

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

for i in range(0, N - 1):
    arrive_time = CSFs[i][0] + CSFs[i][1]
    for j in range(i + 1, N - 1):
        if arrive_time <= CSFs[j][1]:
            arrive_time = CSFs[j][1]
        elif arrive_time % CSFs[j][2] == 0:
            arrive_time = arrive_time
        else:
            
            k = math.ceil((arrive_time - CSFs[j][1]) / CSFs[j][2])
            arrive_time = CSFs[j][1] + CSFs[j][2] * k
        arrive_time += CSFs[j][0]
    print(arrive_time)
print(0)

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

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

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

Solution (Python):
import math
N = int(input())
ST = [[int(i) for i in input().split()] for j in range(N-1)]
for i in range(N-1):
    t = ST[i][1] + ST[i][0]
    for j in range(i+1,N-1):
        t = max(t, ST[j][1])
        k = math.ceil((t-ST[j][1])/ST[j][2])
        t = k * ST[j][2] + ST[j][1] + ST[j][0]
    else:
        print(t)
print(0)

Solution (Python):
l = input().split()
N = int(l[0])

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

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



for i in range(N - 1):
    spent = 0
    for j in range(i, N - 1):
        c = C[j]
        s = S[j]
        f = F[j]
        if spent < s:
            spent = s
        remain = (spent - s) % f
        if remain != 0:
            spent += f - remain
        spent += c
    print(spent)
print(0)

Solution (Python):

import sys


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):

    CSF = list(zip(C,S,F))

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

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = [int()] * (N-1)  
    S = [int()] * (N-1)  
    F = [int()] * (N-1)  
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

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


def solve(c,s,f,i,cnt,n):
    if i == n-1:
        return print(cnt)
    else:
        if cnt < s[i]:
            cnt = s[i]
        loss = (cnt-s[i])%f[i]
        if loss == 0:
            return solve(c,s,f,i+1,cnt+c[i],n)
        else:
            return solve(c,s,f,i+1,cnt+c[i]+(f[i]-loss),n)

for i in range(n):
    solve(c,s,f,i,0,n)

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

for i in range(N):
    for j in range(N-i-1):
        if dp[i] >= para[i+j][1] and dp[i]%para[i+j][2] == 0 :
            dp[i] += para[i+j][0]
        elif  dp[i] < para[i+j][1]: 
            dp[i] = para[i+j][1] + para[i+j][0]
        else:
            a = dp[i] // para[i+j][2] 
            dp[i] = (a+1)*para[i+j][2] + para[i+j][0]
    print(dp[i])

Solution (Python):



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

for i in range(n - 1):
    current_time = 0
    for data in inputs[i:]:
        c, s, f = data
        if current_time < s:
            
            current_time = s
        else:
            
            
            
            
            left, right = 0, 10 ** 9
            while left < right:
                mid = (left + right) // 2
                if (s + f * mid) >= current_time:
                    right = mid
                else:
                    left = mid + 1
            
            current_time = s + f * left
        
        current_time += c
    print(current_time)

print(0)

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

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



def next_start_time(arrive, C, S, F):
    for i in range(1000):
        if arrive > S:
            i = (arrive - S) // F
            if arrive <= S + i * F:
                break
            else:
                i = i + 1
                break
        elif arrive <= S + i * F:
            break
    return S + (i * F) + C


for i in range(N - 1):
    ans = 0
    for j in range(i, N - 1):
        ans = next_start_time(ans, station[j][0], station[j][1], station[j][2])
    print(ans)

print(0)

Solution (Python):
N = int(input())
ans = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    
    for i,a in enumerate(ans):
        if (a-s)%f == 0 and a > s:
            ans[i] += c
        elif a < s:
            ans[i] = c + s
        else:
            ans[i] += c + f - (a-s) % f
    ans.append(c+s)

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

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

C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)

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

for t in range(0, N - 1):
    route_time = S[t]
    for i in range(t, N - 1):
        route_time = route_time + C[i]
        if i != N - 2:
            if route_time >= S[i + 1] and route_time % F[i + 1] == 0:
                continue
            elif route_time >= S[i + 1] and route_time % F[i + 1] != 0:
                route_time = (route_time // F[i + 1]) * F[i + 1] + F[i + 1]
            else:
                route_time = S[i + 1]
    print(route_time)
            
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):
    if j == N-1:
      print(time)
      break 
    if time < CSF[j][1]:
      time = CSF[j][0] + CSF[j][1]
    elif time % CSF[j][2] == 0:
      time += CSF[j][0]
    else:
      time += CSF[j][0] + (CSF[j][2] - time % CSF[j][2])

Solution (Python):
n = int(input())
CSF = [list(map(int,input().split())) for _ in range(n-1)]
Ans = []
from math import ceil
count = 0
for c,s,f in CSF:
    for i in range(count):
        Ans[i] = max(ceil(Ans[i]/f)*f + c , s + c)
    count += 1
    Ans.append(s+c)
print(*Ans,sep = "\n")
print(0)

Solution (Python):
import math


def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num - 1)]

    for i in range(num - 1):
        c, s, f = data[i]
        now_time = s + c
        for j in range(i + 1, num - 1):
            c_now, s_now, f_now = data[j]
            if now_time <= s_now:
                now_time = s_now + c_now
            else:
                now_time = math.ceil(now_time / f_now) * f_now + c_now
        print(now_time)
    print(0)



if __name__ == '__main__':
    main()

Solution (Python):
import math
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  ci, si, fi = list(map(int, input().split()))
  c.append(ci)
  s.append(si)
  f.append(fi)

for i in range(n-1):
  t = s[i]
  for j in range(i, n-2):
    t = t + c[j]

    if t > s[j+1]:
      cycle = math.ceil((t - s[j+1]) / f[j+1])
      t = s[j+1] + cycle * f[j+1]
    else:
      t = s[j+1]
  t = t + c[n-2]
  print(t)
print(0)

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

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


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

Solution (Python):
import math
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    ci,si,fi=list(map(int,input().split()))
    c.append(ci)
    s.append(si)
    f.append(fi)

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

Solution (Python):
from math import ceil

n = int(input())

cs = []
ss = []
fs = []

for _ in range(n-1):
    c, s, f = map(int, input().split())
    cs.append(c)
    ss.append(s)
    fs.append(f)

for i in range(n):
    t = 0
    for j in range(i, n-1):
        if t < ss[j]:
            t = ss[j]
        t = ceil(t / fs[j]) * fs[j]
        t += cs[j]
    print(t)

Solution (Python):

import sys


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    ret = []
    for i in range(N - 1):
        tmp = 1
        for j in range(i, N - 1):
            if tmp > S[j]:
                tmp = ((tmp - S[j] - 1) // F[j] + 1) * F[j] + S[j] + C[j]
            else:
                tmp = S[j] + C[j]
        ret.append(tmp)
    ret.append(0)
    for r in ret:
        print(r)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = [int()] * (N-1)  
    S = [int()] * (N-1)  
    F = [int()] * (N-1)  
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(len(CSF)):
    ans = 0
    ans += CSF[i][1] + CSF[i][0]
    for j in range(i + 1, len(CSF)):
        if ans < CSF[j][1]:
            ans += CSF[j][1] - ans
        if ans % CSF[j][2] == 0:
            pass
        else:
            ans += CSF[j][2] - ans % CSF[j][2]
        ans += CSF[j][0]

    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):
    t=0
    for i in range(j,N-1):
        if t<=S[i]:
            t=S[i]+C[i]
        else:
            t1=S[i]
            while(t1<t):
                t1+=F[i]
            t=t1+C[i]
    print(t)

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

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

ans = []
for i in range(N - 1):
    cnt = 0
    for j in range(i, N - 1):
        if cnt < X[j][1]:
            st = X[j][1]
        elif cnt % X[j][2] == 0:
            st = cnt
        else:
            st = cnt + X[j][2] - (cnt % X[j][2])
        cnt = st + X[j][0]
    ans.append(cnt)
ans.append(0) 
print(*ans, sep='\n')

Solution (Python):

import sys
INF = float("inf")


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):

    def hasha(curr, ith):
        if curr > S[ith]:
            return S[ith] + F[ith]*(-(-(curr-S[ith])//F[ith]))
        else:
            return S[ith]

    ans = []
    for i in range(N-1):        
        buf = 0
        for j in range(i, N-1):  
            buf = hasha(buf, j) + C[j]
        ans.append(buf)
    print(*ans, sep="\n")
    print("0")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    C = [int()] * (N-1)  
    S = [int()] * (N-1)  
    F = [int()] * (N-1)  
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)


if __name__ == '__main__':
    main()

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N = int(input())
    C = []
    S = []
    F = []
    for i in range(N-1):
        s1, s2, s3 = (int(_) for _ in input().split())
        C.append(s1)
        S.append(s2)
        F.append(s3)
    ans = []
    for h in range(N-1):
        time = 0
        for i in range(h,N-1):
            if i ==h:
                time=S[i]+C[i]
                continue
            if time <= S[i]:
                time=S[i]+C[i]
            else:
                tmp_t = S[i]
                while time > tmp_t:
                    tmp_t += F[i]
                time = tmp_t +C[i]
        ans.append(time)
    print('\n'.join(str(_) for _ in ans))
    print(0)
    
if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(1,N+1):
    if i == N:
        print(0)
        break
    time = 0
    for j in range(i,N):
        if time == 0:
            time += CSF[j-1][1]  
        else:
            if time < CSF[j-1][1]:
                time = CSF[j-1][1]
           
            while time % CSF[j-1][2] != 0:  
                time +=1   
        time += CSF[j-1][0]  
    print(time)

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

ans = [0] * N

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

    ans[i] = tmp
    print(ans[i])
        
print(ans[N-1])

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

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

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):
    j = i
    ans = 0
    while j < N-1:
        if ans < S[j]:
            ans = S[j]+C[j]
        else:
            if ans % F[j] == 0:
                ans = ans + C[j]
            else:
                ans = ans + (F[j] - (ans % F[j])) + C[j]
        j += 1
    print(ans)

Solution (Python):
import numpy as np

N = int(input())
CSF = [
  [int(i) for i in input().split()]
  for _ in range(N-1)]
CSF.append([0, 0, 1])

ans = []

for n in range(N-1):
    c, s, f = CSF[n]
    cn, sn, fn = CSF[n+1]
    
    for m in range(N-n-2):
                
        if s+c > sn:
            sn = int(np.ceil((s+c)/fn)*fn)
        c, s, f = cn, sn, fn
        cn, sn, fn = CSF[n+m+2]
        
    ans.append(s+c)
    
ans.append(0)

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

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

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

        t += c
    print(t)

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

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

for i in range(N-1):
	res = 0
	for c,s,f in CSF[i:]:
		if res < s:
			res = s
		if res % f != 0:
			res += f - res % f
		res += c
	ans.append(res)
ans.append(0)
for a in ans:
	print(a)

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

Solution (Python):
N = int(input())
c = [list(map(int, input().split()))for _ in range(N - 1)]
for j in range(N):
    nowt = 0
    for i in range(j, N - 1):
        f = c[i][2]
        nowt = max(c[i][1], (nowt + f - 1) // f * f) + c[i][0]
    print(nowt)

Solution (Python):
N=int(input())
ans=[0]*N
for i in range(1,N):
    C,S,F=map(int,input().split())
    for j in range(i):
        ans[j]=max(S,((F+ans[j]-1)//F)*F)+C
[print(x) for x in ans]

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

for i in range(n):
    point = i
    ans = 0
    while point < n-1:
        c, s, f = csf[point][0], csf[point][1], csf[point][2]
        if ans < s:
            ans += s-ans+c
        else:
            if ans%f != 0:
                ans += f-(ans%f)
            ans += c
        point += 1
    print(ans)

Solution (Python):
import math
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]
for k in range(N):
  t = 0
  for i in range(N-1-k):
    j = k + i
    if t <= CSF[j][1]:
      t = CSF[j][1] + CSF[j][0]
    else:
      t = math.ceil((t-CSF[j][1])/CSF[j][2])*CSF[j][2]+CSF[j][1]+CSF[j][0]
  print(t)

Solution (Python):
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=arr[i][0]+arr[i][1]
  for j in range(i+1,n-1):
    if ans<=arr[j][1]:
      ans=arr[j][0]+arr[j][1]
    else:
      if (ans-arr[j][1])%arr[j][2]==0:
        ans+=arr[j][0]
      else:
        ans+=arr[j][0]+arr[j][2]-ans%arr[j][2]
  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)
T=[0 for i in range(n)]
for i in range(n-1):
  t=S[i]+C[i]
  for j in range(i+1,n-1):
    if t<S[j]:
      t=S[j]
    else:
      t=S[j]+F[j]*((t-S[j]-1)//F[j]+1)
    t+=C[j]
  T[i]=t
print(*T,sep="\n")

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

import math

for i in range(n):
    if i == n - 1:
        print(0)

    else:
        
        time = csf[i][1] + csf[i][0] 

        if i != n - 2:
            station = i
            while True:
                station += 1
                c = csf[station][0]
                s = csf[station][1]
                f = csf[station][2]
                time = math.ceil(max(time - s, 0) / f) * f + s
                time += c

                if station == n-2:
                    break

        print(time)

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

def start_from(i,t):
  if i==N:
    return t
  else:
    c,s,f = CSF[i]
    departure = max(s, (t//f + bool(t%f))*f)
    return start_from(i+1, departure + c)
  
for i in range(1,N):
  print(start_from(i, 0))
print(0)

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    trains = []
    for i in range(n-1):
        trains.append(f())

    for i in range(n):
        time = 0
        for train in trains[i:]:
            start_time = (time//train[2] +  (0 if time%train[2]==0 else 1))* train[2] if time > train[1] else train[1]
            time = start_time + train[0]

        print(time)

        

solve()

Solution (Python):
n = int(input())
temp = 0
stations = list()

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


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

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

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

o = []
for i in range(N):
    s = 0
    while i < N - 1:
        C = CSF[i][0]
        S = CSF[i][1]
        F = CSF[i][2]
        s = (s//F+1)*F if s%F else s
        s = max(s,S)
        s += C
        i += 1
    o.append(s)

print('\n'.join(map(str,o)))

Solution (Python):

def read_input():
    n = int(input())

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

    return n, stations



def time_calc(curr, station):
    if curr <= station[1]:
        return station[0] + station[1]

    diff = curr - station[1]
    if diff % station[2] == 0:
        coef = diff // station[2]
    else:
        coef = diff // station[2] + 1
    return station[0] + station[1] + coef*station[2]


def total_time(stations):
    curr = 0
    for station in stations:
        curr = time_calc(curr, station)

    return curr


def submit():
    n, stations = read_input()

    for i in range(n - 1):
        print(total_time(stations[i:]))
    print(0)

if __name__ == '__main__':
    submit()

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):
    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())
l=[]
for i in range(n-1):
  l1=list(map(int,input().split()))
  l.append(l1)
for i in range(n-1):
  t=0
  t+=l[i][1]+l[i][0]
  for j in range(i+1,n-1):
    if t<l[j][1]:
      t=l[j][1]
      t+=l[j][0]
    else:
      t+=(l[j][2]-t%l[j][2])%l[j][2]
      t+=l[j][0]
  print(t)
print(0)

Solution (Python):
def main():
    N = int(input())
    csf = []
    for _ in range(N - 1):
        C, S, F = map(int, input().split())
        csf.append((C, S, F))
    
    ans = []
    for i in range(N - 1):
        c, s, _  = csf[i]
        t = c + s
        for ii in range(i + 1, N - 1):
            nc, ns, nf = csf[ii]
            if t > ns:
                ns += ((t - ns) // nf) * nf
                if (t - ns) % nf != 0:
                    ns += nf
            t += nc + ns - t
        ans.append(t)
    ans.append(0)
    
    for t in ans:
        print(t)
    

main()

Solution (Python):
def main():
    N = int(input())
    csf = []
    for _ in range(N - 1):
        C, S, F = map(int, input().split())
        csf.append((C, S, F))
    
    ans = []
    for i in range(N - 1):
        c, s, _  = csf[i]
        t = c + s
        for ii in range(i + 1, N - 1):
            nc, ns, nf = csf[ii]
            if t > ns:
                if (t - ns) % nf == 0:
                    ns += ((t - ns) // nf) * nf
                else:
                    ns += ((t - ns) // nf + 1) * nf
            t += nc + ns - t
        ans.append(t)
    ans.append(0)
    
    for t in ans:
        print(t)
    

main()

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):
    time = 0
    for j in range(i, N-1):
        if time < S[j]:
            time = S[j]
        elif time % F[j]:
            time += F[j] - (time % F[j])
        time += C[j]

    print(time)

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

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

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




for i in range(n):
    p = i
    t = 0
    while p!=n-1:
        
        if t > l[p][1]:
            if t%l[p][2] != 0:
                t += l[p][2]-t%l[p][2]
        else:
            t = l[p][1]
        
        t += l[p][0]
        p += 1
    print(t)

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

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

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):
    t = 0
    for j in range(i,n-1):
        if t < s[j]:
            t = s[j]
        elif t % f[j] == 0:
            pass
        else:
            t += f[j] - t % f[j]
        t += c[j]
    print(t)
print(0)

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

Solution (Python):
N = int(input())
C,S,F = [],[],[]
time = []
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 = S[i]+C[i] 
  for j in range(i+1,N-1):
    if(t<S[j]): 
     t = S[j]
    else: 
     
     if(t%F[j] == 0): tmp = 0
     else: tmp = F[j]-(t%F[j]) 
     t += tmp
    t += C[j] 
  time.append(t)
time.append(0)

for i in range(N):
 print(time[i])

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

for i in range(N):
    t = 0
    while i < N-1:
        if t < data[i][1]:
            t = data[i][1]
        if (t-data[i][1]) % data[i][2] != 0:
            t += data[i][2] - (t-data[i][1]) % data[i][2]
        t += data[i][0]
        i += 1
    print(t)

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

for i in range(N-1):
    t = csf[i][1] + csf[i][0]

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

print(0)

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

x=[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):
        c,s,f=x[j]
        if time==0:
            time=c+s
        else:
            if time<s:
                time=s+c
            else:
                time=(time//f+(time%f>0))*f+c
        
    print(time)

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):
  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());c,s,f=[0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1):c[i],s[i],f[i]=map(int,input().split())
for i in range(n-1):
  d=c[i]+s[i]
  for j in range(i+1,n-1):d=max(((d-s[j]-1)//f[j]+1)*f[j]+s[j],s[j])+c[j]
  print(d)
print(0)

Solution (Python):
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))

n = II()
train = [list(MI()) for _ in range(n-1)]

for i in range(n-1):
    
    time = train[i][0] + train[i][1]
    for j in range(i+1, n-1):
        
        if time < train[j][1]:
            
            time = train[j][1]
        elif time % train[j][2] == 0:  
            pass
        else: 
            time += (train[j][2] - (time % train[j][2]))

        time += train[j][0]  

    print(time)
print(0)

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

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

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

print(0)