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())
cost=[]
start=[]
fre=[]

from math import ceil

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


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

    time=start[i]+cost[i]

    for j in range(i+1,n-1):
        if time>=start[j] and time%fre[j]==0:
            time+=cost[j]
        elif time>=start[j] and time%fre[j]!=0:
            time+=fre[j]*ceil(time/fre[j])-time+cost[j]
        else:
            time=start[j]+cost[j]

    print(time)

Solution (Python):
def solve(k):
    t = 0
    for i in range(k, N-1):
        if t < S[i]:
            t = S[i] + C[i]
        else:
            if (t - S[i]) % F[i] == 0:
                t += C[i]
            else:
                t = t + (F[i] - (t - S[i]) % F[i]) + C[i]
    return t

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())
res = [0] * N
for i in range(N):
    res[i] = solve(i)
print(*res, sep='\n')

Solution (Python):

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

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

print(0)

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

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

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

    print(t)
print(0)

Solution (Python):
n = int(input())
c,s,f = [],[],[]
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)
    
ans = []
for i in range(n-1): 
    time = 0
    for j in range(i,n-1): 
        if time <= s[j]:
            time = s[j]+c[j]
        else:
            time += c[j] + f[j]*(0!=time%f[j]) - time%f[j]
    ans.append(time)
        
print('\n'.join(map(str,ans)),'\n0')

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

for i in range(n):
    t = 0
    for c, s, f in l[i:]:
        t = max(s, t)
        mod = abs(t - s)%f
        if mod != 0:
            t += f - mod
        t += c
    print(t)

Solution (Python):
n = int(input())
l = [[0]*3 for i in range(n)]

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

for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        t = max(l[j][1], t)
        mod = abs(t - l[j][1])%l[j][2]
        if mod != 0:
            t += l[j][2] - mod
        t += l[j][0]
    print(t)

print(0)

Solution (Python):
import sys

N = int(input())
CSF = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N - 1)]

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    for i in range(n):
        if i == n - 1:
            print(0)
            break
        c, s, f = CSF[i]
        now = s + c
        for j in range(i + 1, n - 1):
            c, s, f = CSF[j]
            if now >= s:
                diff = now - s
                if diff % f == 0:
                    now += c
                else:
                    now += f - diff % f + c
            else:
                now = s + c
        print(now)


if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import deque

N = int(input())

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

h = deque([0])

for i in range(N-2,-1,-1):
  t = CSFs[i][1]
  t += CSFs[i][0]
  for j in range(i+1,N-1):
    if t < CSFs[j][1]:
      t = CSFs[j][1]
    else:
      if t%CSFs[j][2] > 0:
        t += CSFs[j][2] - (t%CSFs[j][2])
    t += CSFs[j][0]
  h.appendleft(t)
  
while h:
  print(h.popleft())

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

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

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

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            if temp <= ab[j+1][1]:
                temp = ab[j+1][1] + ab[j+1][0]
            else:
                if temp % ab[j+1][2] ==0:
                    temp += ab[j+1][0]
                else:
                    temp = ((temp//ab[j+1][2])+1) * ab[j+1][2] +ab[j+1][0]
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])

Solution (Python):
n = int(input())
stations = [list(map(int, input().split())) for _ in range(n-1)]
for idx in range(n-1):
    t = 0
    for idx2 in range(idx, n-1):
        c, s, f = stations[idx2]
        t = max(t, s)
        if t <= f:
            t = f
        else:
            if t%f > 0:
                t += f - t%f
        t += c
    print(t)
print(0)

Solution (Python):
import math

N,*CSFf = map(int, open(0).read().split())
C = [x for x in CSFf[0::3]]
S = [x for x in CSFf[1::3]]
F = [x for x in CSFf[2::3]]
ans = [0] * N
for i in range(N-1):
    temp = S[i] + C[i]
    for j in range(i+1,N-1):
        if temp <= S[j]:
            temp = S[j] + C[j]
        else:
            temp = math.ceil(temp/F[j]) * F[j] + C[j]
    ans[i] = temp
for x in ans:
    print(x)

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

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

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

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

for i in range(n - 1):
  time = s[i] + c[i]
  i += 1
  while i < n - 1:
    if time < s[i]:
      time = s[i] + c[i]
    else:
      time += (f[i] - (time - s[i]) % f[i]) % f[i] + c[i]
    i += 1
  print(time)

