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
S = [0] * N
F = [0] * (N - 1)
F.append(1)

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

for i in range(N):
    time = S[i]
    for j in range(i, N):
        time = max((F[j] - (time - S[j])) % F[j] + time, S[j]) + C[j]
    print(time)

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

for j in range(N):
    t = 0
    for i in range(j,N-1):
        C,S,F = CSF[i]
        if t >= S:
            if t%F == 0:
                t += C
            else:
                t = (1+t//F)*F + C
        else:
            t = S+C
    T.append(t)
print(*T, sep="\n")

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

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

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

Solution (Python):
import math
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())

times = [0]*N
for j in range(N-1):
    time = 0
    for i in range(j, N-1):
        if time <= S[i]:
            time = S[i]
        else:
            time = math.ceil(time / F[i]) * F[i]
        time += C[i]

    times[j] = time
for i in range(N):
    print(times[i])

Solution (Python):
import math

N = int(input())
plan = [tuple(map(int, input().split())) for _ in range(N-1)] + \
    [(0, 0, 0)]

ans = []
for i in range(N):
    time = 0
    for j in range(i+1, N):
        c, s, f = plan[j-1]
        next_c, next_s, next_f = plan[j]
        if time <= s:
            time = c + s
        else:
            if (time - s) % f == 0:
                time += c
            else:
                time += c + (f - (time - s) % f)
    ans.append(time)


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

Solution (Python):
"""
シミュレーション問題
- 数式にこだわりすぎた
- WAになって何が間違っているかはわからなかった
- Nの範囲を確認すればO(N^2)でも十分問題なかったことが分かったので素直に実装すればよかった
"""
n = int(input())
setting = []
for _ in range(n-1):
    setting.append(tuple(map(int, input().split())))

results = []
for i in range(n-1):
    cur = 0
    for c, s, f in setting[i:]:
        if cur < s:
            cur = c + s
        elif 0 == cur % f:
            cur += c
        else:
            cur += c + f - cur % f
    results.append(cur)
results.append(0)
for result in results:
    print(result)

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

results = []
for i in range(n-1):
    cur = 0
    for j in range(i, n-1):
        if cur < setting[j][1]:
            cur = setting[j][0] + setting[j][1]
        elif 0 == cur % setting[j][2]:
            cur += setting[j][0]
        else:
            cur += setting[j][0] + setting[j][2] - cur % setting[j][2]
    results.append(cur)
results.append(0)
for result in results:
    print(result)

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

from math import ceil

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

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

