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):
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()

sum_time=0
query = []
for i in range(N-1):
    query.append(many_int())

for i in range(N-1):
    C,S,F=query[i]
    sum_time = C+S

    for j in range(i+1,N-1):
        
        C, S, F =query[j]
        sum_time = max(S, sum_time)
        temp = (sum_time-S)/F
        if temp.is_integer():
            pass
        else:
            temp = int((sum_time-S)//F + 1)
            sum_time = S +temp * F
        sum_time += C
    print(int(sum_time))
print(0)

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

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

for i in range(N-1):
    ci,si,fi=map(int, input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)

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

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

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


for i in range(n-1):
    time = 0
    for j in range(i, n-1):
        if i == j:
            time += (train_list[i][0] + train_list[i][1])
        else:
            if train_list[j][1] // time >= 1:
                time = train_list[j][1]
                time += train_list[j][0]
            else:
                p = math.ceil((time - train_list[j][1])/train_list[j][2])
                time = train_list[j][1] + train_list[j][2] * p
                time += train_list[j][0]
    print(time)

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

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

for st in range(N):
    t = 0
    for i in range(st, N-1):
        C, S, F = CSF[i]
        k = max(0, (t-S + F-1)//F)
        t = S+F*k+C
    print(t)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    CSF=LLIN(N-1)
    def solve(CSF):
        now = 0
        for i,(c,s,f) in enumerate(CSF):
            if now <= s: 
                now = s + c
                continue
            else:
                if now%f != 0:
                    now += f - now%f
                now += c
        print(now)
    
    for i in range(N):
        solve(CSF[i:])


if __name__ == '__main__':
    main()

Solution (Python):
import math


def main():
    N = int(input())
    CSF = [[int(x) for x in input().split()] for _ in range(N-1)]
    tt = []

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

        tt.append(t)

    tt.append(0)
    for t in tt:
        print(t)


main()

Solution (Python):

import math

N = int(input())


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

for i in range(1,N):
    C,S,F = map(int, input().split())
    C_list.append(C)
    S_list.append(S)
    F_list.append(F)
    




def get_next_station_arrival_time(now_station_number,now_time):
    
    if now_station_number == N:
        return now_time
    
    
    C = C_list[now_station_number]
    S = S_list[now_station_number]
    F = F_list[now_station_number]
    
    
    
    if now_time <= S:
        return get_next_station_arrival_time(now_station_number + 1, S + C)
    else:
        n = math.ceil((now_time - S)/F) 
        return get_next_station_arrival_time(now_station_number + 1, F*n + S + C)
    

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

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from math import ceil
def resolve():
    n=int(input())
    CSF=[tuple(map(int,input().split())) for _ in range(n-1)]
    for i in range(n-1):
        now=0
        for j in range(i,n-1):
            c,s,f=CSF[j]
            now=f*ceil(max(s,now)/f)+c
        print(now)
    print(0)
resolve()

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

l = [[int(i) for i in input().split(" ")] for _ in range(1, n)]


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

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())

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

for i in range(1,n):
    c[i],s[i],f[i] = [int(x) for x in stdin.readline().rstrip().split()]

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

Solution (Python):
from sys import stdin
from itertools import combinations
from math import factorial
import numpy as np
import math
import bisect

n = int(stdin.readline().rstrip())

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

for i in range(1,n):
    c[i],s[i],f[i] = [int(x) for x in stdin.readline().rstrip().split()]

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

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

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

Solution (Python):
H=int(input())-1
K = [list(map(int, input().split())) for i in range(H)]
total_total=[]
for j in range(H):
    total=K[j][0]+K[j][1]
    for i in range(j,H-1):
        c1=K[i][0]
        s1=K[i][1]
        f1=K[i][2]
        c2=K[i+1][0]
        s2=K[i+1][1]
        f2=K[i+1][2]
        if total>s2:
            if (total-s2)%f2==0:
                total=total+c2
            else:
                total=((total-s2)//f2+1)*f2+s2+c2
        else:
            total=s2+c2
    print(total)
print(0)

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

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

for _ in range(n-1):
    ce,se,fe = map(int, input().split())
    c.append(ce)
    s.append(se)
    f.append(fe)

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

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

for i in range(n-1):
  syoki=hyou[i][0]+hyou[i][1]
  for j in range(i+1,n-1):
    temp=hyou[j][1]
    if temp<syoki:
      syoki=temp+math.ceil((syoki-temp)/hyou[j][2])*hyou[j][2]+hyou[j][0]
    else:
      syoki=temp+hyou[j][0]
  print(syoki)
print(0)

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

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

    time += csf[i][0]  
  print(time)

Solution (Python):
def examC():
    N = I()
    C = [0]*N; S =[0]*N; F = [0]*N
    for i in range(N-1):
        C[i], S[i], F[i] = LI()
    ans = []
    for i in range(N):
        cur = 0
        for j in range(i,N-1):
            cur = max(((cur-1)//F[j] +1)*F[j],S[j])+C[j]
        ans.append(cur)
    for v in ans:
        print(v)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()

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


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

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

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

print(0)

Solution (Python):
N = int(input())
X = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    X.append((c, s, f))
for k in range(N):
    t = 0
    for i in range(k, N-1):
        c, s, f = X[i]
        t = -(-t//f) * f
        t = max(t, s)
        t += c
    print(t)

Solution (Python):
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
    all_time = 0
    for c, s, f in CSF[i:]:
        if all_time < s:
            all_time = s
        if all_time % f != 0:
            all_time += f - (all_time % f)
        all_time += c
    print(all_time)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys,bisect,math,itertools,string,queue,copy
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])
def sortx(x,n,k):
    if k == 0:x.sort(key=lambda y:y[1,n])
    else:x.sort(reversed=True, key=lambda y:y[1,n])
def graph():
    n,m=inpm()
    g=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b=inpm()
        a-=1
        b-=1
        g[a].append(b)
        
    return n,m,g

def main():
    n=inp()
    ans=[]
    csf=[]
    for _ in range(n-1):
        c,s,f=inpm()
        ans.append(s)
        csf.append([c,s,f])
    csf.append([0,0,0])
    ans.append(0)
    for i in range(n-1):
        for j in range(i+1):
            if ans[j]>=csf[i][1] and ans[j]%csf[i][2]==0:
                ans[j]+=csf[i][0]
            elif ans[j]>=csf[i][1]:
                x=ans[j]%csf[i][2]
                ans[j]+=csf[i][2]-x
                ans[j]+=csf[i][0]
            else:
                ans[j]=csf[i][0]+csf[i][1]
    print(*ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
import math

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

for i in range(n):
    time = l[i][0] + l[i][1]

    for j in range(i + 1, n):
        if time <= l[j][1]:
            time = l[j][1]
        elif time % l[j][2] != 0:
            time = int(math.ceil(time / l[j][2]) * l[j][2])
        
        time += l[j][0]
    
    print(time)

print(0)

Solution (Python):
import math

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

for i in range(n):
    time = l[i][0] + l[i][1]

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

print(0)

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

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

for i in range(N-1):
	ans = 0

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

	print(ans)

print(0)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    ans = [0] * n
    csf = []
    for _ in range(n - 1):
        c, s, f = map(int, input().split())
        csf.append([c, s, f])
    for i in range(n - 1):
        elapsed = csf[i][0] + csf[i][1]
        for j in range(i + 1, n - 1):
            c, s, f = csf[j]
            if elapsed <= s:
                elapsed = s
            else:
                elapsed += -elapsed % f
            elapsed += c
        ans[i] = elapsed
    print(*ans, sep="\n")

main()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    ans = [0] * n
    csf = []
    for _ in range(n - 1):
        c, s, f = map(int, input().split())
        csf.append([c, s, f])
    ps = 0
    pf = 1
    for i in range(n - 1):
        elapsed = csf[i][0] + csf[i][1]
        for j in range(i + 1, n - 1):
            c, s, f = csf[j]
            if elapsed <= s:
                elapsed = s
            else:
                elapsed += -elapsed % f
            elapsed += c
        ans[i] = elapsed
    print(*ans, sep="\n")

main()

Solution (Python):
import sys
import collections


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    csf = []
    for i in range(n-1):
        c, s, f = list(map(int, readline().split()))
        csf.append([c, s, f])
    ql = []
    for i in range(n):
        ql.append([0, i, i])
    ql = collections.deque(ql)
    ans = []
    while True:
        if len(ql) != 0:
            time, pos, start = ql.popleft()
            if pos == n - 1:
                ans.append([time, pos, start])
            else:
                c, s, f = csf[pos]
                if s >= time:
                    ql.append([s + c, pos + 1, start])
                else:
                    if time% f == 0:
                        ql.append([time + c, pos + 1, start])
                    else:
                        ql.append([time + (f - time % f) + c, pos + 1, start])
        else:
            break
    ans.sort(key=lambda x: x[2])
    for i in range(len(ans)):
        print(ans[i][0])


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input().strip())
C = [0] * (N - 1)
ans = [0] * (N)
for n in range(N-1):
    C, S, F = [int(x) for x in input().strip().split()]
    ans[n] = S + C
    for i in range(n):
        if ans[i] <= S:
            ans[i] = S + C
        elif ans[i] % F == 0:
            ans[i] += C
        else:
            ans[i] = (ans[i] // F + 1) * F + C

for a in ans:
    print(a)

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

Solution (Python):
N = int(input())
a = N*[0]

for i in range(1,N):
    C,S,F = map(int,input().split())
    for j in range(i):
        a[j] = max(S,((F+a[j]-1)//F)*F)+C

print(*a,sep="\n")

Solution (Python):
n = int(input())
time = 0
d = [list(map(int, input().split())) for i in range(n-1)]
for i in range(n-1):
    j = i
    time = 0
    while j < n-1:
        m = -((-max(0, time-d[j][1]))//d[j][2])
        time = d[j][1] + d[j][2]*m + d[j][0]
        j += 1
    print(time)
print(0)

Solution (Python):
import math

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

for _ in range(N - 1):
	c, s, f = map(int, input().split())
	C.append(c)
	S.append(s)
	F.append(f)
	
S.append(0)
C.append(0)
F.append(1)
	
for i in range(N):
	time = S[i] + C[i] 
	for j in range(i + 1, N):
		if time > S[j]:
			time = F[j] * (math.ceil(time / F[j])) 
		else:
			time = S[j] 
		time += C[j] 
	print(time)

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

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

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

Solution (Python):
import sys








def main():
    n = int(sys.stdin.readline().rstrip())
    c, s, f = [], [], []
    for i in range(n-1):
        ci, si, fi = (int(x) for x in sys.stdin.readline().split())
        c.append(ci); s.append(si); f.append(fi)
    
    x = []
    for i in range(n-1):
        xi = 0
        for j in range(i, n-1):
            if s[j] >= xi: 
                xi = s[j]
                xi += c[j]
            else:
                if (xi - s[j]) % f[j] == 0:
                    xi += c[j]
                else:
                    xi += c[j] + f[j] - (xi - s[j]) % f[j]
        x.append(xi)
    x.append(0)
    for xi in x:
        print(xi)

if __name__ == "__main__":
    
    main()

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

result = []
for i in range(n):
  time = 0
  for req, start, interval in list_train[i:]:
    if time < start:
      time = start + req
    else:
      while (time - start) % interval != 0:
        time += 1
      time += req
  result.append(time)
for one_res in result:
  print(one_res)

Solution (Python):
from math import ceil

N = int(input())
stas = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(N-1):
  t = stas[i][0] + stas[i][1]
  for j in range(i+1,N-1):
    if t <= stas[j][1]:
      t = stas[j][0] + stas[j][1]
    else:
      n = ceil((t-stas[j][1])/stas[j][2])
      t = stas[j][0] + stas[j][1] + stas[j][2]*n
    
  print(t)
print(0)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 18
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
R = []
D = []
interval = []
for _ in range(n - 1):
    c, s, f = LI()
    R += [c]
    D += [s]
    interval += [f]


for start in range(n - 1):
    t = 0
    for j in range(start, n - 1):
        d, r, f = D[j], R[j], interval[j]
        if t <= D[j]:
            t = D[j] + R[j]
        else:
            t = D[j] + (t - D[j]) // interval[j] * interval[j] + bool((t - D[j]) % interval[j]) * interval[j] + R[j]
    print(t)
print(0)

Solution (Python):
N=int(input())
C=list()
S=list()
F=list()
for i in range(N-1):
    a,b,c=map(int,input().split())
    C.append(a)
    S.append(b)
    F.append(c)

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

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

for i in range(n-1):
    ans = 0
    for j in range(i,n-1):
       c,s,f = csf[j]
       ans = max(s,ans+abs(ans%-f))
       ans += c
    print(ans)
print(0)

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

    r = []
    for i, ai in enumerate(A):
        c, s, f = ai
        
        x = s + c
        for ci, si, fi in A[i+1:]:
            
            if x < si:
                x = si
            while x % fi != 0:
                x += 1
            x += ci
        r.append(x)
        x = 0
    r.append(0)

    
    for ri in r:
        print(ri)


if __name__ == "__main__":
    main()

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

lians = [0]*n
for i in range(n-1):
  lians[i] += lidata[i][1]
  for j in range(i):
    if lians[j] <= lidata[i][1]:
      lians[j] = lidata[i][1]
    elif lians[j]%lidata[i][2] != 0:
      lians[j] += lidata[i][2] - lians[j]%lidata[i][2]
  lians = list(map(lambda x:x+lidata[i][0],lians[:i+1])) + lians[i+1:]

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

Solution (Python):
n=int(input())
csf=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n-1):
    time=0
    for j in range(i,n-1):
        c,s,f=csf[j]
        if time<s:
            time=s+c
        else:
            if time%f==0:
                time+=c
            else:
                time=(time//f+1)*f+c
    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):
    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())
l=[]
for i in range(n-1):
    l.append([int(i) for i in input().split()])
ans=[]
i=0 
while i<n-1:
    time=l[i][1]
    cost=0 
    j=i 
    while j<n-1: 
        karma=((max(time,l[j][1]))-(l[j][1]))%l[j][2]
        if karma:
            karma=l[j][2]-karma 
        start=max(time,l[j][1])+karma 
        time=start+l[j][0]
        j+=1 
    i+=1 
    print(time)
print(0)

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

def ceil(x, y):
  return (x -1) // y + 1

for i in range(N - 1):
  n = 0  
  for j in range(i, N - 1):
    c, s, f = CSF[j]
    if n <= s:
      n = s
    n = s + ceil(n - s, f) * f + c
  print(n)
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] = list(map(int, input().split()))


def calcTime(start, time):

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

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

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

Solution (Python):

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

for i in range(n):
    if i == n-1:
        print(0)
    else:
        ela = 0

        for j in range(i, n-1):
            if j == i:
                
                ela += cond[j][1]
            elif j != i:
                
                if ela <= cond[j][1]:
                    ela = cond[j][1]
                elif ela > cond[j][1]:
                    k = cond[j][2]
                    if ela%k == 0:
                        pass
                    else:
                        ela = ela + (k-(ela%k))               
            
            ela += cond[j][0]
        print(ela)

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

Solution (Python):

import sys
import math


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    for i in range(N-1): 
        t = 0
        for j in range(i,N-1):
            if t > S[j]:
                t = (S[j]+(math.ceil((t-S[j])/F[j]))*F[j]) + C[j]
            else:
                t = S[j] + C[j]
        print(t)
    print(0)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    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):


def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

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

    for i in range(n - 1):
        time = 0
        for j in range(i, n - 1):
            times_j = times[j]
            if times_j[1] > time:
                time = times_j[1] + times_j[0]
            else:
                time = times_j[1] + ((time - times_j[1] + times_j[2] - 1) // times_j[2]) * times_j[2] + times_j[0]
        print(time)
    print(0)


if __name__ == '__main__':
    main()

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

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

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

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

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

Solution (Python):
N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N-1)]

ans = [0]*N
for i in range(N-1):
    t = L[i][1]+L[i][0]
    for j in range(i+1, N-1):
        if L[j][1] >= t:
            t = L[j][1]+L[j][0]
        else:
            t = ((t-L[j][1])//L[j][2]+min(1, (t-L[j][1])%L[j][2]))*L[j][2]+L[j][0]+L[j][1]
    ans[i] = t
    
for i in range(N):
    print(ans[i])