Problem:
 Score : 300 points    Problem Statement A railroad running from west to east in Atcoder Kingdom is now complete.  There are N stations on the railroad, numbered 1 through N from west to east.  Tomorrow, the opening ceremony of the railroad will take place.  On this railroad, for each integer i such that 1≤i≤N-1 , there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.  The first train from Station i to Station i+1 will depart Station i  S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.  Here, it is guaranteed that F_i divides S_i .  That is, for each Time t satisfying S_i≤t and t％F_i=0 , there will be a train that departs Station i  t seconds after the ceremony begins and arrives at Station i+1  t+C_i seconds after the ceremony begins, where A％B denotes A modulo B , and there will be no other trains.  For each i , find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.      Constraints  1≤N≤500  1≤C_i≤100  1≤S_i≤10^5  1≤F_i≤10  S_i％F_i=0  All input values are integers.         Input Input is given from Standard Input in the following format:  N  C_1  S_1  F_1  :  C_{N-1}  S_{N-1}  F_{N-1}       Output Print N lines. Assuming that we are at Station i  (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i -th line should contain x .        Sample Input 1 3
6 5 1
1 10 1      Sample Output 1 12
11
0  We will travel from Station 1 as follows:   5 seconds after the beginning: take the train to Station 2 .  11 seconds: arrive at Station 2 .  11 seconds: take the train to Station 3 .  12 seconds: arrive at Station 3 .   We will travel from Station 2 as follows:   10 seconds: take the train to Station 3 .  11 seconds: arrive at Station 3 .   Note that we should print 0 for Station 3 .       Sample Input 2 4
12 24 6
52 16 4
99 2 2      Sample Output 2 187
167
101
0       Sample Input 3 4
12 13 1
44 17 17
66 4096 64      Sample Output 3 4162
4162
4162
0

Solution (Python):
n=int(input())
c=[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):
    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())
csf = [list(map(int, input().split())) for i in range(n-1)]
c,s,f=[],[],[]
for z in csf:
    c.append(z[0])
    s.append(z[1])
    f.append(z[2])
ans = []
t=0
for j in range(n):
    for i in range(j,n-1):
        if t<s[i]:
            t = s[i]
        elif t%f[i]!=0:
            t += f[i]-(t%f[i])
        t+=c[i]
    print(t)
    t=0

Solution (Python):
def min_times(stations, n):
    times = []
    for i in range(n - 1):
        ci, si, fi = stations[i]
        t = si + ci
        for j in range(i + 1, n - 1):
            cj, sj, fj = stations[j]
            if t < sj:
                t = sj + cj
            else:
                waiting = fj - (t - sj) % fj if (t - sj) % fj != 0 else 0
                t += waiting + cj
        times.append(t)
    times.append(0)
    return times


if __name__ == '__main__':
    n = int(input())
    stations = [list(map(int, input().split())) for _ in range(n - 1)]
    for i in min_times(stations, n):
        print(i)

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

        if t%f[j] == 0:
            t += c[j]
        else:
            t += f[j] - t % f[j] + c[j]

    print(t)

print(0)

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

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

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

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

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

print(0)

Solution (Python):
class station:
    def __init__(self, speed, first, interval):
        self.speed = speed
        self.first = first
        self.interval = interval


def onboard_duration(station, start_time, first=False):
    
    if first or start_time < station.first: 
        return station.first + station.speed
    elif start_time % station.interval == 0:
        return start_time + station.speed
    else:
        return start_time + station.interval - (start_time % station.interval) + station.speed


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

for i in range(len(stations)):
    elapsed_time = 0
    for j in range(i, len(stations)):
        if elapsed_time == 0:
            elapsed_time = onboard_duration(stations[j], elapsed_time, first=True)
        else:
            elapsed_time = onboard_duration(stations[j], elapsed_time)
    print(elapsed_time)

print('0')

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

Solution (Python):
def next_start(S, F):
    for i in range(S, S + F + 1):
        if i % F == 0:
            return i


N = int(input())
Cs, Ss, Fs = [], [], []

for i in range(N - 1):
    tmp = list(map(int, input().split()))
    Cs.append(tmp[0])
    Ss.append(tmp[1])
    Fs.append(tmp[2])


for nth in range(N - 1):
    t = 0
    for i in range(nth, N - 1):
        
        t = max(Ss[i], next_start(t, Fs[i]))
        
        t += Cs[i]
        
    print(t)
