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())

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-1):
    t = 0
    for j in range(i, n - 1):
        if t < ss[j]:
            t = ss[j]
        else:
            if t % fs[j] != 0:
                t += fs[j] - (t % fs[j])
        t += cs[j]
    print(t)
print(0)

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

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

Solution (Python):


N = int(input())
CSF = []
for n in range(N-1):
    s = input()
    CSF.append([int(x) for x in s.split()])

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

Solution (Python):
from math import ceil

n = int(input())

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

buf = []
for i, (c, s, f) in enumerate(trains):
    t = s + c
    for cj, sj, fj in trains[i + 1: n]:
        if t < sj:
            t = sj
        else:
            t = ceil(t / fj) * fj
        t += cj
    buf.append(t)
buf.append(0)

print('\n'.join(map(str, buf)))

Solution (Python):

N = 0
C = []
S = []
F = []


def getNextTrain(i, time):
  
  if time <= S[i]:
    return S[i]
  else:
    n = time / F[i]
    m = time % F[i]
    t = F[i] * n
    if m != 0:
      t += F[i]
    
    
    
    

    return t


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


for k in range(N):
  arrive = 0
  for p in range(k, N-1): 
    
    arrive = getNextTrain(p, arrive)
    
    arrive += C[p]
    
  print arrive

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

Solution (Python):


import math
import sys

n = int(sys.stdin.readline().strip())
f_list = []
for _ in range(n - 1):
    c, s, f = sys.stdin.readline().strip().split(" ")
    c = int(c)
    s = int(s)
    f = int(f)
    f_list = [c + math.ceil((max(_f, s)) / f) * f for _f in f_list]
    f_list.append(c + s)
f_list.append(0)
for _f in f_list:
    print(_f)

Solution (Python):
c=[]
s=[]
f=[]

N = 506

for i in range(N) :
    c.append(0)
    s.append(0)
    f.append(0)
n=int(input())
for i in range(1,n) :
    c[i],s[i],f[i] = map(int,input().split())
    
for i in range(1,n) :
    now = s[i] + c[i]
    for j in range(i+1,n) :
        if now >= s[j] :
            now = ((now + f[j] - 1)//f[j] )*f[j]
            now += c[j]
        else :
            now = s[j]
            now += c[j]
    print(now)

print(0)

Solution (Python):

import math

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

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1, N-1):
        s, t, u = CSF[j][0], CSF[j][1], CSF[j][2]
        if t < ans:
            n = int(math.ceil((ans - t) / u))
            ans = int(s + t + u * n)
        else:
            ans = s + t

    print int(ans)

print 0

Solution (Python):

n = int(input())
e = [[int(i) for i in input().split()] for i in range(n-1)]

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

print(0)

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


def next_time(i, t):
    a = S[i]
    if t - a < 0:
        return a
    if t % F[i] == 0:
        return t
    b = (t - a + F[i] - 1) // F[i]
    
    assert (a + b * F[i]) % F[i] == 0
    return a + b * F[i]


for i in range(N):
    time = 0
    for j in range(i, N - 1):
        time = next_time(j, time)
        time += C[j]

    print(time)

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

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


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

Solution (Python):
n = int(input())
cn = []
sn = []
fn = []
for i in range(n-1):
    ci, si, fi = map(int, input().split())
    cn.append(ci)
    sn.append(si)
    fn.append(fi)

ans = [0] * n

for i in range(n-1):
     c = cn[i]
     s = sn[i]
     f = fn[i]
     ans[i] += s + c
     t = ans[i]
     for j in range(i+1, n-1):
        c2 = cn[j]
        s2 = sn[j]
        f2 = fn[j]
        if s2 <= t and t % f2 == 0:
            w = 0
        elif s2 > t:
            w = s2 - t
        else:
            w = f2 - (t % f2)
        ans[i] += w+c2
        t = ans[i]

for i in ans:
    print(i)

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

for i in range(N-1):
  _input = str(input().replace('\r','')).split(' ')
  array.append((int(_input[0]), int(_input[1]), int(_input[2])))

