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

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

Solution (Python):
from math import ceil
N = int(input())
dia = [0]*(N-1)
for i in range(N-1):
    c,s,f = map(int,input().split())
    dia[i] = (c,s,f)
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        if time > s:
            x = (time - s)/f
            s += ceil(x)*f
        time =  s + c
    print(time)
print(0)

Solution (Python):
from math import ceil
N = int(input())
dia = [0]*(N-1)
for i in range(N-1):
    c,s,f = map(int,input().split())
    dia[i] = (c,s,f)
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        if time > s:
            x = (time - s)/f
            s += ceil(x)*f
        time =  s + c
    print(time)
print(0)

Solution (Python):
N = int(input())
dia = [0]*(N-1)
for i in range(N-1):
    c,s,f = map(int,input().split())
    dia[i] = (c,s,f)
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        if time > s:
            x = (time - s)/f
            if x.is_integer():
                s += int(x)*f
            else:
                s += int(x+1)*f
        time =  s + c

        
        
        

    print(time)
print(0)

Solution (Python):
N = int(input())
dia = []
for _ in range(N-1):
    c,s,f = map(int,input().split())
    dia.append((c,s,f))
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        c,s,f = dia[j]
        while time > s:
            s += f

        time = s + c
    print(time)
print(0)

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

Cost = [0]
Start = [0]
Frequency = [0]
Ans = [0] * (N+1)

for __ in range(N-1):
    c, s, f = map(int, input().split())
    Cost.append(c)
    Start.append(s)
    Frequency.append(f)

for i in range(1, N):
    if Ans[i] != 0:
        print(Ans[i])
    else:
        Same = []
        now = 0
        for j in range(i, N):
            if now <= Start[j]:
                if Ans[j] != 0:
                    now = Ans[j]
                    break
                Same.append(j)
                now = Start[j] + Cost[j]
            else:
                tmp = (now-1) // Frequency[j]
                tim = (tmp + 1) * Frequency[j]
                now = tim + Cost[j]
        print(now)
        for k in Same:
            Ans[k] = now
print(0)

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

ans = []
for i in range(N):
    T = 0
    for j in range(i, N-1):
        T = max(CSF[j][1], math.ceil(T/CSF[j][2])*CSF[j][2])
        T += CSF[j][0]
    ans.append(T)


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

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

csfn = [None] * (n - 1)
for i in range(n - 1):
    csfn[i] = list(map(int, input().split(' ')))

result = [0] * n

for i in range(n - 1):
    for j in range(0, i + 1):
        if csfn[i][1] > result[j]:
            result[j] += (csfn[i][1] - result[j])
        else:
            result[j] += (-result[j] % csfn[i][2])
        result[j] += csfn[i][0]
        
for r in result:
    print(r)

Solution (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7

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

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

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

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

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

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

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

for start in range(N):
    time = 0
    current_i = start
    while current_i < N-1:
        if time >= Ss[current_i]:
            if time % Fs[current_i] == 0:
                time += Cs[current_i]
                current_i += 1
            else:
                time = Fs[current_i] * (time // Fs[current_i] + 1)
        else:
            time = Ss[current_i]

    print(time)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
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
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]






n=ii()
carr,sarr,farr=[],[],[]

for _ in range(n-1):
    c,s,f=mii()
    carr.append(c)
    sarr.append(s)
    farr.append(f)

ans = [0]*n

for start in range(n-1):
    for temp in range(start,n-1):
        if ans[start]<sarr[temp]:
            ans[start]=carr[temp]+sarr[temp]
        else:
            aa= farr[temp]-(ans[start]%farr[temp])
            if aa==farr[temp]:
                aa=0
            ans[start]+=aa+carr[temp]
        
print(*ans)

Solution (Python):
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    times = []
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            g = time > s
            time = s + int(g) * ceil((time - s) / f) * f + c
        times.append(str(time))

    ans = "\n".join(times)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    ans = ""
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            if time <= s:
                time = s + c
            else:
                time = s + ceil((time - s) / f) * f + c            

        ans += str(time) + '\n'
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    ans = ""
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            if time <= s:
                time = s
            else:
                time = s + ceil((time - s) / f) * f
            time += c
        
        ans += str(time) + '\n'
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    from math import ceil

    n, *csf = map(int, open(0).read().split())
    csf = list(zip(csf[::3], csf[1::3], csf[2::3]))
    for i in range(n):
        time = 0
        for c, s, f in csf[i:]:
            if time <= s:
                time = s
            else:
                time = s + ceil((time - s) / f) * f
            time += c
        print(time)


if __name__ == '__main__':
    main()

Solution (Python):
import math
n = int(input())
all_li = []
for _ in range(n-1):
    tmp_li = list(map(int,input().split()))
    all_li.append(tmp_li)
if n == 1:
    tmp = all_li[0]
    print(tmp[0]+tmp[1])
    exit()
for i,a in enumerate(all_li):
    now = a[1]+a[0]
    
    for aa in all_li[i+1:]:
        x,y,z = (aa[0],aa[1],aa[2])
        if now <= y:
            now = y+x
        else:
            now = math.ceil((now-y)/z)*z + y + x
    print(now)
    now = 0
print(0)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    N=int(readline())
    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,readline().split())

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