print(0)

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

def station(time, i):
    if i == N:
        print(time)
        return
    c, s, f = CSF[i]
    nextTime = s + c if time <= s else math.ceil(time / f) * f + c
    station(nextTime, i+1)

for i in range(N):
    station(0, i)
print(0)

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

Solution (Python):
N = int(input())
t = [[0 for _ in range(3)] for j in range(N-1)]
for i in range(N-1):
    t[i][0], t[i][1], t[i][2] = map(int, input().split())

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

Solution (Python):
N = int(input())
t = [[0 for _ in range(3)] for j in range(N-1)]
for i in range(N-1):
    t[i][0], t[i][1], t[i][2] = map(int, input().split())

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

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

T = []
for n in range(N):
    t = 0
    for i in range(n, N-1):
        if S[i] >= t:
            d = S[i] - t + C[i]
        else:
            temp = (t - S[i])%F[i]
            if temp == 0:
                d = C[i]
            else:
                d = F[i] - temp + C[i]
        t += d
    T.append(t)

for t in T:
    print(t)

Solution (Python):
from math import ceil
n=int(input())
lst=[]
for i in range(n-1):
    lst.append(list(map(int,input().split())))
def neccesary_time(m):
    t=0
    for i in range(m,n-1):
        s=lst[i][1]
        if t<=s:
            t=s+lst[i][0]
        else:
            t=s+lst[i][2]*ceil((t-s)/lst[i][2])+lst[i][0]
    return t
for i in range(n-1):
    print(neccesary_time(i))
print(0)

Solution (Python):





if __name__ == '__main__':
    station_count = int(input())
    c, s, f = list(), list(), list()

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

    for i in range(station_count):
        elapsed_time = 0

        for j in range(i, station_count - 1):
            if elapsed_time < s[j]:
                elapsed_time = s[j]
            elif (elapsed_time % f[j]) == 0:
                pass
            else:
                elapsed_time = elapsed_time + f[j] - (elapsed_time % f[j])

            elapsed_time += c[j]

        print(elapsed_time)

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

Solution (Python):
def main():
    N = int(input())
    C, S, F = [], [], []
    capnd, sapnd, fapnd = C.append, S.append, F.append
    for c, s, f in (map(int, input().split()) for _ in [0] * (N - 1)):
        capnd(c)
        sapnd(s)
        fapnd(f)

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

main()

Solution (Python):

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

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

Solution (Python):
from functools import lru_cache

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

    for i in range(1,N):
        current_time = 0
        for station_number in range(i,N):
            current_time = next_arrival_time(current_time, infos[station_number -1])
        print(current_time)
    print(0)

@lru_cache(maxsize = 2**26)
def next_arrival_time(current_time, info):
    if current_time <= info[1]:
        return info[1] + info[0]

    next_time = current_time
    remainder = next_time % info[2]
    while remainder != 0:
        next_time += 1
        remainder = next_time % info[2]
    while next_time < current_time:
        next_time += info[2]

    return next_time + info[0]

main()

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] = (int(i2) for i2 in input().split())
for j in range(n):
	answer = 0
	for k in range(j,n-1):
		if answer<s[k]: answer = s[k]
		elif answer%f[k]: answer += f[k]-(answer%f[k])
		answer += c[k]
	print(answer)

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)

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

for i in range(N-1):
    print(T[i])
print(0)

Solution (Python):
N = int(input())-1
timeLine = [[0 for x in range(3)] for y in range(N)]
for i in range(N):
    tmp = input().split()
    timeLine[i][0],timeLine[i][1],timeLine[i][2] = int(tmp[0]),int(tmp[1]),int(tmp[2])
for j in range(N):
    total = timeLine[j][0] + timeLine[j][1]
    now = j+1
    while now <= (N-1):
        if timeLine[now][1] >= total:
            total = timeLine[now][1] + timeLine[now][0]
        else:
            if timeLine[now][1] + timeLine[now][2] >= total:
                total = timeLine[now][0] + timeLine[now][1] + timeLine[now][2]
            else:
                n = int((total-timeLine[now][1])/timeLine[now][2])
                if (total-timeLine[now][1]) % timeLine[now][2] > 0:
                    n += 1
                total = timeLine[now][0] + timeLine[now][1] + timeLine[now][2] * n
        now +=1
    print(total)
print(0)