for i in range(N-1):
  time = array[i][0] + array[i][1]
  for j in range(i+1, N-1):
    if array[j][1] > time:
      time = array[j][1]
    elif time % array[j][2] != 0:
      time = time - time % array[j][2] + array[j][2]
    time = time + array[j][0]
  print(time)

print(0)

Solution (Python):


import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line.rstrip("\n"))

        timestamps = [0]
        for i in xrange(N - 1):
            if i > 0:
                timestamps.append(0)

            c, s, f = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))

            for i in xrange(len(timestamps)):
                if timestamps[i] <= s:
                    timestamps[i] = s + c
                else:
                    d = timestamps[i] % f
                    if d == 0:
                        timestamps[i] += c
                    else:
                        timestamps[i] += (f - d) + c

        for timestamp in timestamps:
            print timestamp
        print 0

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Solution (Python):
c, s, f = [0] * 505, [0] * 505, [0] * 505
n = input()
for _ in xrange(1, n):
    tc, ts, tf = map(int, raw_input().split())
    c[_], s[_], f[_] = tc, ts, tf
for i in xrange(1, n):
    t = s[i]
    t += c[i]
    for j in xrange(i + 1, n):
        if t >= s[j]:
            t += (f[j] - (t % f[j])) % f[j]
        else:
            t = s[j]
        t += c[j]
    print t
print 0

Solution (Python):


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

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

res = []

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

print 0

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

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

for i in range(n-1):
    add=list(map(int,input().split()))
    c.append(add[0])
    s.append(add[1])
    f.append(add[2])
    
for i in range(n-1):
    r[i]=s[i]+c[i]
    for j in range(n-i-2):
        if r[i] < s[i+j+1]:
            wa = s[i+j+1]-r[i]
        elif (r[i]-s[i+j+1])%f[i+j+1] ==0:
            wa=0
        else:
            wa = f[i+j+1]-((r[i]-s[i+j+1])%f[i+j+1])
        r[i] += wa+c[i+j+1]
        
        
print('\n'.join([str(r) for r in r]))

Solution (Python):
n = int(raw_input())
c = []
s = []
f = []
f_of = []

for a in range(n-1):
  x,y,z = map(int,raw_input().split(" "))
  c.append(x)
  s.append(y)
  f.append(z)
  f_of.append(y/z) 

for a in range(n):
  now = 0
  for b in range(a,n-1):
    if now % f[b] != 0:
      buf = f[b] - (now % f[b])
    else:
      buf = 0
    if (now+buf) < f[b]*f_of[b]:
      now = f[b]*f_of[b] + c[b]
    else:
      now = now + buf + c[b]
  print now

Solution (Python):

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

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

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

Solution (Python):

import math

n = int(input())
sta = []

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

for i in range(n):
    time = 0
    while i < n - 1:
        x = math.ceil((time - sta[i]['s']) / sta[i]['f']) if time > sta[i]['s'] else 0
        time = sta[i]['s'] + sta[i]['f'] * x + sta[i]['c']
        i += 1
    print(str(time))

Solution (Python):
import sys

input = sys.stdin.readline
print = sys.stdout.write

a = int(input())

trains = []
for i in range(a-1):
    trains.append([int(i) for i in input().split()])

for start in range(a):
    time = 0
    for i in range(start,a-1):
        if i == 0:
            time += trains[i][1] + trains[i][0]
        else:
            if time < trains[i][1]:
                time = trains[i][1]
            elif time % trains[i][2] > 0:
                time += trains[i][2] - (time % trains[i][2])
            time += trains[i][0]
    print(str(time)+"\n")

Solution (Python):

import math
N = int(input())
Cs = []
Ss = []
Fs = []
for n in range(N-1):
    C, S, F = map(int, input().split())
    Cs.append(C)
    Ss.append(S)
    Fs.append(F)

