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())
schedules = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N - 1):
    sc, ss, sf = schedules[i]
    time = ss + sc
    for j in range(i + 1, N - 1):
        c, s, f = schedules[j]
        if time < s:
            time = s + c
        else:
            time = -(-time // f) * f + c
    print(time)
print(0)

Solution (Python):
N = int(input())
paths = []

for i in range(N - 1) :
    paths.append(list(map(int, input().split())))
    
for i in range(N) :
    if i == N -  1:
        print("0")
    else :
        t = paths[i][1] + paths[i][0]
        
        for j in range(i + 1, N - 1) :
            wait = paths[j][1]
            
            if wait < t :
                wait += paths[j][2] * ((t - wait) // paths[j][2] - 1)
            
            while wait < t :
                wait += paths[j][2]
                
            
            t = wait + paths[j][0]
        print(t)

Solution (Python):
N=int(input())
cnt=0
l=[tuple(map(int,input().split())) for _ in range(N-1)]
for s in range(N-1):
  cnt=0
  for t in range(s,N-1):
    if not cnt:
      cnt=l[t][0]+l[t][1]
    else:
      n=(cnt-l[t][1])//l[t][2]
      if n<0:
        cnt=l[t][1]+l[t][0]
      elif n*l[t][2]==cnt-l[t][1]:
        cnt=l[t][1]+l[t][2]*n+l[t][0]
      else:
        cnt=l[t][1]+l[t][2]*(n+1)+l[t][0]
  print(cnt)
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)


def time(i,x):
  if i == N:
    return x
  else:
    
    a = int(-(-x//F[i-1]))
    t = max(a*F[i-1],S[i-1])
    return time(i+1,t+C[i-1])

for i in range(N):
  print(time(i+1,0))

Solution (Python):
n = int(input())
csf = [tuple(map(int, input().split())) for _ in range(n - 1)]
for i in range(n):
    
    t = 0
    for j in range(i, n - 1):
        
        c_j, s_j, f_j = csf[j]

        
        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())
station = [list(map(int, input().split())) for i in range(n - 1)]

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

print("0")

Solution (Python):






N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


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

for s in range(1, N+1):
    
    if s == N:
        t = 0
        pass
    else:
        t = 0
        for i in range(s, N):
            if t < S[i]:
                t = S[i]

            elif t % F[i] == 0:
                pass

            else:
                t = t + F[i] - (t % F[i])

            t += C[i]
    print(t)

Solution (Python):






N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


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

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

Solution (Python):






N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


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

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

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):
    start = CSF[i][1]
    
    goal = 0
    for cur in range(i,N-1):
        start = max(CSF[cur][1], 
                    (goal//CSF[cur][2]+bool(goal%CSF[cur][2])) * CSF[cur][2])
        goal = start + CSF[cur][0]
        
    print(goal)
    
print(0)

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

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

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

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

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

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

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

ans = []
for i in range(N-1):
    t = 0
    for c,s,f in src[i:]:
        if t <= s:
            t = s+c
        else:
            t += (-t%f) + c
    ans.append(t)
ans.append(0)
print(*ans,sep='\n')

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

Solution (Python):
import math
def find(now,S, F):
    if now<S:
         ans = S
    else:
         ans = math.ceil(now/F)*F
    return(ans)

n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-2):
    ans = csf[i][1];
    for j in range(i,n-2):
        ans = find(ans+csf[j][0],csf[j+1][1],csf[j+1][2])
    print(ans+csf[n-2][0])
if n!=1: print(csf[n-2][0]+csf[n-2][1])
print(0)

Solution (Python):
def main():
    
    N = int(input())
    CSF = []
    for i in range(N-1):
        CSF.append(list(map(int, input().split())))
    CSF.append([0,0,1])
    
    
    ans_list = []
    for st in range(N-1):
        ans = CSF[st][1]
        for i in range(st,N-1):
            nex = ans + CSF[i][0]
            if nex <= CSF[i+1][1]:
                ans = CSF[i+1][1]
            else:
                if nex%CSF[i+1][2] == 0:
                    ans = nex
                else:
                    ans = (nex//CSF[i+1][2] + 1) * CSF[i+1][2]

        ans_list.append(ans)
    
    ans_list.append(0)
    
    for ans in ans_list:
        print(ans)
    
if __name__ == "__main__":
    main()

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)

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

Solution (Python):
N=int(input())
C = []
S = []
F = []
for i in range(N-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
def calcTime(loc,time):
    while loc < N-1:
        deltaT = time - S[loc]
        if deltaT < 0:
            time = S[loc] + C[loc]
        elif deltaT % F[loc] == 0:
            time += C[loc]
        else:
            time += F[loc] - (deltaT % F[loc]) + C[loc]
        loc += 1

    return time
for i in range(N-1):
    print(calcTime(i,S[i]))
print(0)

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

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

for i in range(N):
    tmp = 0
    for j in range(i,N-1):
        tmp = max(tmp, CSF[j][1])

        if not (tmp % CSF[j][2] == 0):
            tmp = tmp + CSF[j][2] - tmp % CSF[j][2]
        tmp += CSF[j][0]
            
    print(tmp)

Solution (Python):
N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]
result = [0]*N
for i in range(N-1):
    now = CSF[i][1] + CSF[i][0]
    for j in range(i+1,N-1):
        c,s,f = CSF[j]
        if s >= now:
            now = c + s 
        else:
            now = c + (now if now % f == 0 else (now // f+1)*f)
    result[i] = now
print(*result,sep='\n')

Solution (Python):

"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""


N = int(input())

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

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

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

time = 0
print(time)

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

for i in range(n):
	if i == n-1:
		print(0)
	else:
		cc = c[i:]
		ss = s[i:]
		ff = f[i:]
		ans = cc[0] + ss[0]
		for j in range(n-2-i):
			if ans <= ss[j+1]:
				ans = cc[j+1] + ss[j+1]
			else:
				start = (((ans - ss[j+1] + ff[j+1] - 1) // ff[j+1]) * ff[j+1]) + ss[j+1]
				ans = start + cc[j+1]

		print(ans)

Solution (Python):
from itertools import accumulate

n = int(input())
csfs = [[int(x) for x in input().split()] for _ in range(n-1)]

def make_func(c, s, f):
    def func(t):
        t = max(t, s)
        a, b = divmod(t, f)
        return f * (a + (b != 0)) + c
    return func

funcs = [make_func(*csf) for csf in csfs]
funcs2 = accumulate(funcs[::-1], func=lambda f1, f2: lambda x: f1(f2(x)))

res = [0] + [f(0) for f in funcs2]
for time in reversed(res):
    print(time)

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

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

for i in range(N):
    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_list = [0] * (N-1)
S_list = [0] * (N-1)
F_list = [0] * (N-1)
for i in range(N-1):
    C_list[i], S_list[i], F_list[i] = map(int, input().split())


for i in range(N-1):
    
    ans = 0
    
    for j in range(i, N-1):
        
        if ans < S_list[j]:
            ans = S_list[j]
        
        ans += C_list[j]
        
        if j != N-2:
            if ans % F_list[j+1] != 0:
                ans += F_list[j+1] - ans % F_list[j+1]
    print(ans)

print(0)

Solution (Python):


N = int(input())

C_list = [0] * (N-1)
S_list = [0] * (N-1)
F_list = [0] * (N-1)
for i in range(N-1):
    C_list[i], S_list[i], F_list[i] = map(int, input().split())


for i in range(N-1):
    
    ans = 0
    
    for j in range(i, N-1):
        
        if j == i:
            ans += S_list[j]
        
        elif ans < S_list[j]:
            ans = S_list[j]
        
        ans += C_list[j]
        
        if j != N-2:
            if ans % F_list[j+1] != 0:
                ans += F_list[j+1] - ans % F_list[j+1]
    print(ans)

print(0)

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

    for i in range(N-1):
        t = 0
        now = i
        while now < N-1:
            if t < S[now]:
                t = S[now]
            for dt in range(101):
                if (t+dt)%F[now]==0:
                    t += dt + C[now]
                    now += 1
                    break
        print(t)
    print(0)


if __name__ == '__main__':
    main()

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

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

    print(t)

Solution (Python):
import math
numOfStation = int(input())
array = [0] * (numOfStation - 1)

for i in range(numOfStation - 1):
    array[i] = input().split()

for i in range(numOfStation - 1):
    time = 0
    for j in range(i, numOfStation - 1):
        nextTrain = int(array[j][1])
        
        if time > nextTrain:
            
            nextTrain += math.ceil((time - nextTrain)/int(array[j][2]))*int(array[j][2])

        time += (nextTrain - time) + int(array[j][0])  

    print(time)

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)


def departure_t(t, j):
    if t < S[j]:
        return S[j]
    elif t % F[j] == 0:
        return t
    else:
        return t - t % F[j] + F[j]


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

Solution (Python):
N = int(input())
Nminus1 = N - 1


CSF = []



for i in range(Nminus1):
    c, s, f = input().split()
    CSF.append((int(c), int(s), int(f)))
    
    
    







ans = []

for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a < S:
            a = S
        elif a % F == 0:
        	pass
        else:
            a += F - a % F
        a += C
    ans.append(a)

ans.append(0)
print('\n'.join(map(str, ans)))

Solution (Python):
N = int(input())
Nminus1 = N - 1


CSF = []



for i in range(Nminus1):
    c, s, f = input().split()
    CSF.append((int(c), int(s), int(f)))
    
    
    







ans = []

for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a <= S:
            n = S - a
        else:
            mod = a % F 
            n = F - mod if mod != 0 else 0
        a = a + C + n
    ans.append(a)

ans.append(0)
print('\n'.join(map(str, ans)))

Solution (Python):
N = int(input())
Nminus1 = N - 1


CSF = []



for i in range(Nminus1):
    c, s, f = input().split()
    CSF.append((int(c), int(s), int(f)))
    
    
    







for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a <= S:
            n = S - a
        else:
            mod = a % F 
            n = F - mod if mod != 0 else 0
        a = a + C + n
    print(a)

print(0)

Solution (Python):
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  
            elif t % f == 0:
                
                
                pass
            else:
                t += f - (t % f)  
            t += c  
        ans.append(t)
    return '\n'.join(map(str, ans))
 
N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))

Solution (Python):

def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  
            elif t % f == 0:
                
                
                pass
            else:
                t += f - (t % f)  
            t += c  
        ans.append(t)
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))

Solution (Python):
N = int(input())
Nminus1 = N - 1


CSF = [0 for _ in range(Nminus1)]



for i in range(Nminus1):
    c, s, f = input().split()
    CSF[i] = (int(c), int(s), int(f))
    
    
    







for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a <= S:
            n = S - a
        else:
            mod = a % F 
            n = F - mod if mod != 0 else 0
        a = a + C + n
    print(a)

print(0)

Solution (Python):
N = int(input())
Nminus1 = N - 1


C = [0 for _ in range(Nminus1)]
S = [0 for _ in range(Nminus1)]
F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()

    C[i] = int(c)
    S[i] = int(s)
    F[i] = int(f)







for i in range(Nminus1):
    a = C[i] + S[i]
    for j in range(i + 1, Nminus1):
        if a <= S[j]:
            n = S[j] - a
        else:
            mod = a % F[j] 
            n = F[j] - mod if mod != 0 else 0
        a = a + C[j] + n
    print(a)

print(0)

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

_list = []
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    _list.append([a, b, c])


for i in range(n - 1):
    num = i
    time = 0

    while num < n - 1:
        c, s, f = _list[num]

        if num == i:
            time += s + c
            num += 1
            continue

        wait = s - time

        if wait >= 0:
            time += wait + c
            num += 1
            continue

        test = (wait * -1) // f
        s += int(f * test)

        wait = s - time

        if wait >= 0:
            time += wait + c

        else:
            time += wait + c + f

        num += 1

    print(time)


print(0)

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

_list = []
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    _list.append([a, b, c])


for i in range(n - 1):
    num = i
    time = 0

    while num < n - 1:
        c, s, f = _list[num]

        if num == i:
            time += s + c
            num += 1
            continue

        while True:
            wait = s - time

            if wait >= 0:
                time += wait + c
                break

            test = (wait * -1) // f
            s += int(f * test)

            if s - time < 0:
                s += f

        num += 1

    print(time)


print(0)

Solution (Python):
N = int(input())
lines = []

for i in range(N-1):
    lines.append(input())

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

for line in lines:
	c, s, f = line.split()
	C.append(int(c))
	S.append(int(s))
	F.append(int(f))

A = []

for i in range(N-1):
	a = C[i] + S[i]
	for j in range(i + 1, N - 1):
		if a <= S[j]:
			n = S[j] - a
		else:
			mod = a % F[j] 
			n = F[j] - mod if mod != 0 else 0
		a = a + C[j] + n
	A.append(a)

for a in A:
	print(a)
print(0)

Solution (Python):
N = int(input())
lines = []

for i in range(N-1):
    lines.append(input())

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

for line in lines:
	c, s, f = line.split()
	C.append(int(c))
	S.append(int(s))
	F.append(int(f))

A = []

for i in range(N-1):
	a = C[i] + S[i]
	for j in range(i + 1, N - 1):
		n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
		n = F[j] - n if a > S[j] and n != 0 else n
		
		a = a + C[j] + n
	A.append(a)

for a in A:
	print(a)
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)

