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());y=[list(map(int,input().split())) for i in range(n-1)]
for s in range(n):
  x=0
  for k,g in enumerate(y[s:]):
    a,b,c=g[0],g[1],g[2]
    if k==0:x=b+a
    elif x>b:
      if (x-b)%c==0:x=x+a
      else:x=(x//c+1)*c+a
    elif x<b:x=b+a
  print(x)

Solution (Python):
n=int(input())
y=[list(map(int,input().split())) for i in range(n-1)]
for s in range(n):
  x=0
  for k,g in enumerate(y[s:]):
    a,b,c=g[0],g[1],g[2]
    if k==0:
      x=b+a
    elif x>b:
      if (x-b)%c==0:
        x=x+a
      else:
        x=(x//c+1)*c+a
    elif x<b:
      x=b+a
  print(x)

Solution (Python):
import math
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
csf = [IL() for i in range(N-1)]

ans = [0]*N

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

for i in ans:
	print(i)

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

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

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

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




res = []

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

res.append(0)

print("\n".join([str(e) for e in res]))

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

Solution (Python):


def main():
    N = int(input())
    
    CSFs = [list(map(int, input().split())) for _ in range(N-1)]
    C = [CSF[0] for CSF in CSFs]
    S = [CSF[1] for CSF in CSFs]
    F = [CSF[2] for CSF in CSFs]

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


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):
    t = 0
    pos = i
    while True:
        if pos == N-1:
            print(t);break
        if t<s[pos]: t = s[pos]
        if t%f[pos]==0:
            t += c[pos]
            pos += 1
        else:
            t = (t//f[pos]+1)*f[pos]

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

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

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

def calculate(i):
  time=ls[i][1]+ls[i][0]
  for j in range(i+1,len(ls)):
    if time<ls[j][1]:
      time=ls[j][1]+ls[j][0]
    elif time %ls[j][2]==0:
      time+=ls[j][0]
    else:
      time+=ls[j][0]+ls[j][2]-time%ls[j][2]
  return time

for i in range(len(ls)):
  ans.append(calculate(i))
ans.append(0)
for i in ans:
  print(i)

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

def calculate(i):
  time=ls[i][1]+ls[i][0]
  for j in range(i+1,len(ls)):
    if time<ls[j][1]:
      time=ls[j][1]+ls[j][0]
    else:
      additional_time=ls[j][2]
      while time %additional_time!=0:
        time+=1
      time+=ls[j][0]
  return time

for i in range(len(ls)):
  ans.append(calculate(i))
ans.append(0)
for i in ans:
  print(i)

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

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

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

Solution (Python):


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


for i in range(0,N):
    ans_i = 0
    for j in range(i, N-1):
        c,s,f = trains[j]
        ans_i = max(ans_i, s)
        if not ans_i % f == 0:
            ans_i += f - ans_i%f
        ans_i += c

        
    print(ans_i)

exit(0)

Solution (Python):


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


for i in range(0,N):
    ans_i = 0
    for j in range(i, N-1):
        c,s,f = trains[j]
        ans_i = max(ans_i, s)
        if not ans_i % f == 0:
            ans_i += f - ans_i%f
        ans_i += c

        
    print(ans_i)

exit(0)

Solution (Python):


N = int(input())
trains = [ [int(j) for j in input().split()] for _ in range(N-1)] + [(0,0,0)]


for i in range(0,N):
    ans_i = 0
    for j in range(i, N-1):
        c,s,f = trains[j]
        ans_i = max(ans_i, s)
        ans_i += c + (f - ans_i%f)%f 
    print(ans_i)

exit(0)


dp = [float("inf") for _ in range(N-1)] + [0] 

t = trains[N-2]
dp[N-2] = t[0]+t[1]
limited_by = [0 for _ in range(N)]
limited_by[N-2] = t[1]

for i in range(N-3, -1, -1):
    c,s,f = trains[i]
    nc,ns,nf = trains[i+1]
    arrive_at = c+s 

    if arrive_at < limited_by[i+1]:
        dp[i] = dp[i+1]
        limited_by[i] = limited_by[i+1] -c 

    else:
        dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - ns
        limited_by[i] = s

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

Solution (Python):
N=int(input())
C=[]
S=[]
F=[]
from math import ceil
for _ 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(0,N-1):
    t=S[i]+C[i]
    sta=i+1
    while sta<N-1:
        if t<=S[sta]:
            t=S[sta]+C[sta]
        else:
            k=ceil((t-S[sta])/F[sta])
            t=S[sta]+k*F[sta]+C[sta]
        sta+=1
    ans.append(t)
for a in ans:
    print(a)
print(0)

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

for l in range(n):
    t = 0
    for k in range(n-1-l):
        t = s[l+k]+(max(0, t-s[l+k])+f[l+k]-1)//f[l+k]*f[l+k]+c[l+k]
    print(t)

Solution (Python):
import math


def solve(N, CSFs):
    ans = []
    for k in range(0, len(CSFs)):
        t = 0
        for c, s, f in CSFs[k:]:
            if t < s:
                t = s
                t += c
            else:
                t = f * math.ceil(t / f)
                t += c
        ans.append(t)
    ans.append(0)
    return "\n".join([str(t) for t in ans])

if __name__ == "__main__":
    N = int(input())
    CSFs = [tuple(map(int, input().split(" "))) for _ in range(N - 1)]
    print(solve(N, CSFs))

Solution (Python):


import copy
import numpy as np
import random

N = int(input())
n = N
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)

answer = []
for i in range(n-1):
    to_goal = C[i] + S[i]
    for j in range(i+1,n-1):
        if to_goal >= S[j]:
            if to_goal % F[j] == 0:
                to_goal += C[j]
            else:
                to_goal = ((to_goal//F[j])+1)*F[j]+C[j]
        elif to_goal < S[j]:
            to_goal = S[j]+C[j]

    answer.append(to_goal)


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

Solution (Python):
N = int(input())
C,S,F = [0],[0],[0]
for i in range(1,N):
    c,s,f = (int(j) for j in input().split())
    C.append(c)
    S.append(s)
    F.append(f)

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

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





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

Solution (Python):


def main():
    n = int(input())
    cs = []
    ss = []
    fs = []
    for i in range(n - 1):
        c, s, f = map(int, input().split())
        cs.append(c)
        ss.append(s)
        fs.append(f)

    for i in range(n):
        t = 0
        for j in range(i, n - 1):
            t = cs[j] + next_depart(ss[j], fs[j], t)
        print(t)

def next_depart(s, f, now):
    mi = max(s, now)
    for t in range(mi, mi + f):
        if t % f == 0:
            return t
    raise Exception

main()

Solution (Python):
import math
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 j in range(N-1):
    t = 0
    for i in range(j, N-1):
        if S[i] >= t:
            t = S[i] + C[i]
        else:
            n = math.ceil((t-S[i])/F[i])
            t = S[i] + n*F[i] + C[i]
    print(t)
print(0)

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

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

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

Solution (Python):
import math

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):
    t = 0
    for j in range(i, n - 1):
        t = s[j] + f[j] * max(0, math.ceil((t - s[j]) / f[j])) + c[j]
    print(t)

print(0)

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

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

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

Ans = []
for i in range(N):
    t = 0
    for j in range(i,N-1):
        (c,s,f) = CSF[j]
        if t <= s:
            t = s+c
        else:
            t = s+((t-s-1)//f+1)*f+c
    Ans.append(t)

for ans in Ans:
    print(ans)

Solution (Python):


import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def getIntFromRows(n): return [int(input()) for i in range(n)]
def getIntMat(n):
    mat = []
    for i in range(n): mat.append(getIntList())
    return mat

def zeros(n): return [0 for i in range(n)]
def zeros2(n, m): return [[0 for i in range(m)] for j in range(n)]
N1097 = 10**9 + 7 
debug = True
def db(x): 
    if debug: print(x)

debug = False
n = getInt()
c, s, f = zeros(n-1), zeros(n-1), zeros(n-1)
for i in range(n-1):
    c[i], s[i], f[i] = getIntList()
db((c,s,f))
for i in range(n-1):
    arriv = 0
    dept = s[i]
    for j in range(i+1, n-1):
        arriv = dept + c[j-1]
        dept = (max(arriv, s[j])+f[j]-1) // f[j] * f[j]
        db((arriv, dept))
    arriv = dept + c[n-2]
    print(arriv)
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 j in range(i, N-1):
        if ans >= CSF[j][1]:
            ans = -(-ans//CSF[j][2]*CSF[j][2]) + CSF[j][0]
        else:
            ans = CSF[j][1] + CSF[j][0]
    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 ans >= CSF[j][1]:
            ans = -(-ans//CSF[j][2]*CSF[j][2]) + CSF[j][0]
        else:
            ans = CSF[j][1] + CSF[j][0]
    print(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)
j = 0
for j in range(N-1):
    ans = C[j]+S[j]
    k = j+1
    l = 0
    for l in range(N-j-2):
        if ans <= S[k+l]:
            ans+=C[k+l]+(S[k+l]-ans)
        else:
            b=math.ceil((ans-S[k+l])/F[k+l])
            ans+=C[k+l]+(S[k+l]+F[k+l]*b-ans)
    print(ans)
print(0)

Solution (Python):
from sys import stderr, setrecursionlimit
from math import ceil
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getInt()
ans = []
for i in range(n-1):
    c, s, f = getInts()
    ans.append(c + s)
    for j in range(i):
        
        if ans[j] <= s:
            
            ans[j] = ans[i]
        else:
            
            
            ans[j] = ceil(ans[j]/f) * f + c
    debug(ans)

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

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

for i in range(1,N+1):
    if i == N:
        print('0')
    else:
        time = 0
        for j in range(i,N):
            if time < data[j-1][1]:
                waitTime = data[j-1][1] - time
            else:
                waitTime =(data[j-1][2]-(time % data[j-1][2]))%data[j-1][2]
            time += waitTime + data[j-1][0]
        else:
            print(time)

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

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

print(0)

Solution (Python):
def solve_impl(ini, T):
    t = 0
    for Ci, Si, Fi in T[ini:]:
        
        if t < Si:
            t = Si
        elif t % Fi != 0:
            t = t + Fi - t % Fi
        t += Ci
    return t


def solve():
    N = int(input())
    T = [ [int(n) for n in input().split()] for _ in range(N-1) ]

    for i in range(N):
        print(solve_impl(i,T))

    return 0


def main():
    ans = solve()


if __name__ == '__main__':
    main()

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

ans = [0] * (N-1)
CSF = [[int(i) for i in input().split()] for i in range(N-1)]

for i in range(N-1):
    now = 0
    for tranit_time, start, interval in CSF[i:]:
        if now <= start:
            now = start
            now += tranit_time
        else:
            if (now - start) % interval == 0:
                now += tranit_time
            else:
                now += interval - ((now - start) % interval)
                now += tranit_time
    ans[i] = now

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

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

for i in range(n-1):
    time_sum = 0
    for j in range(i,n-1):
        if time_sum < s[j]:
            time_sum = s[j]
        elif time_sum%f[j]!=0:
            time_sum += f[j]-time_sum%f[j]
        time_sum += c[j]
    print(time_sum)
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 j in range(i, n - 1):
        ans = -(-1 *max(ans, csf[j][1]) // csf[j][2]) * csf[j][2] + csf[j][0]
    print(ans)

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

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

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

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


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

print('0')

Solution (Python):



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

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


if __name__ == '__main__':
    main()

Solution (Python):
def abc084_c():
    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):
        time = 0
        for j in range(i, n - 1):
            if time < s[j]:
                time = s[j]
            else:
                time = f[j] * ceil(time/f[j])
            time += c[j]
        print(time)
    print(0)


abc084_c()

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

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

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

	print(x)

Solution (Python):

N = int(input())

CSF = [input() for i in range(N-1)]
ans_r = []

for i in range(N-1)[::-1]:
    C, S, F = map(int, CSF[i].split(' '))
    cost = S + C
    for j in range(i+1, N-1):
        Cj, Sj, Fj = map(int, CSF[j].split(' '))
        if cost <= Sj:
            cost = ans_r[(N-1) - j - 1]
            break
        else:
            temp = (cost+Fj-1)//Fj * Fj
            cost = temp + Cj
    ans_r.append(cost)
for i in ans_r[::-1]:
    print(i)
print(0)

Solution (Python):
def main():
    n = int(input())
    table = [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):
            c, s, f = table[j]
            if t <= s:
                t = s + c
            else:
                if t % f != 0:
                    t += f - (t % f)
                t += c
        print(t)
    print(0)


if __name__ == '__main__':
    main()

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

Solution (Python):
n=int(input())
c=[]
s=[]
f=[]
t=0
for i in range(n-1):
    a1,a2,a3=(list)(map(int,input().split()))
    c.append(a1)
    s.append(a2)
    f.append(a3)
time=[]
time.append(t)
for j in range(0,n-1):
    t=0
    for i in range(j,n-1):
        if i==j:
            t=s[i]+c[i]
        elif s[i]>=t:
            t=s[i]+c[i]
        elif (t-s[i])%f[i]==0:
            t=c[i]+t
        else:
            t=f[i]-(t-s[i])%f[i]+c[i]+t
    time.append(t)
    

time.sort(reverse=True)
for i in range(n):
    print(time[i])

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

Solution (Python):
import sys
import math

N = int(input())
C = []
S = []
F = []

for i in range(N - 1):
    c, s, f = [int(x) for x in input().split()]
    C.append(c)
    S.append(s)
    F.append(f)


def f(idx, t):
    depT = -1
    if t <= S[idx]:
        depT = S[idx]
    else:
        depT = S[idx] + F[idx] * math.ceil((t - S[idx]) / F[idx])
    return depT + C[idx]


for i in range(N - 1):
    t = 0
    for j in range(i, N - 1):
        t = f(j, t)
    print(t)

print(0)

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


def t(num):  
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  
      time = s[j]
    elif time % freq[j]:  
      time = wait_next(time, freq[j])
    time += cost[j]  
  return time


def wait_next(now, freq):  
  while(1 and False):
    if not now % freq:
      break
    now += 1

  return (now//freq+1)*freq


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

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


def t(num):  
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  
      time = s[j]
    elif time % freq[j]:  
      time = wait_next(time, freq[j])
    time += cost[j]  
  return time


def wait_next(now, freq):  
  while(1):
    if not now % freq:
      break
    now += 1
  return now


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

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


def t(num):
  time = 0
  for j in range(num, n-1):
    if time < s[j]:
      
      time = s[j]
      
    elif time % freq[j]:
      
      time = wait_next(time, freq[j])
      
    time += cost[j]
    

  return time


def wait_next(now, freq):
  while(1):
    if not now % freq:
      break
    now += 1
  return now


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

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

for i in range(N-1):
	time = 0
	for j in range(i, N-1):
		c, s, f = C_S_F[j]
		time = max(s, time + abs(time%-f))
		time += c
	print(time)
print(0)

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

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

for i in range(n-1):
    p,q,r=map(int,input().split())
    c.append(p)
    s.append(q)
    f.append(r)
    
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]-ans%f[j])%f[j]+c[j]
    print(ans)
print(0)

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

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

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

for i in range(n-1):
    p, q, r = map(int, input().split())
    c.append(p)
    s.append(q)
    f.append(r)

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

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

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

for j in range(n-1):
    time = 0
    tmp = 0
    for k in range(j, n-1):
        if arr[k][1] >= time:
            time = arr[k][1] + arr[k][0]
        else:
            if time % arr[k][2] == 0:
                time = time + arr[k][0]
            else:
                time = (time // arr[k][2] + 1) * arr[k][2] + arr[k][0]   
    print(time)
print(0)

Solution (Python):

"""
Created on Sun Dec  2 18:15:53 2018
ABC084C
@author: maezawa
"""
import math
n = int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    ci, si, fi = list(map(int, input().split()))
    c.append(ci)
    s.append(si)
    f.append(fi)
for j in range(n-1):
    ti = s[j]+c[j]
    for i in range(j+1,n-1):
        
        if s[i] >= ti:
            m = 0
        else:
            m = math.ceil((ti-s[i])/f[i])
        ti = s[i]+m*f[i]+c[i]
    print(ti)
print(0)

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

def move_time(i, t):
    ride = 0
    if t > S[i]:
        if t % F[i] == 0:
            ride = t
        else:
            ride = (t//F[i] + 1) * F[i]
    else:
        ride = S[i]

    return ride + C[i]

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        t = move_time(j, t)
    print(t)

print(0)

Solution (Python):

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

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

Solution (Python):
def nexttrain(x, c, s, f):
    return c + max(s, -(-x//f)*f)
def inpl(): return [int(i) for i in input().split()]

N = int(input())
st = 0
CSF = []
for _ in range(N-1):
    CSF.append(inpl())
for j in range(N-1):
    for i in range(N-1-j):
        c, s, f = CSF[i+j]
        st = nexttrain(st, c, s, f)
    print(st)
    st = 0
print(0)

Solution (Python):
n=int(input())
c=[]
for i in range(n-1):
    x,y,z=map(int,input().split())
    c.append((x,y,z))
for i in range(n-1):
    ans=0
    for j in range(i,n-1):
        ans=[c[j][1]+((ans-c[j][1]+c[j][2]-1)//c[j][2])*c[j][2],c[j][1]][ans<c[j][1]]
        ans+=c[j][0]
    print(ans)
ans=chk=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)


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

    print(t)