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())
a = []
n -= 1
for i in range(n):
    N, S, F = map(int, input().split())
    a.append([N, S, F])

for i in range(n + 1):
    cnt = 0
    for j in range(i, n):
        
        if j == i:
            cnt += a[j][1] + a[j][0]
        else:
            if cnt >= a[j][1]:
                amari = cnt % a[j][2]
                cnt += a[j][0] + (a[j][2] - amari if amari != 0 else 0)
            else:
                cnt = a[j][1] + a[j][0]
    print(cnt)

Solution (Python):
N=int(input())
csf=[tuple(map(int,input().split(' '))) for i in range(N-1)]
for i in range(N-1):
    now = 0
    for j in csf[i:]:
        c,s,f= [k for k in j]
        while now > s:
            s += f
        now = s+c
    print(now)
print(0)

Solution (Python):
from math import ceil

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]
		else:
			k = ceil((t-S[j])/F[j])
			t = S[j] + F[j]*k +C[j]
	print(t)
print(0)

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

Solution (Python):
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n-1)]
for i in range(n):
    t = 0  
    for j in range(i, n-1):
        ci, si, fi = arr[j]  
        if t <= si:  
            t = si
        else:  
            t = ((t + fi - 1)//fi) * fi
        t += ci  
    print(t)

Solution (Python):
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    train=[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=train[j][0]
            s=train[j][1]
            f=train[j][2]
            if t>=s:
                if t%f!=0:
                    t+=f-t%f
                t+=c
            else:
                t=s+c
        print(t)
    print(0)
if __name__=='__main__':
    main()

Solution (Python):
N = int(input())
CSFlist = [list(map(int, input().split())) for _ in range(N-1)]
def calc_time(start):
    now = 0
    for i in range(start, N-1):
        C, S, F = CSFlist[i]
        now = max(now, S)
        if now % F != 0:
            now += F - now % F
        now += C
    return now
for _ in range(N-1):
    print(calc_time(_))
print(0)

Solution (Python):
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

N=I()
C=[0]*N
S=[0]*N
F=[0]*N

for i in range(N-1):
    C[i],S[i],F[i]=MI()
      
ans=[0]*N



def calc(a,c,s,f):
    st=s
    if a>s:
        st=((a+f-1)//f)*f
    return st+c
        
    

for i in range(N-1):
    for j in range(i+1):
        ans[j]=calc(ans[j],C[i],S[i],F[i])

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

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


def left_time(time, si, fi):
    if time>si:
        a = time-si
        if a%fi:
            b = a//fi + 1
            return si + fi*b
        else:
            return time
    else:
        return si

for i in range(n-1):
    total = 0
    total = l[i][0]+l[i][1]
    for j in range(i+1, n-1):
        total = (left_time(total, l[j][1], l[j][2]) + l[j][0])
    print(total)
print(0)

Solution (Python):
N = int(input())
CSFlist = [list(map(int, input().split())) for _ in range(N-1)]
def calc_time(start):
    now = 0
    for i in range(start, N-1):
        C, S, F = CSFlist[i]
        if now < S:
            now = S
        if now % F != 0:
            now += F - now % F
        now += C
    return now
for _ in range(N-1):
    print(calc_time(_))
print(0)

Solution (Python):
import math

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

ans_list = []
for i in range(len(stations)):
    C, S, F = stations[i]
    time = S + C
    index = i+1
    while index < N-1:
        next_C, next_S, next_F = stations[index]
        if next_S > time:
            time = next_S + next_C
        else:
            n = math.ceil(time / next_F)
            time = next_F * n + next_C
        index += 1
    ans_list.append(time)

ans_list.append(0)

for ans in ans_list:
    print(ans)

Solution (Python):
if __name__ == "__main__":
    n = int(input())
    csf = list()
    for i in range(n-1):
        csf.append(list(map(int, input().split())))

    for i in range(n):
        ans = 0
        for j in range(i, n-1):
            if ans <= csf[j][1]:
                ans = csf[j][1]
                ans += csf[j][0]
            else:
                tmp = (csf[j][2] - ans % csf[j][2]) % csf[j][2]
                ans += tmp
                ans += csf[j][0]
        print(ans)

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

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

if __name__ == '__main__':
    main()

Solution (Python):
import math
n=int(input())
ans=0
if n>1:
    data=[]
    for _ in range(n-1):
        data_=list(map(int,input().split()))
        data.append(data_)
    if n>2:
        for i in range(0,n-2):
            time=data[i][1]
            for j in range(i,n-2):
                arrive=time+data[j][0]
                s=data[j+1][1]
                if arrive<=s:
                    time=s
                else:
                    f=data[j+1][2]
                    time=s+f*(math.ceil((arrive-s)/f))
            time+=data[n-2][0]
            print(time)
    time=data[n-2][0]+data[n-2][1]
    print(time)
print(ans)

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

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

Solution (Python):
from math import ceil


def get_required_time(trains, station_num, station):
    arrival = [0] * station_num
    for i in range(station, station_num):
        if arrival[i - 1] < trains[i - 1][1]:
            arrival[i] = trains[i - 1][0] + trains[i - 1][1]
        else:
            arrival[i] = trains[i - 1][0] + trains[i - 1][2] * ceil(arrival[i - 1] / trains[i - 1][2])
    return arrival


def main():
    station_num = int(input())
    trains = [list(map(int, input().split())) for _ in range(station_num - 1)]
    for i in range(1, station_num):
        print(get_required_time(trains, station_num, i)[-1])
    print(0)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
c = []
s = []
f = []
for _ 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-1):
    now = i
    time = s[i]
    while now < n-1:
        time += c[now]
        now += 1
        if now == n-1:
            break
        x = time % f[now]
        if time < s[now]:
            time = s[now]
        elif x == 0:
            pass
        else:
            time += f[now] - x
    print(time)
print(0)

Solution (Python):
from math import ceil

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

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

Solution (Python):
N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    ca,sa,fa = list(map(int,input().split()))
    C[i] = ca
    S[i] = sa
    F[i] = fa
time = [0] * N
for i in range(N-1):
    t = C[i]+S[i]
    for j in range(i+1,N-1):
        if t<= S[j]:
            t = S[j]
        else:
            d = t - S[j]
            k = d // F[j]
            m = d % F[j]
            if m != 0:
                t = S[j] + (k+1) * F[j]
        t += C[j]
    time[i] = t
for i in range(N):
    print(time[i])

Solution (Python):
N = int(input())
ans = []
for _ in range(N - 1):
    C, S, F = map(int, input().split())
    ans.append(S + C)
    for i in range(len(ans) - 1):
        if ans[i] <= S:
            ans[i] = S + C
        else:
            if (ans[i] - S) % F == 0:
                ans[i] += C
            else:
                ans[i] = S + F * ((ans[i] - S) // F + 1) + C

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

Solution (Python):
n = int(input())
a = []
for i in range(n-1):
	c,s,f = map(int, input().split())
	a.append([c,s,f])
ans = 0
while len(a) > 0:
	ans = 0
	for i, j, k in a:
		ans = max(ans, j)
		if ans%k != 0:
			ans += k - (ans%k)
		ans += i
	print (ans)
	a.pop(0)
print (0)

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

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

Solution (Python):
def main():
    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:
                t += F[j] - t%F[j]
            t += C[j]
        print(t)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    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:
                tmp = 0
            else:
                t += F[j] - t%F[j]
            t += C[j]
        print(t)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    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:
                tmp = 0
            else:
                t = t + F[j] - t%F[j]
            t += C[j]
        print(t)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
l = []
for i in range(n-1):
    tmp = list(map(int,input().split()))
    l.append(tmp)
import math
for i in range(n):
    time=0
    now=i
    while now < n-1:
        if time > l[now][1]:
            tmp = math.ceil((time - l[now][1]) / l[now][2])
            wait = tmp * l[now][2]  - (time - l[now][1])
            time+= wait + l[now][0]
        else:
            time+=l[now][1] - time + l[now][0]
        now+=1

    print(time)

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

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

for i in range(n):
    cnt = 0
    for j in range(i, n-1):
        c, s, f = CSF[j][0], CSF[j][1], CSF[j][2]
        if cnt < s:
            cnt = s
        elif cnt % f != 0:
            cnt = (cnt//f + 1) * f
        cnt += c
    ans[i] += cnt

for a in ans:
    print(a)

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

for n in range(N):
  if n == N - 1:
    print(0)
    break
  
  ans = 0
  for index, i in enumerate(li):
    if index < n:
      continue

    if ans < i[1]:
      ans = i[1]
    else:
      if (ans - i[1]) % i[2] != 0:
        ans += i[2] - (ans % i[2])

    ans += i[0]
  print(ans)

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

print("\n".join(str(t) for t in time))

Solution (Python):
from math import ceil

def solve(n, CSF):
    times = [0] * n
    for i, (c, s, f) in enumerate(CSF):
        for j in range(i + 1):
            if times[j] <= s:
                times[j] = s
            else:
                times[j] = s + ceil((times[j] - s) / f) * f
            times[j] += c
    return times

_n = int(input())
_CSF = [map(int, input().split()) for _ in range(_n - 1)]
print(*solve(_n, _CSF), sep='\n')

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

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

me = 0
for i in range(n-1):
  remain = n - i - 1
  time = 0
  for r in range(remain):
    c, s, f = stations[r+i]
    if time < s:
      time = s
    elif time % f == 0:
      pass
    else:
      time = time + f - (time % f)
    time += c
  print(time)
  
print(0)

Solution (Python):
import math

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

for i in range(n-1):
    t = 0
    for j in range(i, n-1):
        if a[j][1] >= t:
            t = a[j][1]
        else:
            t = math.ceil(t / a[j][2]) * a[j][2]
        t += a[j][0]
    print(t)
print(0)

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

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

ans = []
for i in range(n - 1):
  temp = stat[i][1]
  for j in range(i, n - 1):
    c, s, f = map(int, stat[j])
    temp = max(s, temp)
    while temp % f != 0:
      temp += 1
    temp += c
  ans.append(temp)

for i in ans:
  print(i)
print(0)

Solution (Python):
N=int(input())
TTBL=[list(map(int,input().split())) for i in range(N-1)]
def GT(k,t):
  c,s,f=TTBL[k][0],TTBL[k][1],TTBL[k][2]
  return s+max(0,t-s+(f-1))//f*f+c
for i in range(N-1):
  ret = 0
  for j in range(i,N-1):
    ret=GT(j,ret)
  print(ret)
print(0)

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

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

for i in range(n-1):
 ans=l[i][1]+l[i][0]
 for j in range(i+1,n-1):
  if ans<l[j][1]:
   ans=l[j][1]+l[j][0]
  else:
   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())

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



for i in range(len(sList)):
  timeCount = sList[i][1]+sList[i][0] 
  for j in range(i+1,len(sList)):
    if timeCount < sList[j][1]:
      timeCount = sList[j][1]
      
    timeTmp = timeCount % sList[j][2]
    if timeTmp == 0:
      timeCount += sList[j][0]
    else:
      timeCount += sList[j][2] - timeTmp + sList[j][0]
  print(timeCount)

print(0)

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

    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)

ans =[]


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

            b = t % F[j]
            t += F[j] - b
            t += C[j]
    ans.append(t)

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

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

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

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

for i in range(n):
    s=i
    ti=0
    while s!=n-1:
        if ti<t[s][1]:
            ti=t[s][1]+t[s][0]
        else:
            ti=t[s][2]*(math.ceil(ti/t[s][2]))+t[s][0]
        s+=1
    print(ti)

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

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

print(0)

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

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

print(0)

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

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

def calc(x): 
    tmp = 0
    for i in range(x, N - 1):
        tmp = max((tmp + CSF[i][2] - 1) // CSF[i][2] * CSF[i][2], CSF[i][1]) + CSF[i][0] 
    return tmp


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

Solution (Python):
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]
 
def F(n):
    time = 0
    for i in range(n, N-1):
        c, s, f = CSF[i]
        if time <= s:
            time = s + c
        else:
            remainder = time % f
            time += (f-remainder)%f+c
    print(time)
for i in range(N-1):
    F(i)
print(0)

Solution (Python):
n = int(input())
c = []
s = []
f = []
for _ in range(n-1):
    p,q,r = map(int,input().split())
    c.append(p)
    s.append(q)
    f.append(r)
a = [0]*n
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 += f[j]-t%f[j]
        t += c[j]
    a[i] = t
print('\n'.join(map(str, a)))

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

Solution (Python):
n = int(input())
CSF = [list(map(int, input().split())) for _ in range(n-1)]
C, S, F = zip(*CSF)
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]:
      t += F[j]-t%F[j]
    t += C[j]
  print(t)

Solution (Python):
import sys
import math

class cin():
    def getInt():
        return int(sys.stdin.readline().rstrip())
    def getString():
        return sys.stdin.readline().rstrip()

N = cin.getInt()
A = [list(map(int,cin.getString().split())) for i in range(N - 1)]

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][2]) * A[j][2] + A[j][0]
    print(t)

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