print(0)

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

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

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n - 1)]

    for i in range(n):
        if i == n - 1:
            print(0)
        else:
            x = csf[i][1]
            for j in range(i + 1, n - 1):
                cj1, sj1, fj1 = csf[j - 1]
                cj, sj, fj = csf[j]
                
                if x + cj1 + (fj1 - x % fj1) % fj1 <= sj:
                    x = sj
                else:
                    x += cj1 + (fj1 - x % fj1) % fj1
            x += csf[-1][0] + (csf[-1][2] - x % csf[-1][2]) % csf[-1][2]
            print(x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

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

l=[]
for i in range(n-1):
    cnt=0
    for j in range(i,n-1):
        if cnt>=csf[j][1]:
            tmp_cnt=(cnt-csf[j][1]-1)//csf[j][2]
            cnt=csf[j][1]+(tmp_cnt+1)*csf[j][2]
        else:
            cnt=csf[j][1]
        cnt+=csf[j][0]
    l.append(cnt)

l.append(0)
for l_i in l:
    print(l_i)

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

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

Solution (Python):
def main():
    n = int(input())
    C, S, F = [], [], []
    for _ in range(n - 1):
        c, s, f = list(map(int, input().split()))
        C.append(c)
        S.append(s)
        F.append(f)
    for i in range(n):
        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):
n = int(input())
train = [list(map(int, input().split())) for _ in range(n - 1)]

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
CSF = [LIST() for _ in range(N-1)]

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

Solution (Python):






from collections import deque