CSF = [[int(i) for i in input().split()] for _ in range(N-1)]
for i in range(N-1) :
    x = 0
    for j in range(i, N-1) :
        C, S, F = CSF[j]
        if x < S :
            x = S + C
        else :
            x = S + F * ((x - S + F - 1) // F) + C
    print(x)
print(0)

Solution (Python):
N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(N-1):
    for j in range(i, N-1):
        if j == i:
            ans = CSF[j][1]+CSF[j][0]
        else:
            if ans < CSF[j][1]:
                ans = CSF[j][1] + CSF[j][0]
            else:
                if ans % CSF[j][2] == 0:
                    ans = (ans // CSF[j][2]) * CSF[j][2]
                else:
                    ans = (ans // CSF[j][2] + 1) * CSF[j][2]
                ans += CSF[j][0]
    print(ans)
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 h in range(n):
    now=0
    for i in range(h,n-1):
        if(now <= s[i]):
            now = s[i]+c[i]
        else:
            now =  s[i] + (-(-(now-s[i])//f[i]))*f[i] + c[i]

    print(now)

Solution (Python):
import sys
import math
from fractions import gcd





def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""


 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())


 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


N =  int(sys.stdin.readline())
L =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N - 1)]

for i in range(N - 1):
    start = L[i]
    cnt = start[0] + start[1]
    for j in range(i + 1, N - 1):
        next = L[j]
        
        if cnt < next[1]:
            cnt = next[1]
        else:
            
            x = next[1]
            while True:
                if x >= cnt:
                    
                    break
                x += next[2]
            cnt += (x - cnt)
        cnt += next[0]
    print(cnt)

print(0)

Solution (Python):

import sys


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    ans = [0]*(N)
    for k in range(N-1):
        cst = S[k]+C[k]
        for i in range(k+1,N-1):
            if(cst < S[i]):
                cst = max(cst, S[i])
            elif(cst%F[i] == 0):
                cst = cst
            else:
                cst = cst + F[i] - (cst%F[i])
            cst += C[i]
        ans[k] = cst

    for i in ans:
        print(i)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    global N, C, S, F
    N = int(next(tokens))  
    C = [int()] * (N-1)  
    S = [int()] * (N-1)  
    F = [int()] * (N-1)  
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

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

def main():
    N = int(input())
    csf = [list(map(int, input().split())) for i in range(N-1)]
    for start in range(N):
        now = 0
        for i in range(start, N-1):
            c, s, f = csf[i]
            if now <= s:
                now = s
            else:
                if now%f != 0:
                    now += f - now % f
            
            now += c
            
        print(now)

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
C = []
S = []
F = []

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

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

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

res = [0]*N
for i in range(N-1):
    t = 0
    for j in range(i,N-1):
        c = CSF[j][0]
        s = CSF[j][1]
        f = CSF[j][2]
        if t <= s:
            t = s+c
        else:
            if t%f == 0:
                t += c
            else:
                m = t%f
                t += ((f-m)+c)
    res[i] = t
print("\n".join(map(str,res)))

Solution (Python):
def main():
    N = int(input())
    csfs = [[int(i) for i in input().split()] for j in range(N-1)] + [[-1,0,0]]

    for i in range(N):
        state = i
        time = csfs[state][1]
        while state < N-1:
            if time % csfs[state][2] == 0 and csfs[state][1] <= time:
                time += csfs[state][0]
                state += 1
            else:
                time += (csfs[state][2] - time%csfs[state][2])
                if csfs[state][1] > time:
                    time = csfs[state][1]
        print(time)
if __name__ == '__main__':
    main()

Solution (Python):
n,*t=map(int,open(0).read().split())
for i in range(n):
 a=0
 for c,s,f in zip(t[3*i::3],t[3*i+1::3],t[3*i+2::3]):a=max(s,a//-f*-f)+c
 print(a)

Solution (Python):
import sys

input = sys.stdin.readline

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

res = []
for i in range(n):
    t = 0
    for j in range(i, n - 1):
        s = ss[j]
        f = fs[j]
        if t < s:
            t = s
        elif t % f > 0:
            t += f - t % f
        t += cs[j]
    res.append(t)
for x in res:
    print(x)

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

res = []
for i in range(n):
    t = 0
    for j in range(i, n - 1):
        s = ss[j]
        f = fs[j]
        if t < s:
            t = s
        elif t % f > 0:
            t += f - t % f
        t += cs[j]
    res.append(t)
for x in res:
    print(x)

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

res = []
for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        s = ss[j]
        f = fs[j]
        if t < s:
            t = s
        elif t % f > 0:
            t += f - t % f
        t += cs[j]
    res.append(t)
res.append(0)
for x in res:
    print(x)

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

res = []
for i in range(n - 1):
    arrives = [0]
    lefts = [ss[i]]
    for j in range(i, n - 1):
        a = lefts[-1] + cs[j]
        arrives.append(a)
        ns = ss[j + 1]
        if a > ss[j + 1]:
            nf = fs[j + 1]
            w = (nf - (a - ns) % nf) % nf
            lefts.append(a + w)
        else:
            lefts.append(ns)
    res.append(arrives[-1])
res.append(0)
for x in res:
    print(x)

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

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

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))




def min_mult(x,y):
    if x%y==0:
        return x
    else:
        return x + (y-x%y)

N = I()
C,S,F = Line(N-1)

ans = []

for i in range(N-1):
    temp = S[i]+C[i]
    for j in range(i+1,N-1):
        temp = min_mult(max(temp,S[j]),F[j]) + C[j]
    ans.append(temp)

ans.append(0)
for i in range(N):
    print(ans[i])

Solution (Python):
import sys
from statistics import *
from collections import *
from operator import itemgetter

stdin = sys.stdin

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

n = ni()
li = [[0, 0, 0]]
for i in range(1, n):
    li.append(na())
for i in range(1, n):
    t = 0
    for j in range(i, n):
        c, s, f = li[j]
        if t < s:
            t = s
        else:
            for k in range(t, t+f+1):
                if k % f == 0:
                    t = k
                    break
        t += c
    print(t)
print(0)

Solution (Python):


import math

N = int(input().split()[0])
csf_list = []

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

x_list = []
total_c_list = []

for start_i in range(N-1):  
    total_c = csf_list[start_i][0] + csf_list[start_i][1]

    for csf in csf_list[start_i+1:]:  
        c, s, f = csf
        total_c = s if total_c < s else total_c
        i = math.ceil((total_c - s) / f)
        total_c = s + f * i + c
    total_c_list.append(str(total_c))

ans = '\n'.join(total_c_list + ['0'])
print(ans)

Solution (Python):
N = int(input())
CSF = []
for i in range(0, N-1):
    CSF.append(list(map(int, input().split())))
for i in range(0, N):
    ans = 0
    for j in range(i, N-1):
        ans = max(CSF[j][1], ans)
        if ans % CSF[j][2] != 0:
            ans += (CSF[j][2]-ans % CSF[j][2])
        ans += CSF[j][0]
    print(ans)

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

CSF = []

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

CSF.append([0, 0, 1])

ans = [0] * N

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



for i in ans:
    print(i)

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

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

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    for i in range(N):
        cur = 0
        for c, s, f in A[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c  
        print(cur)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
t = 0
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(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)
print(0)

Solution (Python):
import math

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)]
A = [0 for 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-1)[::-1]:
  ans = S[i] + C[i]
  for j in range(i, N-2):
    if ans <= S[j+1]:
      ans = A[j+1]
      break
    else:
      ans = math.ceil(ans / F[j+1]) * F[j+1] + C[j+1]
  A[i] = ans
  