results = []
for i in range(N):
    x = 0
    for n in range(i, N-1):
        if x < S[n]:
            x = S[n]
        if not (x - S[n]) % F[n] == 0:
            x += F[n] - (x - S[n]) % F[n]
        x += C[n]
    results.append(x)

for result in results:
    print(result)

Solution (Python):
N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    C_temp,S_temp,F_temp = map(int,input().split())
    C.append(C_temp)
    S.append(S_temp)
    F.append(F_temp)
ans = S[0]
for i in range(N):
    t = 0
    for j in range(i,N-1):
        if t<S[j]:
            t = S[j]
        elif t%F[j] == 0:
            pass
        else:
            t = t+F[j] -t%F[j]
        t += C[j]
    print(t)

Solution (Python):
N = int(input())
train = [ list(map(int,input().split())) for i in range(N-1)]
for i in range(N-1):
    a = [ 0 for i in range(i+1)]
    a[i] = train[i][1] + train[i][0]
    for j in range(i):
        if train[i][1] >= b[j]:
            a[j] = a[i]
        else:
            a[j] = (((b[j] - train[i][1] - 1) // train[i][2]) + 1) * train[i][2] + a[i]
    b = a
for i in a:
    print(i)
print(0)

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

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

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):
    time = 0
    while i != n-1:
        if i == 0:
            time += S[i]
        elif S[i] <= time and time%F[i] == 0:
            time += 0
        else:
            if time > S[i]:
                r = (time-S[i])//F[i]
                time = S[i] + F[i]*(r + 1)
            else:
                time = S[i]
        time += C[i]
        i += 1        
    print(time)

print(0)

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

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

for i in range(N-1):
    C_i = CSF[i][0]
    S_i = CSF[i][1]
    t = S_i + C_i
    for j in range(i+1,N-1):
        C_j, S_j, F_j = CSF[j]
        if t > S_j:
            w = t%F_j
            if w == 0:
                t += C_j
            else:
                t += F_j - w + C_j
        else:
            t = S_j + C_j
    print(t)
print(0)

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

for i in range(N):
    T = 0
    for j in range(i, N-1):
        if S[j] > T:
            T = S[j]

        if T % F[j] != 0:
            T += F[j] - T%F[j]

        T += C[j]

    print(T)

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

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


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

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

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

Solution (Python):
N=int(input().strip())
C=[0,]
S=[0,]
F=[0,]
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(1,N):
    dept=S[i]
    for j in range(i+1,N):
        arrive=dept+C[j-1]
        gap=arrive%F[j]
        dept=S[j] if arrive<=S[j] else arrive+((F[j]-gap)if gap>0 else 0)
    print(dept+C[N-1])
print(0)

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())
train_list = [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):
        if t < train_list[j][1]:
            t = train_list[j][1]
        elif t % train_list[j][2] == 0:
            pass
        else:
            t = t + train_list[j][2] - t % train_list[j][2]
        t += train_list[j][0]
    print(t)
