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())
C, S, F = [], [], []
for _ in range(N-1):
    c,s,f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)


def time_arrive_next_sta(arrival_time, idx):
    if S[idx] <= arrival_time and arrival_time%F[idx] == 0:
        return arrival_time + C[idx]
    elif S[idx] > arrival_time:
        return S[idx] + C[idx]
    else:
        return arrival_time + C[idx] + (F[idx] - arrival_time%F[idx])

ans = []
for i in range(N-1):
    tmp = 0
    for j in range(i, N-1):
        tmp = time_arrive_next_sta(tmp, j)
    ans.append(tmp)

ans.append(0)

for x in ans:
    print(x)

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-1):
  t = S[i] + C[i]
  i += 1
  while i < N - 1:
    if t == S[i]:
      pass
    elif t > S[i]:
      if t - S[i] % F[i] == 0:
        pass
      else:
        t += F[i] * -(-(t - S[i]) // F[i]) - (t - S[i])
    else:
      t = S[i]
    t += C[i]
    i += 1
  print(t)
print(0)

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

Solution (Python):
n = int(input())
ary = [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 <= ary[j][1]:t = ary[j][1]
        elif t % ary[j][2] == 0:t += 0
        else: t += ary[j][2] - (t % ary[j][2])
        t += ary[j][0]
    print(t)

Solution (Python):

n = int(input())
stations = []

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

def solve(t,i,stations):
    if i == n-1:
        return t
    c,s,f = stations[i]
    t = max(int((t-0.1)//f + 1)*f,s)
    return solve(t+c,i+1,stations)

for i in range(n):
    print(solve(0,i,stations))

Solution (Python):
n = int(input())
l = [[int(x) for x in input().split()] for _ in range(n-1)]
for i in range(n-1):
    ans = 0
    ans += l[i][1] + l[i][0]
    for j in range(i+1, n-1):
        if ans < l[j][1]: ans = l[j][1]
        if ans % l[j][2] != 0:
            ans += l[j][2] - ans % l[j][2]
        ans += l[j][0]
    print(ans)
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):
    ct, st, ft = map(int, input().split())
    c[i] = ct
    s[i] = st
    f[i] = ft

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

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

ans = []  
time = 0
for i in range(N-1):
    
    time = station[i][1]  
    time += station[i][0]  
    for j in range(i+1, N-1):  
        
        if station[j][1] >= time:  
            time = station[j][1]  
            time += station[j][0]  
            continue  
        else:  
        
            tmp = time
            tmp -= station[j][1]
            teisuubai = math.ceil(tmp/station[j][2])
            time = station[j][1] + teisuubai * station[j][2]
            time += station[j][0]
    ans.append(time)

ans.append(0)

for a in ans:
    print(a)

Solution (Python):
N = int(input())
A = [list(map(int,input().split())) for _ in range(N-1)]
T = []
for i in range(N-1):
    t = A[i][1]+A[i][0]
    for j in range(i+1,N-1):
        if t<=A[j][1]:
            t = A[j][1]+A[j][0]
        else:
            if t%A[j][2]==0:
                t += A[j][0]
            else:
                t = (t//A[j][2]+1)*A[j][2]+A[j][0]
    T.append(t)
T.append(0)
for i in range(N):
    print(T[i])

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


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

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

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

Solution (Python):
N=int(input())
ans=[0]*N
def nex(a,ls):
  x=(-a)%ls[2]
  return max([ls[1],a+x])+ls[0]
M=N-1
for i in range(M):
  station=[int(s) for s in input().split()]
  for j in range(i+1):
    ans[j]=nex(ans[j],station)
for e in ans:
  print(e)

Solution (Python):
import math

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

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

Solution (Python):
n = int(input())
ary = [list(map(int,input().split())) for i in range(n-1)]
time = 0
dp = [0]*n
for i in range(n-1):
    time = 0
    for j in range(i,n-1):
        if time <= ary[j][1]: time = ary[j][1]
        elif time > ary[j][1]:
            if time % ary[j][2] == 0:time += 0
            else:time += ary[j][2] - time % ary[j][2]
        time += ary[j][0]
    print(time)
print(0)

Solution (Python):
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    stations = list(map(string_to_int, inputs))
    N = len(stations)
    ret = []
    for i, s in enumerate(stations):
        [C, S, F] = s
        t = S + C
        for j in range(i+1, N):
            if t < stations[j][1]:
                t = stations[j][0] + stations[j][1]
            else:
                w = (t - stations[j][1]) % stations[j][2]
                waiting = 0 if w == 0 else stations[j][2] - w
                t += waiting + stations[j][0]
        ret.append(t)
    ret.append(0)
    return ret


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N-1))
    for r in ret:
        print(r)

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

for i, (c, s, f) in enumerate(csf):
    t = s + c
    for j in range(i + 1, n - 1):
        C, S, F = csf[j][0], csf[j][1], csf[j][2]
        t = max(t, S)
        t = -(-t // F) * F + C
    print(t)
print(0)

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

for i, (c, s, f) in enumerate(csf):
    t = s + c
    for j in range(i + 1, n - 1):
        C, S, F = csf[j][0], csf[j][1], csf[j][2]
        if t < S:
            t = S + C
        else:
            if (t - S) % F == 0:
                t += C
            else:
                t += F - (t-S) % F + C
    print(t)
print(0)

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

f = 0
station = 0
for i, (c, s, f) in enumerate(csf):
    t = s + c
    for j in range(i + 1, n - 1):
        C, S, F = csf[j][0], csf[j][1], csf[j][2]
        if t < S:
            t = S + C
        else:
            if (t - S) % F == 0:
                t += C
            else:
                t += F - (t-S) % F + C
    print(t)
print(0)

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

if N==1:
    print(0)
    exit()


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-1):
    Time=0
    for j in range(i,N-1):
        if j==i:
            Time=S[i]
        else:
            cnt=max(0,(Time+C[j-1]-S[j]-1+F[j])//F[j])
            Time=S[j]+F[j]*cnt
    Time+=C[N-2]
    print(Time)
print(0)

Solution (Python):
import sys
import itertools
from itertools import accumulate
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N = int(input())
c = [inputs() for _ in range(N-1)]
ans = [0]*(N)
start = [[0]*N for _ in range(N)]
for i in range(N-1):
    start[i][i] = c[i][1]
    for j in range(i,N-1):
        if ans[i]<c[j][1]:
            start[i][j] = c[j][1]
            ans[i] = c[j][1]+c[j][0]
        else:
            ttim=0
            if ans[i]%c[j][2]!=0:
                ttim=c[j][2]-(ans[i])%c[j][2]
            start[i][j] = ttim+ans[i]
            ans[i] = ttim+ans[i]+c[j][0]
print(*ans)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
c = []
s = []
f = []
for i in range(n-1):
    a,b,z = inpl()
    c.append(a)
    s.append(b)
    f.append(z)

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

Solution (Python):
n = int(input())
ary = [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 <= ary[j][1]:t = ary[j][1]
        elif t % ary[j][2] == 0:t += 0
        else: t += ary[j][2] - (t % ary[j][2])
        t += ary[j][0]
    print(t)

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

A=[0]*N

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

for i in A:
    print(i)

Solution (Python):
n=int(input())
lst=[]
for i in range(n-1):
  c,s,f=map(int,input().split())
  lst.append([c,s,f])
for j in range(n-1):
  time=lst[j][0]+lst[j][1]
  ind=j
  for k in range(n-j-2):
    if time<=lst[ind+1][1] :
      time=lst[ind+1][0]+lst[ind+1][1]
      ind+=1
    elif (time-lst[ind+1][1])%lst[ind+1][2]==0:
      time+=lst[ind+1][0]
      ind+=1
    else:
      time+=lst[ind+1][0]+lst[ind+1][2]-(time-lst[ind+1][1])%lst[ind+1][2]
      ind+=1
  print(time)
print(0)

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)
c.append(0)
s.append(0)
f.append(0)

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

    print(s_total)

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


for i in range(0,N):
  time = 0
  for j in range(i,N-1):
    if time < CSF[j][1]:
      time = CSF[j][1]
    elif time % CSF[j][2] == 0:
      time = time
    else:
      time = time + CSF[j][2] - (time % CSF[j][2])
    time = time + CSF[j][0]
  ans.append(time)

for i in ans:
  print i

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

for i in range(n-1):
	time = li[i][0] + li[i][1]
	for j in range(i+1, n-1):
		now = li[j][1]
		if now < time:
			now += li[j][2] * (-(-(time-now)//li[j][2]))
		time = now
		time += li[j][0]
	print(time)
print(0)

Solution (Python):


import math

def main(N,C,S,F):
    ans = [0]*N
    for i in range(N-2):
        tmp = S[i]+C[i]
        for j in range(i+1,N-1):
            if tmp<S[j]:
                tmp = S[j]
            elif tmp>S[j] and (tmp-S[j])%F[j]!=0:
                part = math.ceil((tmp-S[j])/F[j])
                tmp = S[j]+F[j]*part
            tmp += C[j]
        ans[i] = tmp
    ans[-2] = C[-1]+S[-1]
    
    for i in ans:
        print(i)

if __name__ == '__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)
    main(N,C,S,F)

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

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

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

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

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

for i in range(n-1):
    res = 0
    for j in range(i, n-1):
        c, s, f = station[j]
        if res == 0:
            res += s + c
        else:
            res += max(s-res, ((res+(f-1))//f)*f - res) + c
    print(res)
else:
    print(0)

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

res = []
for i in range(0,n-1):
    c = csfs[i][0]
    s =csfs[i][1]
    f = csfs[i][2]
    syuppatu = s
    toutyaku = s+c
    for j in range(i+1,n-1):
        if toutyaku < csfs[j][1]:
            syuppatu = csfs[j][1]
            toutyaku = syuppatu+csfs[j][0]
        else:
            syuppatu = ((toutyaku+csfs[j][2]-1) // csfs[j][2]) * csfs[j][2]
            toutyaku = syuppatu + csfs[j][0]
    res.append(toutyaku)
res.append(0)
for re in res:
    print(re)

Solution (Python):


import sys

sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7





N = int(input())
CSF = []
for _ in range(N-1):
    C, S, F = [int(x) for x in input().split()]
    CSF.append((C, S, F))

def f(i):
    ans_r = [0]
    cur = 0
    for c, s, f in CSF[i:]:
        cur = max(cur, s)
        if cur % f != 0:
            cur = cur + (f - (cur % f))
        
        cur += c
        
        ans_r.append(cur)

    return ans_r[-1]

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

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

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

for i in range(n):
  time = 0
  for j in range(i,n-1):
    
    time = max(-(-(time-Route[j][1])//Route[j][2])*Route[j][2],0)+Route[j][0]+Route[j][1]
    
  Station[i] = time
for s in Station:
  print(s)

Solution (Python):
import sys
input=sys.stdin.readline
import math

def main():
    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):
        t = 0
        for j in range(i,N-1):
            k = max(0, math.ceil((t - S[j])/F[j]))
            t = S[j] + k*F[j] + C[j]
        print(t)
    print(0)

if __name__ == '__main__':
    main()

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

for i in range(n-1):
    if i==0:
        ans.append(st[0][0]+st[0][1])
    else:
        for j in range(len(ans)):
            if ans[j]>=st[i][1] and ans[j]%st[i][2]==0:
                ans[j] += st[i][0]
            elif ans[j]<st[i][1]:
                ans[j] = st[i][0]+st[i][1]
            else:
                a = (ans[j]-st[i][1])%st[i][2]
                a = ans[j]-a
                ans[j] = a+st[i][2]+st[i][0]
        ans.append(st[i][0]+st[i][1])

ans.append(0)
for i in range(len(ans)):
    print(ans[i])

Solution (Python):
N = int(input())
c = [list(map(int, input().split())) for _ in range(N - 1)]
anslst = [0] * N
for i in range(N - 1):
    ans = c[i][1] + c[i][0]
    for j in range(i + 1, N - 1):
        if ans <= c[j][1]:
            ans += (c[j][1] - ans) + c[j][0]
        else:
            sho, amari = divmod(ans, c[j][2])
            if amari == 0:
                ans += c[j][0]
            else:
                ans += c[j][0] + (((sho + 1) * c[j][2]) - ans)

    anslst[i] = ans

for i in anslst:
    print(i)

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

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

Solution (Python):
import sys
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline

N = int(input())

ans = [0]

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

    for i in range(len(ans)):
        if s > ans[i]:
            ans[i] = s + c
        else:
            ans[i] = -(-ans[i] // f) * f + c

    ans.append(0)

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

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

ans = [0] * N
for i in range(N-1):
    for j in range(i+1):
        ans[j] = max(S[i], math.ceil(ans[j]/F[i]) * F[i]) + C[i]

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

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


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

Solution (Python):
import sys


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


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

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

    print(*ans, sep=" ")


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):
    t = 0

    for i in range(start, n - 1):
        if S[i] <= t:
            t = F[i] * (t // F[i] + (t % F[i] != 0))
        else:
            t = S[i]

        t += C[i]

    print(t)

print(0)

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


if __name__ == "__main__":
    resolve()

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n-1)]
    arr = []
    for i in range(len(csf)):
        arr.append(csf[i:])

    for x in arr:
        ans = x[0][0] + x[0][1]
        for c, s, f in x[1:]:
            if ans > s:
                if ans % f == 0:
                    ans += c
                else:
                    ans += c + f - ans % f
            else:
                ans = c + s
        print(ans)
    print(0)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n-1)]
    arr = []
    for i in range(len(csf)):
        arr.append(csf[i:])

    for x in arr:
        ans = x[0][0] + x[0][1]
        for c, s, f in x[1:]:
            if ans > s:
                if ans % f == 0:
                    ans += c
                else:
                    ans += c + f - ans % f
            else:
                ans = c + s
        print(ans)
    print(0)


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)

ans = [0] * N

for i in range(N-1):
    cnt = i
    ans[i] += S[i] + C[i]
    while cnt<N-2:
        if ans[i]<S[cnt+1]:
            ans[i] = S[cnt+1]
        if ans[i]%F[cnt+1]!=0:
            ans[i] += F[cnt+1] - ans[i]%F[cnt+1]
        ans[i] += C[cnt+1]
        cnt += 1

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

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

for sta in range(n):
  current = 0
  for i in range(sta, n-1):
    if(trains[i][1] >= current):
      current = trains[i][1]
    else:
      if(current % trains[i][2] != 0):
        current += trains[i][2] - (current % trains[i][2])
    current += trains[i][0]
  print(current)

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


def main():
    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-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] + 1) + C[j]
        print(t)
    print(0)


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

        
        t += C[j]
    print(t)
print(0)

Solution (Python):
def calc2(time,i):
    c1,s1,f1 = Data[i]

    t = max(time,s1)
    if t % f1 == 0:
        pass
    else:
        t = (t//f1+1)*f1
    return t+c1;

def calc(n,N):
    time = 0
    for i in range(n,N-1):
        time = calc2(time,i)
    return time

N = int(input())
Data = []
Ans = []
for _ in range(N-1):
    c,s,f = map(int,input().split())
    Data.append([c,s,f])
for i in range(N-1):
    print(calc(i,N))
print(0)

Solution (Python):
n=int(input())
lists=[list(map(int,input().split())) for _ in range(n-1)]  
for x in range(n):
    nums=x+1
    if nums==n:
        print(0)
    elif nums!=n:
        times=0
        while nums<n:
            if times>lists[nums-1][1]:
                if (times-lists[nums-1][1])%lists[nums-1][2]!=0:
                    a=(times-lists[nums-1][1])%lists[nums-1][2]  
                    times=times+lists[nums-1][2]-a
                    times+=lists[nums-1][0]
                    nums+=1  
                else:
                    times+=lists[nums-1][0]
                    nums+=1
            else:
                times=lists[nums-1][1]
                times+=lists[nums-1][0]   
                nums+=1 
        print(times)

Solution (Python):

def main():
    N, *A = map(int, open(0).read().split())
    CSF = [i for i in zip(*[iter(A)] * 3)]
    ans = []
    for i in range(N):
        cur = 0
        for c, s, f in CSF[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c
        ans.append(cur)
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()

Solution (Python):
from math import ceil

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

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

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

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

Solution (Python):
if __name__ == '__main__':
    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):
        if i == N-1:
            print(0)
            break
        count = S[i]
        count += C[i]
        for j in range(i+1, N-1):
            if count < S[j]:
                count = S[j]
            elif count%F[j] != 0:
                count += F[j] - count%F[j]
            count += C[j]
        print(count)

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

def cul(s,start,add):
  if s <= start:
    return start
  else:
    if s%add==0:
      return s
    else:  
      A = s+(add-s%add)
      return A 
  
for i in range(n-1):
  ans = csf[i][0]+csf[i][1]
  for j in range(i+1,n-1):
    ans = cul(ans,csf[j][1],csf[j][2])+csf[j][0]
  print(ans)  
print(0)

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

time=[]
for i in range(n-1):
    arrive=csf[i][0]+csf[i][1]
    for j in range(i+1,n-1):
        if csf[j][1]>=arrive:
            arrive=csf[j][1]+csf[j][0]
        else:
            if (arrive-csf[j][1])%csf[j][2]==0:
                arrive=((arrive-csf[j][1])//csf[j][2])*csf[j][2]+csf[j][0]+csf[j][1]
            else:
                arrive=((arrive-csf[j][1])//csf[j][2])*csf[j][2]+csf[j][2]+csf[j][0]+csf[j][1]
    time.append(arrive)
    
for i in time:
    print(i)
print(0)

Solution (Python):
from math import ceil

N = int(input())

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

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

Solution (Python):


N=int(input())
l=[]


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

for n in range(N):
    sum=0
    for i in range(n,N-1):
        if sum>l[i][1]:
            sum=l[i][1]-(-(sum-l[i][1])//l[i][2]*l[i][2])+l[i][0]
        else:
            sum=l[i][0]+l[i][1]
    print(sum)

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

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

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