for i in range(N):
  print(A[i])

Solution (Python):
N = int(input())
CSFs = []
for i in range(N-1):
  C, S, F = map(int, input().split())
  CSFs.append((C, S, F))
for i in range(N):
  r = 0
  L = CSFs[i:]
  for C, S, F in L:
    if r < S:
      r = S
    else:
      r = (r-S +F-1)//F*F+S
    r += C
  print(r)

Solution (Python):

N = int(input())

CSF = []

for i in range(N-1):

    C,S,F = map(int,input().split())

    CSF.append([C,S,F])


for i in range(N):


    time = 0

    for j in range(N-1-i):

        j += i

        c = CSF[j][0]
        s = CSF[j][1]
        f = CSF[j][2]

        if time < s:

            time = s + c

        elif time % f == 0:

            time += c

        else:

            time = (time // f + 1) * f + c

    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-1):
    time = 0
    for j in range(i, n-1):
        if  time < s[j]:
            time = s[j]
        elif time % f[j] == 0:
            pass
        else:
            time += f[j] - (time % f[j])
        time += c[j]
    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_)

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:
            pass
        else:
            time += f[j] - (time % f[j])
        time += c[j]
    print(time)
print(0)

Solution (Python):
import math
def main():
    N = int(input())
    info = []
    for _ in range(N-1):
        C, S, F = map(int, input().split())
        info.append([C, S, F])
    for i in range(N-1):
        t = info[i][1] + info[i][0]
        j = i+1
        while j < N-1:
            if t <= info[j][1]:
                t = info[j][1] + info[j][0]
            else:
                k = math.ceil((t-info[j][1])/info[j][2])
                t = k * info[j][2] + info[j][1] + info[j][0]
            j += 1
        print(t)
    print(0)

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
l = [list(map(int, input().split())) for i in range(N-1)]
for i in range(N):
    t=0
    for j in range(i,N-1):
        if t>l[j][1]:
            while 1:
                if t%l[j][2]==0:
                    break
                else:
                    t+=1
            t+=l[j][0]
        else:
            t=l[j][1]+l[j][0]
    print(t)

