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())
status_lst = [0] * (N-1)
for _ in range(N-1):
    status_lst[_] = list(map(int, input().split()))







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

    rev_res.append(elapsed)

rev_res.append(0)

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

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

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

Solution (Python):
from itertools import accumulate
n,*l=map(int,open(0).read().split())
c=l[::3];s=l[1::3];f=l[2::3]
def func(m):
	t=c[m]+s[m]
	for i in range(m+1,n-1):
		fi=f[i]
		t=max((t//fi+(t%fi!=0))*fi,s[i])+c[i]
	return t
for i in range(n-2):
	print(func(i))
print(c[-1]+s[-1],0,sep="\n")

Solution (Python):

import sys, math, fractions, itertools


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



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

if __name__ == '__main__':
    main()

Solution (Python):

import sys, math, fractions, itertools


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



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

if __name__ == '__main__':
    main()

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

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


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

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

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

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

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

Solution (Python):
from math import ceil

N = int(input())

ans = [0] * N
for i in range(1, N):
    c, s, f = [int(zz) for zz in input().split()]
    ans[i] = s + c
    for j in range(1, i):
        p = ceil(ans[j] / f) * f
        if p < s:
            ans[j] = s + c
        else:
            ans[j] = c + p

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

print(0)

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

for n in range(N):
    ans = 0
    for c, s, f in csf[n:]:
        if ans > s:
            tmp = math.ceil((ans - s) / f)
            ans = s + tmp * f + c
        else:
            ans = s + c
    print(ans)

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

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

for idx, station in enumerate(stations):
  time = station[1] + station[0]
  for next in range(idx+1, N-1):
    if time < stations[next][1]:
      time = stations[next][1] + stations[next][0]
    elif (time-stations[next][1])%stations[next][2] == 0:
      time += stations[next][0]
    else:
      time += stations[next][2] - (time-stations[next][1])%stations[next][2] + stations[next][0]
  print(time)
print(0)

Solution (Python):
from math import ceil
from collections import defaultdict
N=int(input())
Time=defaultdict(int)
for i in range(N-1):
    c,s,f=map(int,input().split())
    for j in range(N):
        if j<i:Time[j]=max(s,(ceil(Time[j]/f))*f)+c
        elif j==i:Time[j]=s+c
        else:pass
for k in range(N):print(Time[k])

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
CSF = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N-1)]
for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < CSF[j][1]:
            t = CSF[j][1]
        elif t % CSF[j][2] == 0:
            pass
        else:
            t += CSF[j][2] - t % CSF[j][2]
        t += CSF[j][0]
    print(t)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    m = II()
    print(48-m)
    return


def B():
    a, b = LI()
    s = S()
    ans = list(map(str, range(10)))
    for num, si in enumerate(s):
        if num != a:
            if si in ans:
                continue
            print("No")
            return
        else:
            if si == "-":
                continue
            print("No")
            return
    print("Yes")
    return


def C():
    n = II()
    csf = LIR(n - 1)
    for i in range(n - 1):
        b = 0
        for k in range(i, n - 1):
            c, s, f = csf[k]
            if b <= s:
                b = s + c
            else:
                b += c + (-b % f)
        print(b)
    print(0)
    return


def D():
    a = II()
    ans = inf
    b = 0
    for k in range(1, 10 ** 5):
        b += a
        ans = min(ans, sum(list(map(int, list(str(b))))))
    print(ans)
    return


if __name__ == '__main__':
    C()

Solution (Python):
import copy
import sys
import math

def main():
	n = int(input())
	c, s, f = [], [], []
	for _ in range(n-1):
		tmp = list(map(int,input().split()))
		c.append(tmp[0])
		s.append(tmp[1])
		f.append(tmp[2])
	
	
	
	for i in range(n-1):
		currenttime = s[i] + c[i]
		
		for j in range(i+1,n-1):
			
			
			if(currenttime <= s[j]):
				currenttime = c[j] + s[j]
				
			else:
				
				currenttime = math.ceil((currenttime - s[j]) / f[j]) * f[j] +  s[j] + c[j]
		print(currenttime)
	print(0)

def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

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

Solution (Python):