n=int(input())
r=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    time=r[i][1]
    for j in range(i,n-1):
        if time>=r[j][1]:
            if time%r[j][2]==0:
                time+=r[j][0]
            else:
                time=((time//r[j][2])+1)*r[j][2]
                time+=r[j][0]
        else:
            time=r[j][1]
            time+=r[j][0]
    print(time)
print(0)

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


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


def solve(N, CSF, SMAX=200000):
    A = []
    for c, s, f in CSF:
        for i in range(len(A)):
            if A[i] % f == 0:
                A[i] = max(A[i], s) + c
            else:
                A[i] = max(A[i] - A[i] % f + f, s) + c
        A.append(s + c)
    A.append(0)
    for a in A:
        print(a)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

def arrive(time,now):
  if time>a[now][1]:
    time=(time+a[now][2]-1)//a[now][2]*a[now][2]+a[now][0]
  else: time=a[now][1]+a[now][0]
  if now==n-2:
    return time
  else:
    return arrive(time,now+1)

for i in range(n-1):
  print(arrive(a[i][1],i))
print(0)

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

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

for i in range(n-1):
    t = li[i][1] + li[i][0]
    for j in range(i+1,n-1):
        while True:
            if t >= li[j][1] and t%li[j][2] == 0:
                break
            else:
                t += 1
        t += li[j][0]
    print(t)
print(0)

Solution (Python):
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s
        elif (time - s) % f != 0:
            time += (f - (time - s) % f) 
        time += c
    print(time)
    
def main2():    
    for i in range(n-1):
        main(i)
    print(0)
main2()

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

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s
        if (time - s) % f != 0:
            time += (f - (time - s) % f) 
        time += c
    print(time)
    
    
for i in range(n-1):
    main(i)
print(0)

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

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = [list(MI()) for i in range(n-1)]

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s
        if (time - s) % f != 0:
            time += (f - (time - s) % f) 
        time += c
    print(time)
    
    
for i in range(n-1):
    main(i)
print(0)

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

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



def reach(start, time):
    if start == n-1:
        return time

    
    if time <= csf[start][1]:
        time = csf[start][1]
    else:
        while time % csf[start][2] != 0:
            time += 1
    return reach(start+1, time + csf[start][0])

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

Solution (Python):
import sys
n=int(input())
c=[]
s=[]
f=[]
if n==1:
    print(0)
    sys.exit()
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):
    tmp=0
    while i<n-1:
        if tmp<=s[i]:
            a=s[i]
        elif (tmp-s[i])%f[i]==0:
            a=tmp
        elif tmp>s[i]:
            b=f[i]-(tmp-s[i])%f[i]
            a=tmp+b
        tmp=a+c[i]
        i+=1
    print(tmp)
print(0)

Solution (Python):
n=int(input())
L=[]
for _ in range(n-1):
    L.append(tuple(map(int,input().split())))
ans=[]
for i in range(n-1):
    c,t,f=L[i]
    t += c
    for j in range(i+1,n-1):
        cn,sn,fn=L[j]
        if t>sn:
            t=-int(-t//fn)*fn
        else:
            t=sn
        t += cn
    ans.append(t)
ans.append(0)
for i in ans:
    print(i)

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

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

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

ans = [0] * N
for i in range(N-1):
  C, S, F = map(int, input().split())
  for j in range(i+1):
    if S >= ans[j]:
      ans[j] = S + C
    else:
      ans[j] = F * (1 + (ans[j]-1)//F) + C

for ansi in ans:
  print(ansi)

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

ans = 0
memo = {}
memoset = set()
def dfs(i, time):
    if i==N-1:
        return time
    c, s, f = CSF[i]
    if time<s:
        time = s
    elif time%f!=0:
        time = (time//f+1)*f
    if (time, i) in memoset:
        return memo[(time, i)]
    T = dfs(i+1, time+c)
    memo[(time, i)] = T
    memoset.add((time, i))
    return T

for i in range(N-1):
    print(dfs(i, 0))
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):
  t=l[i][1]
  t+=l[i][0]
  for j in range(i+1,n-1):
    if t<l[j][1]:
      t=l[j][1]
    elif t%l[j][2]!=0:
      t+=l[j][2]-t%l[j][2]
    t+=l[j][0]

  print(t)
print(0)

Solution (Python):
def main():
    from itertools import islice

    N = int(input())

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

    ans = []
    for i in range(N - 1):
        curr = 0
        for c, s, f in islice(trains, i, N - 1, 1):
            if curr < s: curr = s
            r = curr % f
            if r != 0: curr += f - r
            curr += c
        ans.append(curr)
    ans.append(0)

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


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from itertools import islice

    N = int(input())

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

    ans = [0] * N
    for i, (ci, si, fi) in enumerate(trains):
        curr = si + ci
        for j, (cj, sj, fj) in enumerate(islice(trains, i + 1, N, 1)):
            if curr < sj: curr = sj
            r = curr % fj
            if r != 0: curr += (fj - r)
            curr += cj
        ans[i] = curr

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


if __name__ == '__main__':
    main()

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

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

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

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

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

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

Solution (Python):
N = int(input())
A = [list(map(int,input().split())) for _ in range(N-1)]
A.insert(0,0)
B = [0 for _ in range(N+1)]
for i in range(1,N):
    C1,S1,F1 = A[i]
    T = S1
    for j in range(i+1,N):
        C2,S2,F2 = A[j]
        if T+C1>=S2:
            dt = (T+C1)%F2
            if dt>0:
                T += F2-dt+C1
            else:
                T += C1
        else:
            T = S2
        C1 = C2
        S1 = S2
        F1 = F2
    T += C1
    B[i] = T
for i in range(1,N+1):
    print(B[i])

Solution (Python):
N = int(input())
ans = [0 for i in range(N)]
import math
for i in range(N-1):
  c, s, f = map(int, input().split())
  for j in range(i+1):
    if ans[j]>=s:
      x = math.ceil((ans[j]-s)/f)
      ans[j] = s+f*x+c
    else:
      ans[j] = s+c
for i in range(N):
  print(ans[i])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    for i in range(n):
        if i == n - 1:
            print(0)
            break
        c1, s1, _ = CSF[i]
        t = s1 + c1
        for j in range(i + 1, n - 1):
            c2, s2, f2 = CSF[j]
            if t <= s2:
                t = s2 + c2
            else:
                if t % f2 == 0:
                    wait = 0
                else:
                    wait = f2 - (t - s2) % f2
                t += c2 + wait
        print(t)


if __name__ == '__main__':
    resolve()

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

N = int(input())
CSF = tuple(tuple(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):
        c, s, f = CSF[j]
        d = max(0, time - s)
        ride = (d + f - 1) // f
        time = s + ride * f + c
    ans[i] = time

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

Solution (Python):
def examA():
    C1 = SI()
    C2 = SI()
    ans = "YES"
    if C1[0]!=C2[2] or C1[1]!=C2[1] or C1[2]!=C2[0]:
        ans = "NO"
    print(ans)
    return

def examB():
    A, B, C, X, Y = LI()
    loop = max(X,Y)
    ans = inf
    for i in range(loop+1):
        cost = i*2*C
        if X>i:
            cost += A*(X-i)
        if Y>i:
            cost += B*(Y-i)
        ans = min(ans,cost)
    print(ans)
    return

def examC():
    def gcd(x, y):
        if y == 0:
            return x
        while (y != 0):
            x, y = y, x % y
        return x
    N, x = LI()
    X = LI()
    if N==1:
        print(abs(X[0]-x))
        return
    for i in range(N):
        X[i] = abs(X[i]-x)
    now = gcd(X[0],X[1])
    for i in range(2,N):
        now = gcd(now,X[i])
    ans = now
    print(ans)
    return

def examD():
    N = I()
    C = [LI()for _ in range(N-1)]
    ans = [inf]*N
    for i in range(N):
        cur = 0
        for j in range(i,N-1):
            c, s, f = C[j]
            next = 0
            if cur<=s:
                cur = s+c
            else:
                cur = (1+(cur-1)//f)*f + c
        ans[i] = cur
    for v in ans:
        print(v)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examD()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

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


def get(i):
    ans = 0
    for c, s, f in csf[i:]:
        ans = max(ans, s)
        ans = (ans + f - 1) // f * f
        ans += c
    return ans


for i in range(n):
    print(get(i))

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

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

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

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

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

Solution (Python):
N = int(input())
CC = [0] * (N-1)
SS = [0] * (N-1)
FF = [0] * (N-1)

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

for i in range(N-1):
    T = 0
    Max = 0
    for k in range(i,N-1):
        Max = max(T, SS[k])
        U = Max % FF[k]
        if U == 0:
            T = Max + CC[k]
        else:
            T = Max - U + FF[k] + CC[k]
        
    print(T)
print(0)

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

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

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

print(0)

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

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

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

anss =[]
for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        for k in range(10**8):
            if tmp <= s[j] + f[j] * k:
                tmp = s[j] + f[j] * k + c[j]
                break
    else:
        anss.append(tmp)
else:
    anss += [0]

for ans in anss:
    print(ans)

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

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

anss =[]
for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        k = 0
        while 1:
            if tmp <= s[j] + f[j] * k:
                tmp = s[j] + f[j] * k + c[j]
                break
            else:
                k += 1
    else:
        anss.append(tmp)
else:
    anss += [0]

for ans in anss:
    print(ans)

Solution (Python):
def main():
    n = int(input())
    csf = [tuple(map(int, input().split())) for _ in range(n - 1)]
    r = [0] * n
    for i1 in range(n - 1):
        t = 0
        for i2 in range(i1, n - 1):
            if t <= csf[i2][1]:
                t = csf[i2][1]
            else:
                if t % csf[i2][2] != 0:
                    t = ((t // csf[i2][2]) + 1) * csf[i2][2]
            t += csf[i2][0]
        r[i1] = t

    p2d = lambda x: print(*x, sep="\n")
    p2d(r)

if __name__ == '__main__':
    main()

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

c = [0] * n
f = [0] * n
s = [0] * n

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

lapse = [0] * n

for i in range(n):
    for j in range(i + 1, n):

        t = 0
        while s[j - 1] + t * f[j - 1] < lapse[i]:
            t += 1

        lapse[i] = s[j - 1] + t * f[j - 1] + c[j - 1]

    print(lapse[i])

Solution (Python):
def mips():
    return map(int,input().split())
def ii():
    return int(input())
N = ii()
L = []
for i in range(N-1):
    C,S,F = mips()
    L.append([C,S,F])
for i in range(N-1):
    x = L[i][0] + L[i][1]
    j = i + 1
    while j != N-1:
        if x >= L[j][1] and x % L[j][2] == 0: 
            x += L[j][0]
            j += 1
        else:
            if x < L[j][1]: 
                x += (L[j][1]-x + L[j][0])
                j += 1
            else: 
                while x % L[j][2] != 0:
                    x += 1
                x += L[j][0] 
                j += 1
    print(x)
print(0)

Solution (Python):
from math import ceil
n = int(input())
lst = [list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    ans = lst[i][0]+lst[i][1]
    for j in range(i+1, n-1):
        k = max(0, ceil((ans-lst[j][1])/lst[j][2]))
        ans = lst[j][1]+k*lst[j][2]+lst[j][0]
    print(ans)
print(0)

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