Solution (Python):
n = int(input())
c = [0]*(n-1)
s = [0]*(n-1)
f = [0]*(n-1)

for i in range(n-1):
    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]):
            t += f[j]-(t%f[j])
        t += c[j]
    print(t)

Solution (Python):
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N-1)]
time ={}
time[N] = 0

def timecal(i, now=0):
    if i == N:
        return now
    else:
        if now <= CSF[i-1][1]:
            return timecal(i+1, CSF[i-1][1] + CSF[i-1][0])
        else:
            return timecal(i+1, now + CSF[i-1][0] + (CSF[i-1][2] - now % CSF[i-1][2]) % CSF[i-1][2])

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

Solution (Python):
n = int(input())
data = [list(map(int,input().split())) for _ in range(n - 1)]
time = [0] * n
for i,arr in enumerate(data):
    for k in range(i+1):
        if arr[1] > time[k]:
            time[k] = arr[0] + arr[1]
        elif time[k] % arr[2] == 0:
            time[k] += arr[0]
        else:
            time[k] += arr[2] - (time[k] % arr[2]) + arr[0]

for i in time:
    print(i)

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

time = [0] * N


for i, station in enumerate(stations):
    C, S, F = station
    for j in range(i + 1):
        if S > time[j]:
            time[j] = S + C
        elif time[j] % F == 0:
            time[j] += C
        else:
            time[j] += F - (time[j] % F) + C

[ print(t) for t in 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):
    sumTime = 0
    stationNumber = i
    
    while stationNumber < N - 1:
        
        if sumTime <= s[stationNumber]:
            sumTime = s[stationNumber]

        if (sumTime - s[stationNumber]) % f[stationNumber] == 0:
            sumTime += c[stationNumber]
            stationNumber += 1
        else:
            sumTime += f[stationNumber] - (sumTime - s[stationNumber]) % f[stationNumber]

    print(sumTime)

Solution (Python):
import math
def find(stations, start):
	currentT=stations[start][1]
	currentS=start
	while currentS != len(stations):
		C=stations[currentS][0]
		S=stations[currentS][1]
		F=stations[currentS][2]

		if currentT < S:
			currentT=S
		tmp=math.ceil((currentT-S)/F)
		currentT=S+tmp*F+C
		currentS+=1
	return currentT

N=int(input())
stations=[]
for i in range(N-1):
	stations.append([int(i) for i in input().split()])
for i in range(N-1):
	print(find(stations, i))
print(0)

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

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

C = []
S = []
F = []
for i 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:
            pass
        else:
             t +=  F[j] - t % F[j]
        t += C[j]
    print(t)

Solution (Python):
N = int(raw_input())
C, S, F = [], [], []
for i in range(N-1):
	C_S_F = [int(num) for num in raw_input().split()]
	C.append(C_S_F[0])
	S.append(C_S_F[1])
	F.append(C_S_F[2])

def calc_time(i):
	Y = S[i] + C[i]
	for point in range(i, N-2):
		
		Y = max((Y / F[point+1] + int((Y % F[point+1]) != 0)) * F[point+1], 
			S[point+1]) + C[point+1]
		
	return Y

for i in range(N-1):
	print calc_time(i)

print 0

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

for i in range(N):
	t = 0
	station = i
	while station < N-1:
		c, s, f = li[station]
		if t < s:
			t = s
			t += c
		else:
			t += (f-(t-s))%f + c
		station += 1
	print(t)

Solution (Python):



import sys

def main():
    n = int(input())
    csf = tuple(tuple(map(int, line.split())) for line in sys.stdin.readlines())
    ans = []
    for i in range(n - 1):
        t = 0
        for c, s, f in csf[i:]:
            if t < s:
                t = s
            k, r = divmod(t - s, f)
            if r != 0:
                t = s + (k + 1) * f
            t += c
        ans.append(t)
    ans.append(0)

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

if __name__ == '__main__':
    main()

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


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

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

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

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

    times, start, interval = [], [], []
    for i in range(N-1):
        t, s, i = list(map(int, input().split()))
        times.append(t)
        start.append(s)
        interval.append(i)

    for src_station_idx in range(N-1):
        current_total_time = start[src_station_idx] + times[src_station_idx]

        for via_station_idx in range(src_station_idx+1, N-1):
            moving_time = times[via_station_idx]

            
            if current_total_time <= start[via_station_idx]:
                waiting_time = start[via_station_idx] - current_total_time
            else:
                passed_time_from_start = current_total_time - start[via_station_idx]
                passed_time_from_before = passed_time_from_start % interval[via_station_idx]

                if passed_time_from_before == 0:
                    waiting_time = 0
                else:
                    waiting_time = interval[via_station_idx] - passed_time_from_before

            current_total_time += waiting_time + moving_time

        print(current_total_time)

    print(0)