def tt(time,i):
	if(i==n):
		return time
	if(time<=s[i]):
		return tt(s[i]+c[i],i+1)
	return tt((((time-s[i]-1)//f[i])+1)*f[i]+s[i]+c[i],i+1)

n = int(input())
c=[]
s=[]
f=[]
t=[]

c.append(0)
s.append(0)
f.append(0)
t.append(0)
for i in range(1,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	c.append(hoge[0])
	s.append(hoge[1])
	f.append(hoge[2])
	t.append(0)
c.append(0)
s.append(0)
f.append(1)
t.append(0)










for i in range(1,n+1):
	print(tt(0,i))

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

Solution (Python):

import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math





 
def main():
    N = int(input())
    csf = []
    for i in range(N-1):
        c,s,f = map(int, input().split())
        csf.append((c,s,f))
        
    for i, val in enumerate(csf):
        ans = 0
        c,s,f = val
        ans += s + c
        for j, vol in enumerate(csf):
            if i >= j:
                continue
                
            cc,ss,ff = vol
            if ans <= ss:
                ans = ss + cc
            else:
                tmp = ans - ss
                if tmp == 0:
                    ans += cc
                    continue
                    
                tmp2 = (tmp // ff)
                if tmp % ff != 0:
                    tmp2 += 1
                tmp2 = (tmp2 * ff) + ss
                ans = ans + (tmp2 - ans) + cc
        print(ans)
                
    print(0)
    
	
if __name__ == "__main__":
	main()

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

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

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 = []
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] - time + C[j]
        else:
            time += C[j] + (F[j] - time % F[j] if time % F[j] else 0)
    ans.append(time)

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

Solution (Python):



n = int(input())

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

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

Solution (Python):
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int c[] = new int[n];
		int s[] = new int[n];
		int f[] = new int[n];
		for (int i = 1; i < n; i++) {
			c[i] = Integer.parseInt(sc.next());
			s[i] = Integer.parseInt(sc.next());
			f[i] = Integer.parseInt(sc.next());
		}
		for (int i = 1; i <= n; i++) {
			int t = 0;
			for (int j = i; j < n; j++) {
				if (t < s[j])
					t = s[j];
				else if ( t % f[j] != 0)
					t += f[j] - t % f[j];
				t += c[j];
			}
			out.println(t);
		}
		out.flush();
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Solution (Python):
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int c[] = new int[n];
		int s[] = new int[n];
		int f[] = new int[n];
		for (int i = 1; i < n; i++) {
			c[i] = Integer.parseInt(sc.next());
			s[i] = Integer.parseInt(sc.next());
			f[i] = Integer.parseInt(sc.next());
		}
		for (int i = 1; i <= n; i++) {
			int t = 0;
			for (int j = i; j < n; j++) {
				if (t < s[j])
					t = s[j];
				else if ( t % f[j] != 0)
					t += f[j] - t % f[j];
				t += c[j];
			}
			out.println(t);
		}
		out.flush();
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Solution (Python):
import numpy as np

N = int(input())

C = np.empty(N - 1, dtype = int)
S = np.empty(N - 1, dtype = int)
F = np.empty(N - 1, dtype = int)
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]
    
    t += C[i]
    
    for j in range(i + 1, N - 1):
        
        if t > S[j]:
            
            a = (t - S[j]) // F[j]
            b = (t - S[j]) % F[j]
            
            t = S[j] + (a + min(b, 1)) * F[j]
        
        elif t < S[j]:
            
            t = S[j]
        
        t += C[j]
    
    print(t)

print(0)

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

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

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

n = int(input())
csfn = [() for i in range(n-1)]
tl = [0]*n
for i in range(n-1):
  c,s,f = map(int,input().split())
  csfn[i] += (c,s,f)
  
  for j in range(i+1):
    if tl[j] < csfn[i][1]:
      tl[j] = csfn[i][1] + csfn[i][0]
    elif tl[j] % csfn[i][2] == 0:
      tl[j] += csfn[i][0]
    else:
      tl[j] += csfn[i][0] + csfn[i][2] - tl[j] % csfn[i][2]
for k in tl:
  print(k)

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

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

Solution (Python):

n = int(input())
train_list = []
for i in range(n-1):
    train_list.append([ int(v) for v in input().split() ])

def ride(a,t):
    global train_list
    if a == n - 1:
        return t
    else:
        duration, first, interval = train_list[a]
        if t <= first:
            time = first + duration
        else:
            b = (t - first + interval - 1) // interval
            time = first + duration + interval * b
        return ride(a+1,time)

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

Solution (Python):
N = int(input())
lc=[]
ls=[]
lf=[]
for _ in range(N-1):
    C,S,F = map(int,input().split())
    lc.append(C)
    ls.append(S)
    lf.append(F)

for i in range(N-1):
    j = i
    ct = 0
    while j < N-1:
        if ct <= ls[j]:ct = ls[j] + lc[j]
        else:
            os = ct - ls[j]
            rm = os - lf[j] * (os//lf[j])
            if rm == 0:ct += lc[j]
            else:ct += (lf[j]-rm) + lc[j]
        if j == N-2:print(ct)
        j += 1
else:print(0)

Solution (Python):
N = int(input())
CSF = []
for n in range(N-1):
  CSF.append([int(csf) for csf in input().split()])

for i in range(N-1):
  total_time = 0
  for j in range(i, N-1):
    c12, s1, f1 = CSF[j]
    if s1 >= total_time:
      total_time = s1 + c12
    else:
      how_many_arrival_train = (total_time - s1) // f1
      how_long_waiting_time = (total_time - s1) % f1
      if how_long_waiting_time == 0:
        total_time = s1 + f1 * how_many_arrival_train + c12
      else:
        total_time = s1 + f1 * (how_many_arrival_train + 1) + c12
  print(total_time)
print(0)

Solution (Python):
N = int(input())
C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)
for i in range(N - 1):
    C[i], S[i], F[i] = map(int, input().split())
for n in range(N):
    time = 0
    for i in range(n, N - 1):
        dep = S[i]
        time = max(time, dep)
        while time > dep:
            dep += F[i]
        time = dep + C[i]
    print(time)

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):
		c,s,f=csf[i]
		if t>=s:
			t+=(s-t)%f+c
		else:
			t=s+c
	print(t)

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

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

Solution (Python):
n=int(input())
if n==1:
    print("0")
    exit()
l=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n):
    t=0
    k=i
    while k<n-1:
        if l[k][1]>t:
            t=l[k][0]+l[k][1]
            k+=1
            continue
        elif t%l[k][2]==0:
            t+=l[k][0]
            k+=1
            continue
        else:t+=l[k][2]-t%l[k][2]
    print(t)

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

ans = [0]*N
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        time = max(time,CSF[j][1]) 
        time += (CSF[j][1]-time)%CSF[j][2] 
        time += CSF[j][0] 
    ans[i] = time
for i in ans:
    print(i)

Solution (Python):
import math
N =int(input() )
trains = [list(map(int,input().split(" "))) for _ in range(N-1)]
for s in range(N):
    ans = 0
    spent = 0
    arrived_time = 0
    for train in trains[s:]:
        c,s,f = train
        n = max(0,math.ceil((ans-s) /f))
        wait = n * f + s - ans
        

        ans += c + wait

    print(ans)

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

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

for i in range(n):
    time=0
    for j in range(i,n):
        if time<csf[j][1]:
            time=csf[j][1]+csf[j][0]
        elif time%csf[j][2]!=0:
            time+=csf[j][2]-(time%csf[j][2])+csf[j][0]
        else:
            time+=csf[j][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):
    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
input = sys.stdin.readline

N = int(input())
L = [[int(v) for v in input().split()] for _ in range(N - 1)]

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

print(0)

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

Solution (Python):
def nextsta(t,c,s,f):
    if t<=s:return s
    elif t%f == 0:return t
    else:return(t + f - t%f)
N=int(input())-1
CSF = [[int(i) for i in input().split()] for i in range(N)]
for StartSt in range(N):
    cursta = StartSt
    curtime = 0
    for st in range(StartSt,N):
        c,s,f = CSF[cursta]
        curtime = nextsta(curtime,c,s,f) + c
        cursta += 1
    print(curtime)
print(0)

Solution (Python):

import sys
input = sys.stdin.readline

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


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

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


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
L = [list(map(int, input().split())) for i in range(N-1)]
for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if t < L[j][1]:
            t = L[j][1]
        elif t % L[j][2] == 0:
            pass
        else:
            t = t + L[j][2] - t % L[j][2]
        t += L[j][0]  
    print(t)
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):
    ct=0
    for j in range(i,N-1):
        if ct<=S[j]:
            ct=S[j]
        else:
            if ct%F[j]!=0:
                ct+=F[j]-(ct%F[j])
        ct+=C[j]
    print(ct)
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())