for n in range(N-1):
    current_time = 0
    for i in range(n,N-1,1):
        if Ss[i] - current_time <= 0:
            tmp = (current_time + Ss[i]) % Fs[i]
            wait_time = (Fs[i] - tmp) % Fs[i]
            
            
        else:
            wait_time = (Ss[i] - current_time)
            
            
        current_time += wait_time
        current_time += Cs[i]
        
    print(current_time)
print(0)

Solution (Python):
n = int(input())
c = []
s = []
f = []
for i in range(n - 1):
  c += [0]
  s += [0]
  f += [0]
  c[i], s[i], f[i] = [int(x) for x in input().split()]

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

print('0')

Solution (Python):
import math

N = int(input())
c = []
s = []
f = []
for _ in range(N - 1):
    _c, _s, _f = [int(x) for x in input().split()]
    c.append(_c)
    s.append(_s)
    f.append(_f)

def solve(i):
    start_time = 0
    for j in range(i, N - 1):
        
        
        
        depart_time = get_dep_time(start_time, s[j], f[j])
        
        arrived_time = depart_time + c[j]
        
        start_time = arrived_time
    return arrived_time

def get_dep_time(start, s, f):
    """
    E.g.:
        start = 18
        s = 15
        f = 5
        ret = 20
        start = 13
        s = 15
        f = 5
        ret = 15
    """
    t = max(start, s)
    return math.ceil(t / f) * f

for i in range(N - 1):
    
    
    print(solve(i))
    
print(0)

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

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

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

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

Solution (Python):
import sys
import math

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

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

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

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

Solution (Python):
from pprint import pprint as pp
"""
問題文
Atcoder国に、 1 本の東西方向に走る鉄道が完成しました。
この鉄道には N 個の駅があり、西から順に 1,2,…,N の番号がついています。
明日、鉄道の開通式が開かれます。
この鉄道では、1≦i≦N−1 を満たす全ての整数 i に対して、駅 i から駅 i+1 に、Ci 秒で向かう列車が運行されます。
ただし、これら以外の列車は運行されません。
駅 i から駅 i+1 に移動する列車のうち最初の列車は、開通式開始 Si 秒後に駅 i を発車し、その後は 
Fi 秒おきに駅 i を発車する列車があります。
また、Si は Fi で割り切れることが保証されます。
つまり、A%B で A を B で割った余りを表すとき、Si≦t,t%Fi=0 を満たす全ての t に対してのみ、
開通式開始 t 秒後に駅 i を出発し、開通式開始 t+Ci 秒後に駅 i+1 に到着する列車があります。
列車の乗り降りにかかる時間を考えないとき、全ての駅 i に対して、開通式開始時に駅 i にいる場合、
駅 N に到着できるのは最も早くて開通式開始何秒後か、答えてください。
制約
    1≦N≦500
    1≦Ci≦100
    1≦Si≦105
    1≦Fi≦100
    Si%Fi=0
    入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。

N
C1 S1 F1
:
CN−1 SN−1 FN−1

出力
i 行目 (1≦i≦N) に、開通式開始時に駅 i にいる場合、駅 N に到着できるのが最も早くて開通式開始 x 秒後のとき、x を出力せよ。
"""
n=int(input())
csf = []
for _ in range(n-1):
  csf.append(list(map(int, input().split())))

ts = []

for i in range(n-1):
  t = csf[i][1]
  for c,s,f in csf[i:]:
    if t < s:
      t = s
    if (t%f) != 0:
      t += f-(t % f)
    t += c
  ts.append(t)
ts.append(0)

for t in ts:
  print(t)

Solution (Python):
if __name__ == '__main__':
    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)

    ans_list = []

    for i in range(N - 1):
        tmp_ans = 0
        while i < N - 1:
            if tmp_ans <= S[i]:
                tmp_ans = S[i] + C[i]
            else:
                if tmp_ans % F[i] != 0:
                    tmp_ans += F[i] - (tmp_ans % F[i])
                tmp_ans += C[i]

            i += 1

        ans_list.append(tmp_ans)

    
    ans_list.append(0)
    for answer in ans_list:
        print(answer)

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