Solution (Python):
N = int(input())
CSFlist = [tuple(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
    now = 0
    for c, s, f in CSFlist[i:]:
        now = max(now, s)
        now += (f - now % f) if now % f != 0 else 0
        now += c
    print(now)

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

ans.append(0)

for i in ans:
    print(i)

Solution (Python):
import math

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

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

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

ans = [0]*n
for i in range(n):
    time = 0
    for j in range(i, n-1):
        if l[j][1] - time > 0:
            time += l[j][1] - time
        if time % l[j][2] != 0:
            time += l[j][2] - time % l[j][2]
        time += l[j][0]
    ans[i] += time

for i in ans:
    print(i)

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

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

result=[]
for i in range(n-1):
  temp=CSF[i][1]+CSF[i][0]
  j=i+1
  while j<n-1:
    
    a,b=CSF[j][2],CSF[j][1]
    t=(temp-b)/a
    if t<=0:
      t=0
    else:
      t=-1*((b-temp)//a)
    temp=a*t+b+CSF[j][0]  
    j+=1
  result.append(temp)

for item in result:
  print(item)
print(0)

Solution (Python):
import math

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

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

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    csf = []
    for _ in range(N - 1):
        csf.append([int(x) for x in input().split()])

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



if __name__ == '__main__':
    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(len(C)):
  cur=0
  for j in range(i,len(C)):
    
    
    
    if cur<S[j]:
      cur=S[j]
    cur=((cur+F[j]-1)//F[j])*F[j]+C[j]
  print(cur)
print(0)

Solution (Python):
n = int(input())
c = []
s = []
f = []
for _ 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):
   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):
from math import ceil
n = int(input())
cc = [0]*(n-1)
ss = [0]*(n-1)
ff = [0]*(n-1)
ans = [0]*n

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

for i in range(n-1):
    for j in range(i,n-1):
        x = max(0,ceil((ans[i]-ss[j])/ff[j]))
        ans[i] = ss[j] + x*ff[j] + cc[j]

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

Solution (Python):
a = int(input())
l = []

for i in range(a-1):
    ta,tb,tc  = map(int,input().split())
    l.append([ta,tb,tc])

for i in range(a-1):
    s = 0
    s += sum(l[i][:2])
    for j in range(i+1,a-1):
        
        if s<= l[j][1]:s = sum(l[j][:2])
        elif s%l[j][2]==0 :s+=l[j][0]
        else : s+=l[j][2]- s%l[j][2] + l[j][0]
        
    print(s)
print(0)

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

        else:
            if nowtime[h] % F[h] == 0:
                nowtime[h + 1] = nowtime[h] + C[h]
            else:
                nowtime[h+1] = nowtime[h]+F[h]-(nowtime[h] % F[h])+C[h]
    print(nowtime[N - 1])

print(0)

Solution (Python):

from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left

N=int(input())
times = [list(map(int, input().split())) for i in range(N-1)]
for start in range(N-1):
    current = start + 1
    elapsed =  times[start][1] + times[start][0]
    while current < N-1:
        if elapsed < times[current][1]:
            elapsed = times[current][1]
        if elapsed % times[current][2] != 0:
            elapsed = times[current][2] * (elapsed // times[current][2] + 1)
        elapsed += times[current][0] 
        current += 1
    print(elapsed)
print(0)

Solution (Python):
N = int(input())
C, S, F = zip(*[tuple(map(int, input().split())) for _ in range(N-1)])
S = list(s for s in S) + [0]
for i in range(N-1):
    for j in range(i, N-1):
        S[i] = max(S[i], S[j])
        while S[i] % F[j]:
            S[i] += 1
        S[i] += C[j]
print(*S, sep="\n")

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

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

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

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

for i in range(N-1):
    total_time = 0
    for j, (c, s, f) in enumerate(zip(C[i:], S[i:], F[i:])):
        if j == 0:
            total_time += (c + s)
        else:
            if total_time < s:
                total_time = s
            if total_time % f != 0:
                total_time += f - total_time % f
            total_time += c
    print(total_time)
print(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)

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

    print(t)

print(0)

Solution (Python):
N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c1, s1, f1 = map(int, input().split())
    C.append(c1)
    S.append(s1)
    F.append(f1)
    
for i in range(N-1):
    ans = 0
    for j in range(i,N-1):
        if ans <= S[j]:
            ans = S[j] + C[j]
        elif (ans - S[j]) % F[j] == 0:
            ans += C[j]
        else:
            ans += C[j] + F[j] - ((ans - S[j]) % F[j])
    print(ans)  
print(0)

Solution (Python):

N = int(input())

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

for i in range(N-1):
  count = T[i][1]
  for j in range(i, N-1):
    c, s, f = map(int, T[j])

    if count >= s and (count - s) % f == 0:
      count += c
    elif count >= s:
      count += c + f - (count - s) % f
    else:
      count = s + c
  print(count)

print(0)

Solution (Python):
N = int(input())
CSF = []
import math
for i in range(N-1):
    CSF.append(list(map(int,input().split())))
def time(t,i):
    if CSF[i][1] >= t:
        return CSF[i][1]+CSF[i][0]
    else:
        x = math.ceil((t-CSF[i][1])/CSF[i][2])
        return CSF[i][1]+ x*CSF[i][2] + CSF[i][0]

for i in range(N-1):
    t = CSF[i][0]+CSF[i][1]
    for j in range(i+1,N-1):
        t = time(t,j)
    print(t)

print(0)