def ceil(x,y):
    if x % y == 0:
        return x
    else:
        return (x//y+1)*y

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

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

Solution (Python):
n = int(input())
c = [0]*n
s = [0]*n
f = [0]*n
ans = [0]*n

for i in range(n-1):
  c[i], s[i], f[i] = map(int, input().split())
    
for i in range(n):
  t = 0
  for j in range(i, n-1):
    if t <= s[j]:
      t = s[j]
    elif t % f[j] is 0:
      t = t
    else:
      t = t + f [j] - t % f [j];
    t += c[j];
  print(t)

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
stations = []
for i in range(N-1):
    stations.append(nl())

times = [0] * N
for i in range(N-1):
    C, S, F = stations[i]
    t = S + C
    for j in range(i+1, N-1):
        C, S, F = stations[j]
        w = t // F * F
        if t % F > 0:
            w += F
        w = max(S, w)
        t = w + C
    print(t)

print(0)

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

Solution (Python):
def start(x,s,f):
  
  if x <= s:
    return s
  return (x+f-1)//f*f

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

def F(i):
  x = 0
  for c,s,f in CSF[i:]:
    x = start(x,s,f)
    x += c
  return x

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

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


def solve(i):
    curStation = i
    ans = CSF[curStation][1]
    while curStation < N-1:
        if ans >= CSF[curStation][1]:
            t = (ans - CSF[curStation][1]) // CSF[curStation][2]
            if (ans - CSF[curStation][1]) % CSF[curStation][2] == 0:
                ans = CSF[curStation][1] + CSF[curStation][2] * t
            else:
                ans = CSF[curStation][1] + CSF[curStation][2] * (t+1)
        else:
            ans = CSF[curStation][1]
        ans += CSF[curStation][0]
        curStation += 1
        if curStation == N-1:
            break
    return ans


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

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

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

print(0)

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

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