Problem:
 Score : 300 points    Problem Statement A railroad running from west to east in Atcoder Kingdom is now complete.  There are N stations on the railroad, numbered 1 through N from west to east.  Tomorrow, the opening ceremony of the railroad will take place.  On this railroad, for each integer i such that 1≤i≤N-1 , there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.  The first train from Station i to Station i+1 will depart Station i  S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.  Here, it is guaranteed that F_i divides S_i .  That is, for each Time t satisfying S_i≤t and t％F_i=0 , there will be a train that departs Station i  t seconds after the ceremony begins and arrives at Station i+1  t+C_i seconds after the ceremony begins, where A％B denotes A modulo B , and there will be no other trains.  For each i , find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.      Constraints  1≤N≤500  1≤C_i≤100  1≤S_i≤10^5  1≤F_i≤10  S_i％F_i=0  All input values are integers.         Input Input is given from Standard Input in the following format:  N  C_1  S_1  F_1  :  C_{N-1}  S_{N-1}  F_{N-1}       Output Print N lines. Assuming that we are at Station i  (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i -th line should contain x .        Sample Input 1 3
6 5 1
1 10 1      Sample Output 1 12
11
0  We will travel from Station 1 as follows:   5 seconds after the beginning: take the train to Station 2 .  11 seconds: arrive at Station 2 .  11 seconds: take the train to Station 3 .  12 seconds: arrive at Station 3 .   We will travel from Station 2 as follows:   10 seconds: take the train to Station 3 .  11 seconds: arrive at Station 3 .   Note that we should print 0 for Station 3 .       Sample Input 2 4
12 24 6
52 16 4
99 2 2      Sample Output 2 187
167
101
0       Sample Input 3 4
12 13 1
44 17 17
66 4096 64      Sample Output 3 4162
4162
4162
0

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

ans=[0]*(N)

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

    for j in range(i,N-1):
        m=-(-t//F[j])*F[j]
        t=max(S[j],m)
        t+=C[j]
    
    ans[i]=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-1):
    t = csf[i][0]+csf[i][1]
    for j in range(i+1, N-1):
        if t <= csf[j][1]:
            t = csf[j][1]
        else:
            t = (t+csf[j][2]-1)//csf[j][2] * csf[j][2]
        t += csf[j][0]
    print(t)
print(0)

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

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

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

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

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

def d(x,t): 
	if S[x]>=t:
		return C[x]+S[x]-t
	else:
		if (t-S[x])%F[x]==0:
			return C[x]
		else:
			return C[x]+F[x]-(t-S[x])%F[x]

for i in range(n-1):
	x=i
	ans=0
	for j in range(x,n-1):
		ans+=d(j,ans)
		x=+1
	print(ans)
print(0)

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

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

def cnt(x):
  ret = 0
  for i in range(x, N-1):
    C, S, F = CSF[i]
    if ret < S:
      ret = S
      ret += C
    else:
      ret = -(-ret//F)*F
      ret += C
  return ret

for x in range(N):
  print(cnt(x))

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

    anslis = []

    for j in range(n-1):
        tmp = 0
        for i in range(j,n-1):
            c, s, f= inlis[i][0], inlis[i][1], inlis[i][2]
            if tmp < s:
                tmp = s
            
            amari = tmp % f
            if amari != 0:
                tmp += f - amari

            tmp += c
            
        anslis.append(tmp)
    anslis.append(0)
    
    for k in anslis:
        print(k)
    


if __name__ == "__main__":
    main()

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

Solution (Python):
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def ceil(A, B):
    if A%B == 0:
        return A//B
    return A//B+1

def solve() -> Any:
    N = read_int()
    C, S, F = [], [], []
    for _ in range(N-1):
        c, s, f = read_ints()
        C.append(c)
        S.append(s)
        F.append(f)
    dp = [
        [0 for _ in range(N)] for _ in range(N)
    ]
    
    for j in range(1, N):
        for i in range(j):
            if dp[i][j-1] <= S[j-1]:
                dp[i][j] = S[j-1]+C[j-1]
            else:
                k = ceil((dp[i][j-1]-S[j-1]), F[j-1])
                dp[i][j] = k*F[j-1]+S[j-1]+C[j-1]
                
    for i in range(N):
        print(dp[i][N-1])


if __name__ == '__main__':
    solve()

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    n = I()
    time = [0 for _ in range(n)]
    start = [0 for _ in range(n)]
    freq = [0 for _ in range(n)]

    for i in range(n-1):
        time[i], start[i], freq[i] = LI()

    ans = [0 for _ in range(n)]

    for i in range(n):
        before = 0
        after = 0
        for j in range(i,n-1):
            if before < start[j]:
                after = start[j]
            else:
                after = before - before%freq[j] + freq[j]*(before%freq[j] != 0)

            before = after + time[j]

        ans[i] = before

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



main()

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    L = [i_list() for i in range(n-1)]

    ans = []

    for l in range(n-1):
        time = L[l][1] + L[l][0]
        for j in range(n-l-2):
            t = l+j+1
            if time <= L[t][1]: 
                time = L[t][1] + L[t][0]
            elif (time - L[t][1]) % L[t][2] == 0: 
                time += L[t][0]
            else: 
                s = (time - L[t][1])//L[t][2] + 1
                time = L[t][1] + L[t][2]*s + L[t][0]
        print(time)
    print(0)




if __name__=="__main__":
    main()

Solution (Python):

import sys
import math
sys.setrecursionlimit(10**6)
n = int(input())

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

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

    c, s, f = csf_tmp[0]

    t = c+s
    for j in range(1, len(csf_tmp)):
        c, s, f = csf_tmp[j]

        if t <= s:
            t = s
        else:
            mod = (t-s) % f
            if mod != 0:
                t += f-mod
        
        t += c
        
    print(t)
    
print(0)

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

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


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

Solution (Python):
from math import ceil

n = int(input())
cs = []
ss = []
fs = []

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

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

Solution (Python):
from math import ceil

n=int(input())
lst=[]
ans=[]

for i in range(n-1):
    x,y,z=map(int,input().split())
    lst.append([x,y,z])


for i in range(n-1):
    pin=0
    for c,s,f in lst[i:]:
        xxx=max(ceil((pin-s)/f),0)
        pin=s+xxx*f+c
    
    ans.append(pin)


for i in ans:
    print(i)

print(0)

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

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

ans = []
for i in range(N - 1):
    t = x[i][0] + x[i][1]
    for j in range(i + 1, N - 1):
        if t % x[j][2] == 0:
            t = max(t, x[j][1])
        else:
            t = max(t + (x[j][2] - t % x[j][2]), x[j][1])
        t += x[j][0]
    ans.append(t)
ans.append(0)

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

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

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

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

Solution (Python):

def main():
    with open(0) as f:
        N = int(f.readline())
        train = [tuple(map(int, line.split())) for line in f.readlines()]
    
    ans = []
    for start in range(N-1):
        arrive = 0
        for station in range(start, N-1):
            c, s, f = train[station]
            
            departure = lambda arrive:(arrive+f-1)//f*f if arrive >= s else s
            arrive = departure(arrive) + c
        ans.append(arrive)
    ans.append(0)
    for x in ans: print(x)

main()

Solution (Python):
url = "https://atcoder.jp/contests/abc087/tasks/arc090_a"
import copy
def main():
    n = int(input())
    t = [list(map(int, input().split())) for _ in range(n-1)]
    for i in range(len(t)):
        time = t[i][0] + t[i][1]
        for j in range(i+1, len(t)):
            st = t[j]
            if time <= st[1]:
                time = st[1]
            elif time % st[2] == 0:
                pass
            else:
                time += st[2] - (time % (st[2]))
            time += st[0]
        print(time)
    print(0)



if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    CSF = [NLI() for _ in range(N-1)]
    CSF.append([0,0,1])

    
    for n in range(N-1):
        time = CSF[n][1]
        
        for m in range(n,N-1):
            time += CSF[m][0]
            if time < CSF[m+1][1]:
                time = CSF[m+1][1]
            else:
                if time % CSF[m+1][2] != 0:
                    time = ((time//CSF[m+1][2])+1)*CSF[m+1][2]
        print(time)
    print(0)



if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    d = [list(map(int, input().split())) for _ in range(N-1)]
    for i in range(N-1):
        measure_time(d[i], d[i+1:])
    print(0)


def measure_time(start, remain):
    t = 0
    t = start[1] + start[0]
    for r in remain:
        if t < r[1]:
            t = r[1]
        elif (t - r[1]) % r[2] != 0:
            t += r[2] - (t - r[1]) % r[2]
        t += r[0]
    print(t)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
x=[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):
        if ans%x[j][2]==0:
            a=0
        else:
            a=x[j][2]-(ans%x[j][2])
        ans=(max(ans+a,x[j][1]))
        ans+=x[j][0]
    print(ans)

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

Solution (Python):


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

t = [[-1 for _ in range(n)] for _ in range(n-1)]

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

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





for i in range(n-1):
    print(t[i][n-1])
print(0)

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

Solution (Python):

import sys, math, heapq
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

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

for i in range(N - 1):
    c, s, f = CSF[i]
    time = s + c
    for csfj in CSF[i + 1 :]:
        c, s, f = csfj
        if time < s:
            time = s
        else:
            time = f * ((time + f - 1) // f)
        time += c
    print(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 c, s, f in csf[i::]:
        if ans <= s:
            ans = s
        else:
            if ans % f == 0:
                pass
            else:
                ans = (ans // f + 1) * f
        ans += c
    print(ans)

Solution (Python):
def solve():
    n = int(input())
    csf = [list(map(int,input().split())) for _ in range(n-1)]
    
    for i in range(n):
        time = 0
        while True:
            if i == n-1:
                print(time)
                break
            if time < csf[i][1]:
                time = csf[i][1] + csf[i][0]
            else:
                if time%csf[i][2] == 0:
                    time += csf[i][0]
                else:
                    time += csf[i][0] + csf[i][2] -  time%csf[i][2]
            i += 1

if __name__ == "__main__":
    solve()

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

for i in range(n):
    time = 0
    while True:
        if i == n-1:
            print(time)
            break
        if time < csf[i][1]:
            time = csf[i][1] + csf[i][0]
        else:
            if time%csf[i][2] == 0:
                time += csf[i][0]
            else:
                time += csf[i][0] + csf[i][2] -  time%csf[i][2]
        i += 1

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

for i in range(n):
    time = 0
    while True:
        if i == n-1:
            print(time)
            break
        if csf[i][1] <= time and time%csf[i][2] == 0:
            time += csf[i][0]
        elif csf[i][1] > time:
            time = csf[i][1] + csf[i][0]
        else:
            time += csf[i][2] - time%csf[i][2] + csf[i][0]
        i += 1

Solution (Python):
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n = ni()
    C = []
    S = []
    F = []
    for i in range(n - 1):
        c, s, f = nm()
        C.append(c)
        S.append(s)
        F.append(f)
    for i in range(n - 1):
        time = 0
        for j in range(i, n - 1):
            if time <= S[j]:
                time = S[j] + C[j]
            else:
                time = time + (F[j] - (time - S[j]) % F[j]) % F[j] + C[j]
        print(time)
    print(0)


if __name__ == '__main__':
    main()

Solution (Python):
import sys



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


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    times = []
    for _ in range(n - 1):
        times.append(input_int_list())

    for i in range(n - 1):
        cur = 0
        for j in range(i, n - 1):
            c, s, f = times[j]
            
            time = s
            while time < cur:
                time += f
            cur = time + c
        print(cur)
    
    print(0)
    return


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N=intput()
L=[]
for _ in range(N-1):
    L.append(lint())
for i in range(N):
    tmp = 0
    for j in range(i,N-1):
        c,s,f=L[j]
        tmp = max(((tmp-1)//f+1)*f,s)+c
    print(tmp)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N=intput()
L=[]
ans=[]
for _ in range(N-1):
    L.append(lint())
for i in range(N):
    tmp = 0
    for j in range(i,N-1):
        c,s,f=L[j]
        tmp = max(((tmp-1)//f+1)*f,s)+c
    ans.append(tmp)
lprint(ans)

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 station in range(N):
    now = station
    time = 0

    while now < N-1:
        if time < S[now]:
            time = S[now] + C[now]
        else:
            if time % F[now] == 0:
                time += C[now]
            else:
                wait_time = F[now] - (time % F[now])
                time += wait_time + C[now]

        now += 1

    print(time)

Solution (Python):
import sys
n, *CSF = list(map(int, sys.stdin.buffer.read().split()))
C = CSF[::3]
S = CSF[1::3]
F = CSF[2::3]


def solve(x):
    cur = 0
    for i in range(x, n - 1):
        y = cur % F[i]
        if S[i] > cur:
            cur = S[i] + C[i]
        elif y == 0:
            cur += C[i]
        else:
            cur += (F[i] - y) + C[i]
    return cur


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

Solution (Python):
import sys
n, *CSF = list(map(int, sys.stdin.read().split()))
C = CSF[::3]
S = CSF[1::3]
F = CSF[2::3]


def solve(x):
    cur = 0
    for i in range(x, n - 1):
        y = cur % F[i]
        if S[i] > cur:
            cur = S[i] + C[i]
        elif y == 0:
            cur += C[i]
        else:
            cur += (F[i] - y) + C[i]
    return cur


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

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

Solution (Python):
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  
  
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright






n=int(input())
A=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n):
    if i==n-1:print(0);exit()
    now=0
    for l in A[i:]:
        c,s,f =l 
        now=max(now,s)
        for plus in range(0,101):
            if (now+plus)% f==0:
                now+=plus
                break
        now+=c
    print(now)

Solution (Python):
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict 
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  
  
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright






n=int(input())
A=[list(map(int,input().split())) for i in range(n-1)]
for i in range(n):
    if i==n-1:print(0);exit()
    now=0
    for l in A[i:]:
        c,s,f =l 
        now=max(now,s)
        for plus in range(0,101):
            if (now+plus)% f==0:
                now+=plus
                break
        now+=c
    print(now)

Solution (Python):
n = int(input())
cl = []
sl = []
fl = []

for _ in range(n-1):
    c,s,f = map(int,input().split())
    cl += [c]
    sl += [s]
    fl += [f]

        

for i in range(n):
    time = 0
    while True:
        if i==n-1:
            print(time)
            break
        if sl[i]<=time and time%fl[i]==0:
            time += cl[i]
        elif sl[i]>time:
            time = sl[i] +cl[i]
        else: 
            time += fl[i] - time%fl[i] +cl[i]
        i += 1

Solution (Python):
n = int(input())
cost = [0]*n
start = [0]*n
freaq = [0]*n
dp = [[0]*n for _ in range(n)]

for i in range(n-1):
    cost[i],start[i],freaq[i] = map(int,input().split())
    dp[i][i] = start[i]

freaq[n-1] = 1

t = 0

for i in range(n-1):
    for j in range(i+1):
        t = dp[j][i]
        t += cost[i]
        if t%freaq[i+1] != 0:
            t += freaq[i+1] - t%freaq[i+1]
        t = max(t,start[i+1])
        dp[j][i+1] = t

for i in range(n):
    print(dp[i][n-1])

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)
T=[-1]*n
T[-1]=0
for i in range(n-1):
    p=i
    t=0
    for j in range(n-i-1):
        if t<=s[p]:
            t=s[p]
            t+=c[p]
        else:
            m=(t+f[p]-1)//f[p]
            t=m*f[p]
            t+=c[p]
        p+=1
    T[i]=t
for i in range(n):
    print(T[i])

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

for i in l:print(i)

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

for i in range(N):
 p,q,r=C[i]
 A=q+p
 for j in range(i+1,N):
  c,s,f=C[j]
  if A<s:A=s
  m=(A-s)%f
  if m!=0:A+=f-m
  A+=c
 print(A)
print(0)

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

for i in range(N-1):
 c,s,f=C[i]
 A=s+c
 for j in range(i+1,N-1):
    nc,ns,nf=C[j]
    if A<ns:A=ns
    elif (A-ns)%nf!=0:A+=nf-(A-ns)%nf
    A+=nc
 print(A)
print(0)

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

for i in range(N-1):
    c,s,f=C[i]
    ans=s+c
    for j in range(i+1,N-1):
        nc,ns,nf=C[j]
        
        ans=max(ans,ns)
        m=(ans-ns)%nf
        if m!=0:ans+=nf-m
        
        ans+=nc
    print(ans)
print(0)

Solution (Python):
n = int(input())
ls = [list(map(int,input().split())) for _ in range(n-1)]
def culc(nt,p):
    if nt == 0:
        if p != n-1:
            nt = ls[p][1] + ls[p][0]
            culc(nt,p+1)
        else:
            print(0)
    else:
        if p != n-1:
            if nt >= ls[p][1]:
                m = (nt - ls[p][1])//ls[p][2]
                if (nt - ls[p][1])%ls[p][2] != 0:
                    m += 1
                nt = ls[p][1] + ls[p][2]*m + ls[p][0]
                culc(nt,p+1)
            else:
                nt = ls[p][1] + ls[p][0]
                culc(nt,p+1)
        else:
            print(nt)
for i in range(n):
    culc(0,i)

Solution (Python):
n = int(input())
ls = [list(map(int,input().split())) for _ in range(n-1)]
def culc(nt,p):
    if nt == 0:
        if p != n-1:
            nt = ls[p][1] + ls[p][0]
            culc(nt,p+1)
        else:
            print(0)
    else:
        if p != n-1:
            if nt >= ls[p][1]:
                m = (nt - ls[p][1])//ls[p][2]
                if (nt - ls[p][1])%ls[p][2] != 0:
                    m += 1
                nt = ls[p][1] + ls[p][2]*m + ls[p][0]
                culc(nt,p+1)
            else:
                nt = ls[p][1] + ls[p][0]
                culc(nt,p+1)
        else:
            print(nt)
for i in range(n):
    culc(0,i)

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

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

Solution (Python):
def jikan(now_t,i):
    if i==n:
        return now_t
    else:
        if now_t<=s[i]:
            now_t = s[i]
        else:
            tmp1 = now_t//f[i]
            if now_t%f[i]!=0:
                now_t = (tmp1+1)*f[i]
        tmp = jikan(now_t+c[i],i+1)
        return tmp

n = int(input())
c,s,f = [0],[0],[0]
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(1,n+1):
    print(jikan(0,i))