print(0)

Solution (Python):
n = int(raw_input())
l = [map(int, raw_input().split()) for _ in range(n-1)]
m = []
for i in range(n-1):
    m.append(l[i][1]+l[i][0])
    for j in range(i):
        if m[j] <= l[i][1]:
            m[j] = m[i]
        else:
            k = (m[j] + l[i][2] - 1) / l[i][2] * l[i][2]
            m[j] = k +  l[i][0]
m.append(0)
for i in m:
    print i

Solution (Python):
def f(vs):
    t = 0
    for i in range(len(vs)):
        c, s, f = vs[i]
        m = max(0, (t - s + f - 1) / f)
        t = s + m*f + c
    return t

def solve():
    n = input()
    vs = [map(int, raw_input().split()) for i in range(n-1)]
    return [f(vs[i:]) for i in range(n)]

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

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

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

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

print(0)

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

anss = []
for i in range(N-1):
    now = 0
    for c,s,f in src[i:]:
        if now < s: now = s
        now += (f-(now%f))%f + c
    anss.append(now)
anss.append(0)
print(*anss, sep='\n')

Solution (Python):

def inpl(): return list(map(int, input().split()))
N = int(input())

stations = [inpl() for _ in range(N-1)]

for i in range(N):
    now = 0
    for C, S, F in stations[i:]:
        if now <= S:
            now = S
        now = S + -(-(now - S)//F)*F + C
        
    print(now)

Solution (Python):
N = int(input())
C = []
S = []
F = []
T = [0 for i in range(N)]

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

for t in T:
    print(t)

Solution (Python):
def inpl(): return list(map(int, input().split()))
N = int(input())
ans = [0 for i in range(N-1)]
CSF = [inpl() for i 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 = t+CSF[j][2]-t%CSF[j][2]
        t += CSF[j][0]
    print(t)

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

print(0)

Solution (Python):
import math
n = int(input())
params = [[int(param) for param in input().split()] for _ in range(n-1)]


while params:

    c, s, f = params.pop(0)
    total = s + c

    for index, param in enumerate(params):
        c, s, f = param

        if (s > total):
            total = s + c
        elif((total-s) % f == 0):
            total += c
        else:
            total = (total + f) - (total % f) + c
            
            
            
            

    print(total)

print(0)

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