Solution (Python):
N=int(input())
l = [list(map(int, input().split())) for i in range(N-1)]
for i in range(N):
    t=0
    for j in range(i,N-1):
        if t>l[j][1]:
            while 1:
                if t%l[j][2]==0:
                    break
                else:
                    t+=1
            t+=l[j][0]
        else:
            t=l[j][1]+l[j][0]
    print(t)

Solution (Python):
n=int(input())
a=[0]*n
x=[]
y=[]
z=[]
for i in range(n-1):
	p,pp,ppp=map(int,input().split())
	x.append(p)
	y.append(pp)
	z.append(ppp)
for i in range(n-2):
	ans=y[i]+x[i]
	for j in range(n-i-2):
		if ans<y[j+1+i]:
			ans=y[j+1+i]
		if (ans-y[j+1+i])%z[j+1+i]!=0:
			ans+=z[j+1+i]-((ans-y[j+1+i])%z[j+1+i])
		ans+=x[j+1+i]
	print(ans)
print(y[-1]+x[-1])
print(0)

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

for i in range(n-1):
    cnt = i
    now = 0
    tmp = 0
    while cnt <= n-2:
        if cnt == n-2:
            if now == 0:
                tmp += csf[cnt][0] + csf[cnt][1]
                print(tmp)
                cnt += 1
                now += 1
            else:
                tmp += max((tmp + csf[cnt][2] - 1) // csf[cnt][2] * csf[cnt][2],csf[cnt][1]) - tmp + csf[cnt][0]
                cnt += 1
                print(tmp)
        elif now == 0:
            tmp += csf[cnt][0] + csf[cnt][1]
            cnt += 1
            now += 1
        else:
            tmp += max((tmp + csf[cnt][2] - 1) // csf[cnt][2] * csf[cnt][2],csf[cnt][1]) - tmp + csf[cnt][0]
            cnt += 1
            
    
    
print(0)

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

  ans = []
  for i in range(n-1):
    time = 0
    for j in range(i,n-1):
      c,s,f = query[j]
      time = max(s,time)
      if not time%f == 0:
        time += f-time%f
      time += c
    ans.append(time)
  for i in ans:
    print(i)
  print(0)
solve()

Solution (Python):
import math
N = int(input())
lst = [list(map(int, input().split())) for i in range(N-1)]
ans = []
for i in range(N-1):
  t = lst[i][0] + lst[i][1]
  for j in range(i+1, N-1):
    if (t >= lst[j][1]):
      if (t % lst[j][2] == 0):
        t += lst[j][0]
      else:
        n = math.ceil((t - lst[j][1]) / lst[j][2])
        t = lst[j][1] + lst[j][2] * n + lst[j][0]
    else:
      t = lst[j][1] + lst[j][0]
  ans.append(t)
ans.append(0)

for i in ans:
  print(i)

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

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

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

if N >= 2:
    for i in range(N-1):
        ans = 0
        for j in range(i, N-1):
            c, s, f = csf[j]
            if ans < s:
                ans = s + c
            else:
                if ans % f == 0:
                    ans += c
                else:
                    ans += f - ans % f + c
        print(ans)
print(0)

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

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

ans = [0] * N

for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        if j == i:
            now = CSF[j][1] + CSF[j][0]
        else:
            if now <= CSF[j][1]:
                now = CSF[j][1] + CSF[j][0]
            else:
                if (now - CSF[j][1]) % CSF[j][2] == 0: 
                    now += CSF[j][0]
                else:
                    wait = CSF[j][2] - ((now - CSF[j][1]) % CSF[j][2])
                    now += wait + CSF[j][0]
                    
    ans[i] = now
    


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

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())

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

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

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

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

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

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

for i in range(N):
    total=0
    for k in range(i,N):
        if k==i:
            total+=A[k][0]+A[k][1]
        else:
            if A[k][1]>total:
                total=A[k][1]
            if total%A[k][2]!=0:
                total=total+A[k][2]-total%A[k][2] 
            total+=A[k][0]
    print(total)
print(0)

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

ans = [(0, i) for i in range(N)]
for i in range(N - 1):
    for j in range(N - i - 1):
        Cj, Sj, Fj = CSF[ans[j][1]]
        if ans[j][0] <= Sj:
            ans[j] = (Sj + Cj, ans[j][1] + 1)
        elif ans[j][0] % Fj == 0:
            ans[j] = (ans[j][0] + Cj, ans[j][1] + 1)
        else:
            ans[j] = (ans[j][0] + Fj - (ans[j][0] % Fj) + Cj, ans[j][1] + 1)

for a in ans:
    print(a[0])

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

for i in range(n-1): 
    c,s,f = csf[i]
    s += c
    
    for j in range(i+1,n-1): 
        c1,s1,f1 = csf[j]
        s = ((math.ceil((s-s1)/f1))*f1 if s >= s1 else 0)+s1+c1
        
    print(s)
print(0)

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

eki = []
for i in range(N - 1):
    eki.append([int(_) for _ in input().split()])

for i in range(N - 1):
    s = eki[i][0] + eki[i][1]
    for j in range(i + 1, N - 1):
        tmp = s - eki[j][1]
        if tmp < 0:
            s = eki[j][1]
        elif tmp % eki[j][2] != 0:
            s += eki[j][2] - (tmp % eki[j][2])
        s += eki[j][0]

    print(s)
print(0)

Solution (Python):
import math
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 j in range(N-1):
    ans = 0
    for i in range(j, N-1):
        tmp = math.ceil(ans/F[i]) * F[i]
        tmp2 = max(tmp, S[i])
        ans = tmp2
        ans += C[i]

    print(ans)
print(0)

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

for start in range(0, N):
    now = 0
    for c, s, f in trains[start:]:
        if now < s:
            now = s
        now += (f - now % f) % f
        now += c
    print(now)

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

for i in range(n):
    ans = 0
    while i<=n-2:        
        c = csf[i][0]
        s = csf[i][1]
        f = csf[i][2]
        ans = max(s,math.ceil(ans/f)*f)+c
        i+=1
    print(ans)

Solution (Python):


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

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

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

Solution (Python):
import math
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
    if i == N - 1:
        print(0)
        exit()
    
    
    for j in range(i, N-1):
        
        
        k_tmp = math.ceil((t - S[j])/F[j])
        k = max(0,k_tmp)

        t = S[j] + F[j] * k + C[j]
    
    print(t)

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

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



print(0)

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

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


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

Solution (Python):
n = int(input())
csf = []
for _ 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):
    c,s,f = csf[j]
    start = max(time,s)
    START = ((start-1)//f+1)*f
    time = START + c
  print(time)
print(0)

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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


def solve(from_i):
    t = 0
    for c, s, f in CSF[from_i:]:
        t = max(s, math.ceil(t / f) * f) + c
    return t


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

Solution (Python):
import math
N = int(input())
table = [list(map(int,input().split())) for i in range(N-1)]
for i in range(1,N+1):
    time = 0
    for j in range(i,N):
        if time < table[j-1][1]:
            time = table[j-1][1]+table[j-1][0]
        else:
            time = math.ceil((time-table[j-1][1])/table[j-1][2])*table[j-1][2]+table[j-1][1]+table[j-1][0]
    print(time)

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







rev_res = []
for ix, st_i in enumerate(status_lst):
    elapsed = st_i[1] + st_i[0]
    for next_st in range(ix+1, N-1):
        st_n = status_lst[next_st]
        if elapsed < st_n[1]:
            elapsed = st_n[1] + st_n[0]
        else:
            wait_time = elapsed % st_n[2]
            if wait_time == 0:
                elapsed = elapsed + st_n[0]
                
                
            elif wait_time == elapsed:
                
                
                elapsed = st_n[2] + st_n[0]
            else:
                elapsed = elapsed + st_n[2] - wait_time + st_n[0]

    rev_res.append(elapsed)

rev_res.append(0)

for ans in rev_res:
    print(ans)