if __name__=="__main__":
    main()

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


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 warshall_floyd(d, n):
    
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d



def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    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 lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


n=I()
lis=[LI() for i in range(n)]
for i in range(n-1):
    time=lis[i][1]+lis[i][0]
    pos=i+1
    
    
    while pos<n-1:
        if time<lis[pos][1]:
            time=lis[pos][1]
        if time%lis[pos][2]!=0:
            time+=(lis[pos][2]-time%lis[pos][2])
        time+=lis[pos][0]
        pos+=1
        
        
    print(time)
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)

for i in range(n-2):
  ans = C[i]+S[i]
  for j in range(i+1, n-1):
    if S[j] >= ans:
      ans += (S[j]-ans) + C[j]
    else:
      if (ans-S[j])%F[j] == 0: ans += C[j]
      else: ans += F[j] - (ans-S[j])%F[j] + C[j]
  print(ans)
print(C[-1]+S[-1])
print(0)

Solution (Python):
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

from math import ceil

n = ni()
csf = nan(n - 1)

ans = []
for i in range(n - 1):
    c, s, f = csf[i]
    cur = s + c
    for j in range(i + 1, n - 1):
        nc, ns, nf = csf[j]
        cur = max(ceil(cur / nf) * nf, ns) + nc
    ans.append(cur)
ans.append(0)

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

Solution (Python):
import sys, math
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N = I()
    CSF = [LI() for _ in range(N-1)]

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

if __name__ == '__main__':
    resolve()

Solution (Python):
def main():
    n = int(input())
    info = [[int(x) for x in input().split()] for _ in range(n - 1)]
    answer = [0 for _ in range(n)]
    for i in range(n - 2, -1, -1):
        now = info[i][1]
        for j in range(i, n - 1):
            if j > i and now % info[j][2]:
                now += info[j][2] - now % info[j][2]
            now = max(now, info[j][1])
            now += info[j][0]
        answer[i] = now
    print("\n".join(map(str, answer)))


if __name__ == '__main__':
    main()

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

ans = [0]*N
for i in range(N-1):
    c,s,f = map(int,input().split())
    ans[i] += s+c
    for j in range(i):
        ans[j] = max((ans[j]+f-1)//f*f, s)+c
for a in ans:
    print(a)

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

ans = [0]*N
for i in range(N-1):
    c,s,f = map(int,input().split())
    ans[i] += c+s
    for j in range(i):
        ans[j] = max((ans[j]+f-1)//f*f, s)+c
for a in ans:
    print(a)

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

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

ans=[0]*n
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:
            pass
        else:
            t=(t//F[j]+1)*F[j]
        t+=C[j]
    ans[i]=t

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

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
csf = [list(map(int, readline().split())) for _ in range(n - 1)]
for i, (c, s, _) in enumerate(csf):
    s += c
    for cc, ss, ff in csf[i + 1:]:
        if s < ss:
            s = ss
        elif s % ff != 0:
            s += ff - (s % ff)
        s += cc
    print(s)
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))


ans = []
for i in range(n - 1):
    _c, start, _ = trains[i]
    t = start + _c
    for j in range(i + 1, n - 1):
        c, s, f = trains[j]
        if t > s:
            while t > s:
                s += f
            t += (s - t) + c
        else:
            t = s + c
    ans.append(t)
ans.append(0)
for a in ans:
    print(a)

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):
  ci,si,fi = map(int,input().split())
  c[i] = ci
  s[i] = si
  f[i] = fi
for i in range(n-1):
  x = s[i]
  for j in range(i,n-2):
    x += c[j]
    x = max(s[j+1],math.ceil(x/f[j+1])*f[j+1])
  x += c[n-2]
  print(x)
print(0)

Solution (Python):
N,*L = map(int, open(0).read().split())
ans = 0
inf = [0]*(N-1)
for i,(c,s,f) in enumerate(zip(*[iter(L)]*3)):
  inf[i] = (c,s,f)