main()

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

C = []
S = []
F = []
for i 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:
            pass
        else:
             t +=  F[j] - t % F[j]
        t += C[j]
    print(t)

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


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

Solution (Python):
def solve():
    n = int(input())
    c = []
    s = []
    f = []
    result = []
    for i in range(n - 1):
        tc, ts , tf = input().split()
        c.append(int(tc))
        s.append(int(ts))
        f.append(int(tf))
    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 = t + c[j]
        result.append(t)
    for i in range(n):
        print(result[i])
solve()

Solution (Python):
n = int(input())
ans = [0]*n
c, s, f = [], [], []
for i in range(n - 1):
    ct, st, ft = list(map(int, input().split()))
    c.append(ct)
    s.append(st)
    f.append(ft)

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

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

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc084/tasks/abc084_c

"""
import sys
from sys import stdin
from collections import namedtuple
from math import ceil
input = stdin.readline


def solve(trains, N):
    arrives = []

    for i in range(N-1):
        arrives.append(0)
        for j in range(len(arrives)):
            t = arrives[j] - trains[i].S
            dt = max(trains[i].S, (trains[i].S + ceil(t/trains[i].F)*trains[i].F ))
            arrives[j] = dt + trains[i].C

    arrives.append(0)
    return arrives


T = namedtuple('T', ['C', 'S', 'F'])
def main(args):
    trains = []
    N = int(input())
    for _ in range(N-1):
        c, s, f = map(int, input().split())
        trains.append(T(c, s, f))
    ans = solve(trains, N)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

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

time_list = []

for i in range(N - 1):
    C, S, F = map(int, input().split())
    time_list.append(C + S)
    for j in range(0, i):
        t = time_list[j]
        if t < S:
            time_list[j] += S - t + C
        elif t % F != 0:
            time_list[j] += F - t % F + C
        else:
            time_list[j] += C

time_list.append(0)

for time in time_list:
    print(time)

Solution (Python):
N = int(input())
t = [0 for i in range(N)]
csf = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
	tmp_t = 0
	for j in range(i, N - 1):
		c, s, f = csf[j]
		if s >= tmp_t:
			tmp_t += s - tmp_t + c
		else:
			a = (tmp_t - s + f - 1) // f
			tmp_t += s + f * a - tmp_t + c
	print(tmp_t)
print(0)

Solution (Python):
N = int(input())
t = [0 for i in range(N)]
csf = [list(map(int, input().split())) for i in range(N - 1)]
for i in range(N - 1):
	tmp_t = 0
	for j in range(i, N - 1):
		c, s, f = csf[j]
		if s >= tmp_t:
			tmp_t += s - tmp_t + c
		else:
			a = (tmp_t - s + f - 1) // f
			tmp_t += s + f * a - tmp_t + c
	print(tmp_t)
print(0)

Solution (Python):

def main():
    N = int(input())

    x = [[int(a) for a in input().split()] for i in range(N - 1)]

    for i in range(N):
        time = 0
        for a in range(i, N-1):
            C = x[a][0]
            S = x[a][1]
            F = x[a][2]
            time = max(time, S)
            if time % F == 0:
                pass
            else:
                time = time + F - time % F
            time += C
        print(time)

main()

Solution (Python):
n = int(input())
c=[]
t=[]
f=[]
for v in range(n-1):
    cn, tn, fn = map(int,input().split())
    c.append(cn)
    t.append(tn)
    f.append(fn)

for q in range(n):
    time=0
    for p in range(q,n-1):
        if time>t[p]:
            while time%f[p]>0:
                time+=1
        else:
            time=t[p]
        time+=c[p]
    print(time)

Solution (Python):
n = int(input())
c=[]
t=[]
f=[]
for v in range(n-1):
    cn, tn, fn = map(int,input().split())
    c.append(cn)
    t.append(tn)
    f.append(fn)

for q in range(n):
    time=0
    for p in range(q,n-1):
        if time>t[p]:
            while time%f[p]>0:
                time+=1
        else:
            time=t[p]
        time+=c[p]
    print(time)

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

for (i, tmp_s) in enumerate(s):
    tmp_t = tmp_s 
    for j in range(i, N-1):
        if tmp_t<s[j]:
            delta = s[j] - tmp_t
        else:
            delta = f[j]-tmp_t%f[j]
        if delta==f[j]:
            delta = 0
        tmp_t = tmp_t + delta +c[j]
    print(tmp_t)

print(0)

Solution (Python):
n = int(input())
t = 0
st = 0
cn = []
sn = []
fn = []

for i in range(n-1):
  c,s,f = map(int,input().split())
  cn.append(c)
  sn.append(s)
  fn.append(f)

for j in range(n-1):
    t = 0
    for i in range(j,n-1):
      st = sn[i]
      if t <= sn[i]:
        t = sn[i]
      if t%fn[i] != 0:
          t += fn[i]-t%fn[i]
      t += cn[i]
    print(t)


print(0)

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

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

for i in range(0,N-1):
    X.append(list(map(int,input().strip().split(" "))))

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

Solution (Python):
def F(Arri,S,F,C):
    if (Arri-S) <= 0:
        k=0
    else:
        k = (Arri-S) // F
        if (Arri-S) % F !=0:
            k += 1
    return S+F*k+C

N=int(input())
n=0
L=[]
l = [0,0,0]
while n < N-1:
    l[0],l[1],l[2] = map(int,input().split(' '))
    L.append(l.copy())
    n+=1
T = []
j = 0
while j < N-1:
    t=0
    t += L[j][0]+L[j][1]
    q=j+1
    while q < N-1:
        t = F(t,L[q][1],L[q][2],L[q][0])
        q += 1
    T.append(t)
    j += 1
T.append(0)
for i in T:
    print(i)

Solution (Python):
from math import ceil
n = int(input())
data = [list(map(int,input().split())) for i in range(n-1)]
ret = 0

for cnt in range(n):
    ret = 0
    for i in data:
        if ret <= i[1]:
            ret = i[1]
        else:
            ret = ceil(ret/i[2]) * i[2]
        ret += i[0]
    print(ret)
    if cnt != n-1 : data.pop(0)

Solution (Python):


n=int(raw_input())
l=[0 for i in xrange(n)]
for i in xrange(n-1):
 c,s,f=map(int,raw_input().split())
 for j in xrange(i+1):
  l[j]=max(s,(l[j]+f-1)/f*f)+c
for i in xrange(n):
 print l[i]

Solution (Python):
N = int(input())
n = 0
C = []
S = []
F = []
T = []
while n < N-1:
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
    n = n + 1
n = 0
while n < N-1:
    t = S[n]
    T.append(t)
    for i in range(n,N-1):
        if T[n]<=S[i]:
            T[n] = S[i]
        if T[n]%F[i] != 0:
            a = T[n]%F[i]
            T[n] = T[n] + F[i] - a
        T[n] = T[n] + C[i]
    print(T[n])
    n = n+1
print(0)

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

Solution (Python):


class Diagram:
    def __init__(self, n, xs):
        self.n = n
        self.xs = xs + [[0, 0, 0]]

    def departure(self, i, t):
        if i == self.n - 1:
            return t
        s = self.xs[i][1]
        f = self.xs[i][2]
        c = s // f
        x = max(s, t)
        d, m = divmod(x, f)
        if m == 0:
            return x
        else:
            return f*(d+1)

    def arrival(self, i, t):
        return self.departure(i, t) + self.xs[i][0]



if __name__ == "__main__":
    n = int(input())
    xs = [list(map(int, input().split())) for i in range(n-1)]
    d = Diagram(n, xs)

    ys = [0]*n
    for i in range(n):
        for j in range(i,n) :
            ys[i] = d.arrival(j, ys[i])
    for y in ys:
        print(y)

Solution (Python):


n = int(input())
c = [0] * (n + 1)
s = [0] * (n + 1)
f = [0] * (n + 1)

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

def time(i, after=0):
    
    if i == n:
        return after
    if (after < s[i]):
        start_time = s[i]
    else:
        if (after - s[i]) % f[i] == 0:
            start_time = after
        else:
            start_time = ((after - s[i])  // f[i] + 1) * f[i] + s[i]
    return time(i + 1, after=start_time+c[i])

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

Solution (Python):
import math
csf=[map(int,input().split())for _ 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())
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)

ans = []
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)