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 baisu(a,b):
  if a%b==0:
    return a
  else:
    return ((a//b)+1)*b
C=list()
S=list()
F=list()
N=int(input())
for i in range(N-1):
  c,s,f=map(int,input().split())
  C.append(c)
  S.append(s)
  F.append(f)
L = [[0 for j in range(N)] for i in range(N)]
for i in range(N-1):
  L[i][i]=S[i]
  for j in range(i+1,N):
    L[i][j]=baisu(max(L[i][j-1],S[j-1]),F[j-1])+C[j-1]
  print(L[i][-1])
print(0)

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

Solution (Python):
N = int(input())
l = []
for i in range(N-1):
  c, s, f = map(int, input().split())
  l.append([c, s, f])
  
for i in range(N-1):
  time = l[i][1] + l[i][0]
  for j in range(i+1, N-1):
    if time-l[j][1] >= 0:
      wait = time % l[j][2]
      if wait == 0:
        time += l[j][0]
      else:
        time += l[j][2] - wait + l[j][0]
    else:
      time = l[j][1] + l[j][0]
  print(time)
print(0)

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def cc(al):
	ret = 0
	for (c, s, f) in al:
		if ret <= s:
			ret = s+c
		else:
			st = ((ret + f-1)//f)*f
			ret = st + c
	print(ret)
		

def main():
	n = int(input())
	
	
	
	
	al = [lin() for _ in range(n-1)]
	for i in range(n):
		cc(al[i:])
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

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


for i in range(n):
  s=0
  for j in range(i,n-1):
    s=max(t[j][1],((s-1)//t[j][2]+1)*t[j][2])+t[j][0]
  print(s)

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
ls = []
for i in range(n-1):
    c, s, f = MAP()
    ls.append([c, s, f])
for i in range(n-1):
    ans = 0
    for j in range(i, n-1):
        ans = max(ans, ls[j][1])
        ans = ls[j][0] + ( ans + ls[j][2] - 1 )// ls[j][2] * ls[j][2]
    print(ans)
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 f(n, s, f):
    if n <= s:
        return s
    if n % f == 0:
        return n
    else:
        return n // f * f + f

for i in range(n-1):
    now = S[i] + C[i]
    for j in range(i+1, n-1):
        now = f(now, S[j], F[j]) + C[j]
    print(now)
print(0)

Solution (Python):
import sys

N = int(sys.stdin.readline())

stations = []
for _ in range(N-1):
    c, s, f = map(int, sys.stdin.readline().split())
    stations.append((c, s, f))

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

    print(t)
print(0)

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


for station_index in range(N - 1):
    ans = 0
    for j in range(station_index, N - 1):
        cost, start, f = trains[j]
        if ans < start:
            ans = start + cost
        elif ans == start:
            ans += cost
        else:
            if (ans - start) % f == 0:
                ans += cost
            else:
                ans += (f - (ans - start) % f) + cost
    print(ans)
print(0)

Solution (Python):
from math import ceil
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=s[i]+c[i]
  if i<n-1:
    for j in range(i+1,n-1):
      if s[j]>=t:
        t=s[j]+c[j]
      else:
        t=ceil(t/f[j])*f[j]+c[j]
  print(t)

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

for j in range(0,N,1):
    t = 0
    for i in range(j,N-1,1):
        C,S,F = CSF[i]

        if t < S:
            t = S
        
        if t%F != 0:
            t += F-t%F
        
        t += C

    print(t)

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

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

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

print(0)

Solution (Python):
(n,),*csf = [list(map(int, s.split())) for s in open(0)]

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

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

Solution (Python):
def main():
    import sys

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

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

             
            
        
    
if __name__ == '__main__':
    main()

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N = z()
C, S, F = [0]*(N-1), [0]*(N-1), [0]*(N-1)
for i in range(N-1):
    c, s, f = zz()
    C[i], S[i], F[i] = c, s, f

ans = [0]*N
ans[N-2] = C[N-2] + S[N-2]
C_sum = [0]*(N-1)
C_sum[N-2] = C[N-2]
for i in reversed(range(0, N-2)):
    C_sum[i] = C_sum[i+1] + C[i]

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

    
    
    
    
    
    
    
    
    

    
    

for ans_ in ans:
    print(ans_)

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

for i in range(n-1):
    c1, s1, f1 = arr[i]
    ct = s1+c1
    for j in range(i+1, n-1):
        c2, s2, f2 = arr[j]
        while ct > s2:
            s2 += f2
        ct = s2 + c2
    print (ct)
print (0)

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

for i, [ci, si, fi] in enumerate(csf):
    time = si + ci
    for cj,sj,fj in csf[i + 1:]:
        time = max(sj, time)
        time += (fj - (time % fj)) % fj + cj
    print(time)
print(0)

Solution (Python):
n = int(input())
csf = [list(map(int,input().split())) for i in range(n-1)]
t = [[0] * n for i in range(n)]
for i in range(n-1):
    cc, cs, cf = csf[i][0], csf[i][1], csf[i][2]
    t[i][i] = cs
    for j in range(1+i):
        cs = csf[i][1]
        while t[j][i] > cs:
            cs += cf
        t[j][i+1] = cs + cc 
for i in range(n):
    print(t[i][n-1])

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

import math
result = []
for i, item in enumerate(maps):
    cost = item[0] + item[1]
    for j in range(i+1, n-1):
        next_cost = maps[j][1]
        if cost <= next_cost:
            cost = next_cost + maps[j][0]
        else:
            gap = cost - next_cost
            gap = math.ceil(gap/maps[j][2])
            cost = next_cost + maps[j][2]*gap + maps[j][0]
    result.append(cost)

for i in result:
    print(i , flush=True)
print(0 , flush=True)

Solution (Python):
import math

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

cost = []

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

for c in cost:
    print(c)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
def input(): return sys.stdin.readline()[:-1] 


import string

from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    
    n = int(input())
    a = []
    for _ in range(n-1):
        a.append([int(x) for x in input().split()])

    for i in range(n-1):
        c, s, f = a[i]

        cur = s + c
        for j in range(i+1, n-1):
            c, s, f = a[j]
            if s > cur:
                cur = s
            else:
                x = (cur + f - 1) // f
                cur = x * f

            cur += c
            
        print(cur)

    print(0)

t = 1

for case in range(1,t+1):
    ans = solve()


"""
a b a
d c d
a b a
"""

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')







def solve():
    N = II()
    L = []
    for i in range(N-1):
        c, s, f = MI()
        L.append([i, s])
        for j in range(i+1):
            k, t = L[j-1]
            if s <= t:
                if t % f == 0:
                    L[j-1] = [k, t+c]
                else:
                    t = t + f - (t % f)
                    L[j-1] = [k, t+c]
            else:
                L[j-1] = [k, s+c]
    

    for (i, t) in L:
        print(t)
    print(0)
            
        
        
if __name__ == '__main__':
    solve()

Solution (Python):
def ceil(n, m):
    return -(-n // m)

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

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

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

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):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    N = NI()
    trains = [NLI() for _ in range(N-1)]
    if N == 1:
        print(0)
        exit()

    for start in range(N-1):
        t = 0
        for now in range(start, N-1):
            C, S, F = trains[now]
            if t < S:
                t = S + C
            else:
                k = math.ceil((t-S)/F)
                t = S + k * F + C
        print(t)

    print(0)


if __name__ == "__main__":
    main()

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    train = []
    for _ in range(n - 1):
        c, s, f = map(int, input().split())
        train.append((c, s, f))
    
    for i in range(n):
        if i == n - 1:
            print(0)
            continue
        start = i + 1
        time = train[i][0] + train[i][1]
        while start < n - 1:
            if time < train[start][1]:
                time = train[start][0] + train[start][1]
            elif time % train[start][2] == 0:
                time += train[start][0]
            else:
                time += train[start][2] - (time % train[start][2])
                time += train[start][0]
            start += 1
        print(time)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
c=[];s=[];f=[]
for i in range(n-1):
    ci,si,fi=map(int,input().split())
    c.append(ci);s.append(si);f.append(fi)
for i in range(n-1):
    ans=s[i]+c[i]
    for j in range(i+1,n-1):
        tmp=ans
        if s[j]>=tmp:
            ans+=s[j]-tmp+c[j]
        else:
            ans+=f[j]-((tmp-s[j])%f[j] if (tmp-s[j])%f[j]!=0 else f[j])+c[j]
    print(ans)
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 = data[j][0]
        s = data[j][1]
        f = data[j][2]
        if t < s: 
            t = s
        elif t % f == 0:
            pass
        else:
            t += f - (t%f)
        t += c
    print(t)
        

print(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 j in range(i, N - 1):
        
        c, s, f = CSF[j][0], CSF[j][1], CSF[j][2]

        

        

        
        
        if ans < s:
            ans = s
        else:
            
            if ans % f == 0:
                ans += 0
            
            
            else:
                ans += f - ans % f

        
        ans += c
    
    print(ans)

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

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

Solution (Python):
import numpy as np

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



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

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
csf = [lr() for i in range(n-1)]
ans = []
for i in range(n):
    time = 0
    for j in range(i,n-1):
        c,s,f = csf[j]
        if time >= s:
            k = time%f
            if k != 0:
                time = (time//f+1)*f+c
            else:
                time = time+c
        else:
            time = s+c
    ans.append(time)
for num in ans:
    print(num)

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

import numpy as np
for i in range(N-1):
    elapsed_time = 0
    for k in range(i, N-1):
        c, s, f = stations[k]
        
        if elapsed_time <= s:
            wait_time = s - elapsed_time
        else:
            x = elapsed_time - s
            next_train = f * np.ceil(x/f)
            wait_time = next_train - x
        elapsed_time += wait_time + c
    print(int(elapsed_time))
print(0)

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

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

Station=[]
for n in range(N-1):
    Station.append(list(map(int,input().split())))
    
S=range(N)
for i in range(len(S)):
    t=0
    for s in range(i,len(S)-1):
        if t <= Station[s][1]:
            t = Station[s][1] + Station[s][0]
        else:
            if t%Station[s][2] != 0:
                t = t + (Station[s][2]-t%Station[s][2]) + Station[s][0]
            else:
                t = t + Station[s][0]
    print(t)

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    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())

    ans = [0] * N
    for i in range(N - 1):
        time = 0
        for c, s, f in zip(C[i:], S[i:], F[i:]):
            if time < s:
                time = s
            r = (time - s) % f
            time += f - r if r > 0 else 0
            time += c
        ans[i] = time

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


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N):
    if i == N - 1:
        print(0)
        break
    time = 0
    for j in range(i, N-1):
        if time < S[j]:
            time = S[j]
        if time % F[j] == 0:
            time += C[j]
        else:
            time += (F[j] - (time % F[j])) + C[j]
    print(time)

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

N = int(input())
CSF = [[0,0,0]]
for i in range(1,N):
    CSF.append(list(map(int,input().split())))
for i in range(1,N+1):
    nowtime = 0
    for j in range(i,N):
        if nowtime <=CSF[j][1]:
            depT =CSF[j][1]
        else:
            depT =CSF[j][1] + math.ceil((nowtime-CSF[j][1])/CSF[j][2])*CSF[j][2]

        nowtime = depT+CSF[j][0]
        
    print(nowtime)

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

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



N = int(input())

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

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

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

Solution (Python):
N = int(input())
csf = [0] * (N - 1)

for i in range(N - 1):
  c, s, f = map(int, input().split())
  csf[i] = [c, s, f]
  
def depart(n):
  now_time = 0
  if n == N - 1:
    return 0
  while n != N - 1:
    next_st = csf[n]
    if now_time <= next_st[1]:
      now_time = next_st[1] + next_st[0]
    else:
      while now_time % next_st[2] != 0:
        now_time += 1
      now_time += next_st[0]
    n += 1
    
  return now_time

for i in range(N):
  print(depart(i))

Solution (Python):
def nx(t,s,f):
    if t<s:
        return s
    elif (t-s)%f==0:
        return t
    else:
        return t+f-t%f
n = int(input())
C,S,F = [0]*n, [0]*n, [0]*n
for i in range(n-1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(n):
    ans = 0
    for j in range(i, n-1):
        ans = nx(ans,S[j],F[j])+C[j]
    print(ans)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    csf = [tuple(in_nn()) for _ in range(N - 1)]

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


if __name__ == '__main__':
    main()

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

def main(n,c,s,f):
    tList=[]
    t=[0]*(n+1)
    
    
    for e in range(1,n):
        t[e]=s[e]
        for i in range(e+1,n):
            t[i]=t[i-1]+c[i-1]
            if t[i]<=s[i]:
                t[i]=s[i]
            else:
                if t[i]%f[i]==0:
                    pass
                else:
                    t[i]=((t[i]//f[i])+1)*f[i]
        t[n]=t[n-1]+c[n-1]
        tList.append(t[n])
    tList.append(0)
    return tList

if __name__=='__main__':
    n,c,s,f=readinput()
    ans=main(n,c,s,f)
    for t in ans:
        print(t)

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

Solution (Python):
n = int(input())
train = [list(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 = train[j]
        t = max(t, s)
        t += (f - t % f) % f
        t += c
    print(t)

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

    for i in range(N-1):
        t = S[i][1] + S[i][0]
        for j in range(i+1,N-1):
            t = max(S[j][1],-(-t//S[j][2])*S[j][2]) + S[j][0]

        print(t)

    print(0)


main()

Solution (Python):
n=int(input())
l=[0 for _ in range(n)]

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

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

print(0)

Solution (Python):


def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    CSF = []
    for _ in range(N-1):
        c, s, f = MII()
        CSF.append((c, s, f))

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

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
tmp=[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):
      data=tmp[j]
      if time<data[1]:
         time=data[1]+data[0]
      else:
         if time%data[2]==0:
            time+=data[0]
         else:
            time+=data[2]-(time%data[2])+data[0]
   print(time)
print(0)

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

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

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

print(0)

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

for i in range(n-1):  
  t = 0
  for j in range(i, n-1):
    c,s,f = l[j]
    while t > s:
      s += f
    t = s+c
  print(t)
print(0)

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