for i in range(N-1):
  ans = 0
  for j in range(i,N-1):
    c,s,f = inf[j]
    m = ((ans-1)//f+1)*f
    ans = max(m,s)
    ans += c
  print(ans)
print(0)

Solution (Python):
n=int(input())
csf=[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):
        t=max(csf[j][1],t+(-t)%csf[j][2])+csf[j][0]
    print(t)
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 - 1):
    time = s[i] + c[i]
    for j in range(i + 1, n - 1):
        if time < s[j]:
            time = s[j] + c[j]
        elif time % f[j] != 0:
            time += f[j] - time % f[j] + c[j]
        else:
            time += c[j]
    print(time)
print(0)

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

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

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

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

import math

for i in range(N):
    time = 0
    for csf in CSF[i:]:
        if time <= csf[1]:
            time = csf[1] + csf[0]
        else:
            time = math.ceil((time - csf[1]) / csf[2])*csf[2] + csf[1] + csf[0]
    print(time)

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


ans = [0] * n
for i in range(n - 1):
    temp_time = 0
    for j in range(i, n - 1):
        c, s, f = csf[j]
        if temp_time <= s:
            temp_time += s - temp_time + c

        else:
            temp = temp_time % f
            temp_time += (f - temp) % f + c
    ans[i] = temp_time
print(*ans, sep='\n')

Solution (Python):
from sys import stdin
N=list(map(int,stdin.readline().strip().split()))[0]
eki=[list(map(int,input().split())) for _ in range(N-1)]

for i in range(len(eki)):
    x = eki[i][1]+eki[i][0]
    for j in range(i+1,len(eki)):
        if eki[j][1] >x:
            x=eki[j][1]
            x += eki[j][0]
        elif x%eki[j][2]==0:x+=eki[j][0]
        else:
            x+=eki[j][0]+eki[j][2]-x%eki[j][2]
    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):
    time=0
    for j in range(i,n-1):
        c,s,f=CSF[j]
        if i==j:
            time +=c+s
            continue
        else:
            if time<s:time=s
            elif time%f!=0:time +=f-(time%f)
            time +=c
    print(time)
print(0)

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

def main():
    N = int(readline())
    CSF = [list(map(int, readline().rstrip().split())) for _ in range(N-1)]
    
    for i in range(N):
        t = 0
        for c, s, f in CSF[i:]:
            m = (t - s) / f
            m = max(math.ceil(m), 0)
            t = s + f * m + c
        print(t)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
c,s,f=[0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1):
    c[i],s[i],f[i]=map(int,input().split())
for j in range(n-1):
    t=s[j]+c[j]
    now=j+1
    while now<n-1:
        if s[now]<t:
            t=((-t)//f[now])*(-f[now])
        else:
            t=s[now]
        t+=c[now]
        now+=1
    print(t)
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):
    t = max(t, s[j])
    t = (t + f[j] - 1) // f[j] * f[j] + c[j]
  print(t)

Solution (Python):
import sys

readline = sys.stdin.readline
N = int(readline())
CSF = [list(map(int, readline().split())) for _ in range(N-1)]
for i in range(N):
    time = 0
    for c, s, f in CSF[i:N-1]:
        if time < s:
            time = s
        else:
            time = (time+f-1)//f*f
        time += c
    print(time)

Solution (Python):
import sys

readline = sys.stdin.readline
N = int(readline())
CSF = [tuple(map(int, readline().split())) for _ in range(N-1)]
for i in range(N):
    time = 0
    for c, s, f in CSF[i:N-1]:
        if time < s:
            time = s
        else:
            time = (time+f-1)//f*f
        time += c
    print(time)

Solution (Python):
import sys

readline = sys.stdin.readline
N = int(readline())
CSF = []
for i in range(N-1):
    CSF.append(tuple(map(int, readline().split())))
for i in range(N):
    time = 0
    for c, s, f in CSF[i:N-1]:
        if time < s:
            time = s
        else:
            time = (time+f-1)//f*f
        time += c
    print(time)

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

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

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):
  j=i
  t=0
  while j<N-1:
    if t<=S[j]:
      t=S[j]
    else:
      tmp= t-S[j]
      s=tmp%F[j]
      if s!=0:
        t += F[j]-s
    
    t += C[j]
    j +=1
  print(t)

Solution (Python):
import sys

IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]

DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y


def main():
    n = II()
    tt = [MII() for _ in range(n-1)]
    for i in range(n):
        t = 0
        for c, s, f in tt[i:]:
            
            if t <= s:
                t = s
            elif t%f == 0:
                pass
            else:
                t += f - (t%f)
            
            t += c
        print(t)


if __name__ == '__main__':
    main()