for i in range(N-1):
	C = info[i][0]
	S = info[i][1]
	F = info[i][2]
	next_arrive = []
	for j in arrive:
		if j <= S:
			next_arrive.append(S+C)
		else:
			if j % F == 0:
				next_arrive.append(j+C)
			else:
				cnt = F * ((j // F) + 1)
				next_arrive.append(cnt+C)

	next_arrive.append(S+C)
	arrive = next_arrive[:]

arrive.append(0)

for ans in arrive:
	print(ans)

Solution (Python):
N = int(raw_input())
train = [map(int, raw_input().split(' ')) for _ in range(N-1)]

for i in range(N-1):
    c1, s1, f1 = train[i]
    time = s1 + c1
    for j in range(i+1, N-1):
        c2, s2, f2 = train[j]
        next_dept = max(s2, time)
        if next_dept != s2 and time % f2 != 0:
            next_dept += f2 - time % f2
        time = next_dept + c2
    print time
print 0

Solution (Python):
import sys                                                                     
N = int(sys.stdin.readline())                                                  
Cs = []                                                                        
Ss = []                                                                        
Fs = []                                                                        
for i in range(N - 1):                                                         
    C, S, F = map(int, sys.stdin.readline().split())                           
    Cs.append(C)                                                               
    Ss.append(S)                                                               
    Fs.append(F)                                                               
Cs.append(0)                                                                   
Ss.append(0)                                                                   
Fs.append(1)                                                                   
                                                                               
for i in range(N - 1):                                                         
    t = 0                                                                      
    for j in range(i, N - 1):                                                  
        t = max(t, Ss[j]) + Cs[j]                                              
        t = ((t - 1) // Fs[j + 1] + 1) * Fs[j + 1]                             
    print(t)                                                                   
print(0)

Solution (Python):
n = int(input())
c = []
s = []
f = []

for i in range(n-1):
    tc,ts,tf = map(int,input().split(' '))
    c.append(tc)
    s.append(ts)
    f.append(tf)

ans = []
for i in range(n-1):

    time=s[i]+c[i]
    for j in range(i+1,n-1):


        time = max(s[j],(int((time-0.1)/f[j])+1)*f[j]) + c[j]
    ans.append(time)

ans.append(0)

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

Solution (Python):
def train(c,s,f,t):
    if t < s:
        t = s
    while (t-s)%f != 0:
        t += 1
    return t+c


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

Solution (Python):
import numpy as np


def getInput():
    """

    :return: list of list of str. 1st dim: row, 2nd dim: column.
    """
    separator = ' '
    ret_array = []
    while True:
        try:
            row = input().split(sep=separator)
            ret_array.append(row)
        except EOFError:
            break
    return ret_array


g = getInput()


N = int(g[0][0])
C = np.zeros(N-1, dtype=int)
S = np.zeros(N-1, dtype=int)
F = np.zeros(N-1, dtype=int)


for i in range(0, N-1):
    C[i], S[i], F[i] = list(map(int, g[i+1]))


for i in range(0, N):
    if i == N-1:
        print(0)
        exit()
    current_time = 0
    for j in range(i, N-1):
        if S[j] > current_time:
            current_time = S[j]
        else:
            current_time = np.ceil(current_time/F[j])*F[j]
        current_time += C[j]
    print(int(current_time))

Solution (Python):
import math
n=int(input())
x=[]
for k in range(n-1):
  a,b,c=[int(i) for i in input().split(' ')]

  x=[max(math.ceil((j-b)/c)*c+b,b) + a for j in x]

  x.append(a+b)
x.append(0)
for i in range(n):
  print(x[i])

Solution (Python):
N = int(input())
C = [None]*(N-1)
S = [None]*(N-1)
F = [None]*(N-1)

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

for v in ans:
  print(v)

Solution (Python):
n = input()
t = [map(int, raw_input().split()) for _ in xrange(n-1)]

for i in xrange(n-1):
    s = t[i][1]
    for j in xrange(i, n-1):
        if s >= t[j][1]:
            if not ((s - t[j][1]) % t[j][2]) == 0:
                s += t[j][2] - ((s - t[j][1]) % t[j][2])
            s += t[j][0]
        else:
            s = t[j][0] + t[j][1]
    print s
print 0

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




ans=[]

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


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

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

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

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

for i in range(n):
    t = 0
    for j in range(i,n-1):
        ci, si, fi = vec[j]
        if t <= si :
            t = si
        else :
            t = ((t+fi-1)//fi)*fi
        t += ci
    print(t)

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

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


def helper(t,i):
  c,s,f = stations[i]

  n = max((t-s-1)//f+1,0)
  return s+f*n+c

for s in range(N):
  t = 0
  for i in range(s,N):
    t = helper(t,i)
  print(t)

print(0)

Solution (Python):
import sys

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

def calc(n, t, cache={}):
    if n == N - 1:
        return t
    if (n, t) in cache:
        return cache[(n, t)]
    if t >= S[n]:
        st = S[n] + (t - S[n] + F[n] - 1) // F[n] * F[n]
    else:
        st = S[n]
    r = calc(n + 1, st + C[n])
    cache[(n, t)] = r
    return r

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

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

Solution (Python):


import functools


def div_ceil(a, b):
    return (a + b - 1) // b


def simulate(cs, ss, fs, goal_sta, start_sta):
    assert start_sta <= goal_sta
    cur_t = 0
    for i in range(start_sta, goal_sta):
        next_start_t = max(ss[i], div_ceil(cur_t, fs[i]) * fs[i])
        cur_t = next_start_t + cs[i]
    return cur_t


def solve(n, cs, ss, fs):
    sim_from = functools.partial(simulate,
                                 cs=cs, ss=ss, fs=fs, goal_sta=n - 1)
    return [sim_from(start_sta=i) for i in range(n)]


def main():
    n = int(input())
    cs = [-1 for _ in range(n - 1)]
    ss = [-1 for _ in range(n - 1)]
    fs = [-1 for _ in range(n - 1)]
    for i in range(n - 1):
        cs[i], ss[i], fs[i] = (int(z) for z in input().split())
    print(*solve(n, cs, ss, fs), sep="\n")


if __name__ == '__main__':
    main()

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

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

for i in range(n - 1):
    current = 0
    for j in range(i, n - 1):
        if current >= arr[j][1]:
            if current % arr[j][2] == 0:
                current = current + arr[j][0]
            else:
                current = (arr[j][2] - (current % arr[j][2])) + current + arr[j][0]
                pass
        else:
            current = arr[j][1] + arr[j][0]
    print(current)

print(0)

Solution (Python):




N = int(input())

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

dp = [0]*N
for i in range(1, N):
    dp[i] = S[i] + C[i]
    for x in range(1, i):
        sec = dp[x]
        if sec <= S[i]:
            dp[x] = S[i] + C[i]
        else:
            vol = (sec // F[i])
            if sec % F[i] > 0:
                vol += 1
            dp[x] = vol*F[i] + C[i]
for i in range(1, N):
    print(dp[i])
print(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, s, f = csf[j]
        t = max(s, ((t + f - 1) // f) * f) + c
    print(t)

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

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

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

C_list = []
S_list = []
F_list = []

for _ in range(N-1):
    c, s, f = map(int, input().split())
    C_list.append(c)
    S_list.append(s)
    F_list.append(f)

def next_station(t, c, s, f):
    if t >= s:
        if t % f == 0:
            return t + c
        else:
            return f*(t // f + 1) + c
    else:
        return s + c
    
for i in range(N):
    t = 0
    for j in range(i, N-1):
        t = next_station(t, C_list[j], S_list[j], F_list[j])
    print(t)

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

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
cs = []
ss = []
fs = []
for i in range(n-1):
    c, s, f = na()
    cs.append(c)
    ss.append(s)
    fs.append(f)

for i in range(n):
    t = 0
    for j in range(i, n-1):
        if t <= ss[j]:
            t = ss[j]
        else:
            t = (t + fs[j] - 1) // fs[j] * fs[j]
        t += cs[j]
    print(t)