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):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

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

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

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

for i in range(0,n-1):
    print(kaisuu(s,i))

print(0)

Solution (Python):
from sys import stdin

n = int(input())
s = [stdin.readline().rstrip().split() for i in range(n-1)]

def kaisuu(s,i):
    t = int(s[i][0]) + int(s[i][1])
    if i != n-1:
        for j in range(i+1,n-1):
            if  t <= int(s[j][1]):
                t = int(s[j][0]) + int(s[j][1])
            elif t % int(s[j][2]) == 0:
                t = t + int(s[j][0])
            else:
                t = t + int(s[j][0]) + (int(s[j][2]) - t % int(s[j][2]))
    return t

for i in range(0,n-1):
    print(kaisuu(s,i))

print(0)

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    train = [LI() for _ in range(n - 1)]

    for i in range(n):
        res = 0
        for c, s, f in train[i:]:
            if res <= s:
                res = c + s
            else:
                res += (f - (res - s) % f) % f + c

        print(res)


if __name__ == '__main__':
    main()

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

min_time = [0 for _ in range(N)]
for i in range(N-1):
    speed, start, interval = map(int, input().split())
    min_time[i] += start + speed
    for j in range(i):
        if min_time[j] - start < 0:
            min_time[j] = start
        else:
            while (min_time[j] - start) % interval != 0:
                min_time[j] += 1
        min_time[j] += speed

for ans in min_time:
    print(ans)

Solution (Python):
import math

n = int(input())
c = [0] * n
s = [0] * n
f = [0] * n

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

for i in range(1, n + 1):
    t = 0
    for j in range(i, n):
        if t <= s[j]:
            t = s[j] + c[j]
        else:
            t = math.ceil(t / f[j]) * f[j] + c[j]
    print(t)

Solution (Python):



import math


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

ans = [0] * n

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

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

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)
t = [0]*N

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

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

for j in range(N):
    if j == N - 1:
        print(0)
        exit()
    cc, ss, ff = CSF[j]
    t = ss + cc
    for i in range(j + 1, N - 1):
        c, s, f = CSF[i]
        if t <= s:
            t = s + c
        else:
            num = ceil(t / f)
            t = num * f + c
    print(t)

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

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        
        if total_time < s:
            time += s - total_time
        
        else:
            time += (f - total_time % f) % f
        
        time += c
        total_time += time
    print(total_time)

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

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

for i in range(N-1):
    ans = 0
    for j in range(i, N-1):
        if ans <= train[j][1]:
            ans = train[j][1]
        elif ans%train[j][2] != 0:
            ans += train[j][2] - (ans%train[j][2])
        
        ans += train[j][0]
    print(ans)

print(0)

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

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

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

Solution (Python):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
CSF = []
for i in range(1, N):
    CSF.append(LI())

for i in range(N-1):
    
    current = i
    time = 0
    for csf in CSF[i:]:
        if time < csf[1]:
            
            time = csf[1] + csf[0]
        elif time % csf[2] == 0:
            time += csf[0]
        else:
            
            div = time % csf[2]
            time -= div
            time += csf[2]
            time += csf[0]
        current += 1
    print(time)

print(0)

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

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

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

Solution (Python):
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
  x,y,z=map(int,input().split())
  c.append(x)
  s.append(y)
  f.append(z)
def needtime(t,i):
  if s[i]>=t:
    T=s[i]
  else:
    if (t-s[i])%f[i]==0:
      T=t
    else:
      T=t+f[i]-(t-s[i])%f[i]
  return T+c[i]
for i in range(n):
  t=0
  for j in range(i,n-1):
    t=needtime(t,j)
  print(t)

Solution (Python):


n = int(input())

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

for i in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

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

print(0)

Solution (Python):
N=int(input())
C=[0]*N
S=[0]*N
F=[0]*N

def solve(n):
    ans=0
    for i in range(n,N):
        if ans < S[i]:
            ans = S[i]
        a = ans % F[i]
        if a > 0:
            ans += F[i] - a
        ans += C[i]
    return ans

for i in range(1,N):
    C[i],S[i],F[i]=map(int,input().split())
for i in range(1,N+1):
    print(solve(i))

Solution (Python):
n = int(input())
l = []
for _ in range(n-1):
    l.append([int(i) for i in input().split()])
for j in range(n):
    l_ = l[j:]
    c = 0
    for i in range(n-1-j):
        if c <= l_[i][1]:
            c = l_[i][1]
        elif (c % l_[i][2] != 0):
            c = (c // l_[i][2] + 1) * l_[i][2]
        else:
            c = (c // l_[i][2]) * l_[i][2]
        c += l_[i][0]
    print(c)

Solution (Python):
import math
import sys
N = int(input())
if N == 1:
    print(0)
    sys.exit()
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):
    cur = 0
    for j in range(i, N-1):
        if cur <= s[j]:
            cur = s[j] + c[j]
        else:
            cur += (s[j]+f[j]*math.ceil((cur-s[j])/f[j])-cur) + c[j]
    print(cur)

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

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

for i in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

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

print(0)

Solution (Python):
N = int(input())
train = [[] for _ in range(N)]
L = []
for cnt in range(N - 1):
    l = list(map(int,input().split()))
    L.append(l)

from math import ceil

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        k = max(0,ceil((now - L[i][1]) / L[i][2]))
        now = L[i][1] + L[i][2] * k
        now += L[i][0]
    print(now)

Solution (Python):
import math
N = int(input())
tc,ts,tf = 0,0,0
C, S, F, =[], [], []
t = 0
for i in range(N-1):
    tc,ts,tf = map(int,input().split())
    C.append(tc)
    S.append(ts)
    F.append(tf)

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

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

def gotoN(start): 
	global C,S,F
	if start==N:
		return 0
	else:
		stn = start
		t = S[stn-1]
		while stn < N:
			t = max(((t-1)//F[stn-1]+1)*F[stn-1], S[stn-1])+C[stn-1]
			stn += 1
		return t

for i in range(1,N+1):
	print(gotoN(i))

Solution (Python):

n = int(input())


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



for i in range(n-1):

    ans = csf[i][0] + csf[i][1]

    for j in range(i+1,n-1):
        here = csf[j]
        
        ans = max(ans,here[1])
        
        rm = ans % here[2]
        if rm != 0:
            ans += here[2] - rm
            
        ans += here[0]


    print(ans)

print(0)

Solution (Python):
from math import ceil


def solve(string):
    n, *csf = map(int, string.split())
    f_list = []
    for c, s, f in zip(csf[::3], csf[1::3], csf[2::3]):
        f_list = [c + ceil((max(_f, s)) / f) * f for _f in f_list]
        f_list.append(c + s)
    f_list.append(0)
    return "\n".join([str(_f) for _f in f_list])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n - 1)])))

Solution (Python):
N = int(input())
inputs = [list(map(int, input().split())) for i in range(N-1)]
if len(inputs) != N:
  inputs. append([0, 0, 1])

for i in range(N):
  reach = 0
  for j in range(i, N):
    info = inputs[j]
    if reach < info[1]:
      reach = info[1]
    if (reach-info[1])%info[2] != 0:
      reach += (info[2] - (reach-info[1])%info[2])
    reach += info[0]
    
  print(reach)

Solution (Python):
n=int(input())
ls=[]
for i in range(n-1):
  c,s,f=map(int,input().split())
  ls.append(s)
  ls=list(map(lambda x:(x+c+(0 if x%f==0 else (f-x%f)) if s<=x else s+c),ls))
ls=ls+[0]
print(*ls,sep="\n")

Solution (Python):
from math import ceil
n = int(input())
cur = [0]*n
for i in range(n-1):
	c,s,f = map(int,input().split())
	for j in range(i+1):
		cur[j] = max(s,ceil(cur[j]/f)*f)+c
print(*cur,sep='\n')

Solution (Python):
from math import ceil

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

for i in range(n-1):
	time = CSF[i][1]+CSF[i][0]
	for j in range(i+1,n-1):
		if (time-CSF[j][1])%CSF[j][2] != 0 or time-CSF[j][1]<0:
			time = max(CSF[j][1],CSF[j][2]*(ceil(time/CSF[j][2])))
		time += CSF[j][0]
	print(time)
print(0)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007


def A():
    return


def B():
    return


def C():
    n = I()
    a = LIR(n-1)
    for i in range(n):
        t = 0
        x = i
        while x < n-1:
            if t < a[x][1]:
                t = a[x][1]
            t += (a[x][2]-t)%a[x][2]
            t += a[x][0]
            x += 1
        print(t)


def D():
    def check(n):
        if n == 1:
            return False
        i = 2
        while i*i <= n:
            if n%i == 0:
                return False
            i += 1
        return True
    f = [0 for i in range(100001)]
    for i in range(1,100001):
        f[i] += f[i-1]
        if check(i):
            if check((i+1)//2):
                f[i] += 1
    q = I()
    for i in range(q):
        l,r = LI()
        print(f[r]-f[l-1])


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    C()

Solution (Python):
def tcalc(station):
  time = 0
  for i in range(station-1,n-1):
    f = l[i][2]
    s = l[i][1]
    c = l[i][0]
    time = max(((time-1)//f+1)*f, s)+c
  return time
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n-1)]
for j in range(1,n+1):
  print(tcalc(j))

Solution (Python):
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]
for start in range(N):
    t = 0
    for i in range(start, N-1):
        C, S, F = CSF[i]
        if t<S:
            t = S
        else:
            t += (F - (t - S)%F)%F
        t += C
    print(t)

Solution (Python):
n=int(input())
al=[];bl=[];cl=[]
for _ in range(n-1):
  x,y,z=map(int,input().split())
  al.append(x);bl.append(y);cl.append(z)
for i in range(n-2):
  time=al[i]+bl[i]
  for j in range(i+1,n-1):
    if time<=bl[j]:
      time=bl[j]+al[j]
    else:
      time=time+(-1*time)%cl[j]+al[j]
  print(time)
print(al[-1]+bl[-1])
print(0)

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
D=[]
for i in range(n-1):
    D.append(IL())
for i in range(n):
    t=0
    for j in range(i,n-1):
        if t<D[j][1]:
            t=D[j][1]+D[j][0]
        else:
            for k in range(100):
                if (t+k)%D[j][2]==0:
                    t+=k+D[j][0]
                    break
    print(t)

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

CSFn = [[int(j) for j in input().split()] for i in range(N - 1)]


def next(s):
    t = 0

    for Ci, Si, Fi in CSFn[s:]:
        
        if t < Si:
            t = Si

        
        elif t % Fi:
            t += Fi - t % Fi

        
        t += Ci

    return t


def main():
    
    for i in range(N - 1):
        t = next(i)
        print(t)

    print(0)

    return


main()

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 next(s, t):
    
    if t < S[s]:
        t = S[s]

    
    elif t % F[s]:
        t += F[s] - t % F[s]

    
    t += C[s]

    return t


def main():
    
    for i in range(N - 1):
        t = next(i, 0)

        
        for j in range(i + 1, N - 1):
            t = next(j, t)

        print(t)

    print(0)

    return


main()

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

Solution (Python):
def special_trains(N: int, CSF: list) -> list:
    res = []
    for i in range(N):
        t = 0
        for c, s, f in CSF[i:]:
            if t < s:
                t = s
            if t % f != 0:
                t = (t + f) - (t % f)
            t = t + c
        res.append(t)
    return res


if __name__ == "__main__":
    N = int(input())
    CSF = [tuple(map(int, input().split())) for _ in range(N-1)]
    ans = special_trains(N, CSF)
    for a in ans:
        print(a)

Solution (Python):
N = 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, raw_input().split())

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

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

result = []
for i in range(n-1):
    t = e[i][0] + e[i][1]
    for x in e[i+1:]:
        if t <= x[1]:
            t = x[0] + x[1]
            continue
        t = math.ceil((t-x[1])/x[2])*x[2] + x[1] + x[0]
    result .append(t)

result.append(0)
for x in result:
    print(x)

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

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

ans = []
for i in range(N-1):
    t = csf[i][1] + csf[i][0]
    for j in range(i+1,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]
    ans.append(t)
ans.append(0)
for a in ans: print(a)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    A = [0 for _ in range(N)]
    for i in range(N-1):
        C, S, F = map(int, input().split())
        for j in range(i+1):
            a = A[j]
            if a <= S:
                A[j] += C + (S - a)
            elif a % F == 0:
                A[j] += C
            else:
                A[j] += C + F - (a % F)
    for a in A:
        print(a)



if __name__ == '__main__':
    main()

Solution (Python):
import math
N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())
for i in range(N):
    x = S[i] + C[i]
    for j in range(i+1,N-1):
        if x < S[j]:
            x = S[j] + C[j]
        else:
            x = S[j] + F[j] * math.ceil((x - S[j]) / F[j]) + C[j]
    print(x)

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

for i in range(N):
  t = 0
  for j in range(i,N-1):
    if(t < CSF[j][1]):
      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):
def calc(start, C, S, F):
    time = 0
    pos = start
    while pos < N:
        
        
        if time == 0: 
            time += S[start] + C[start]
        else:
            if time < S[pos]:
                time = S[pos] + C[pos]
            else:
                if (time - S[pos]) % F[pos] != 0:
                    time += F[pos] - ((time - S[pos]) % F[pos]) + C[pos]
                else:
                    time += C[pos] 
        pos += 1
    return time

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

for i in range(1, N+1):
    print(str(calc(i, C, S, F)))

Solution (Python):
def main():
    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):
        cur, t = i, 0
        while cur < N-1:
            t += (F[cur] - t) % F[cur]
            t = max(t, S[cur])
            t += C[cur]
            cur += 1
        print(t)
    print(0)


if __name__ == "__main__":
    main()

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

Solution (Python):
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
ans = []
for i in range(len(l)):
    m = l[i][1]
    for j in range(i,len(l)):
        if m<l[j][1]:
            m = l[j][1]+l[j][0]
        elif m==l[j][1] or (m-l[j][1])%l[j][2]==0:
            m += l[j][0]
        else:
            next = l[j][2]-m%l[j][2]
            m += next+l[j][0]
    ans.append(m)
ans.append(0)
for i in ans:
    print(i)

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

a = [list(map(int,input().split())) for i in range(n-1)]
su = 0 
for i in range(n):
    if i == n-1:
        print(0)
    else:
        for j in range(i,n-1):
            if su < a[j][1]:
                su = a[j][1] + a[j][0]
            elif su % a[j][2] == 0:
                su += a[j][0]
            else:
                su += a[j][2] - (su - a[j][1]) % a[j][2] + a[j][0]
        print(su)
        su = 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])


def dis(i):
    if i<n-2:
        cnt=X[i][1]+X[i][0]
        while i<n-2:
                if cnt<X[i+1][1]:
                    cnt=X[i+1][1]+X[i+1][0]
                else:
                    if cnt%X[i+1][2]!=0:
                        cnt+=X[i+1][2]-(cnt%X[i+1][2])+X[i+1][0]
                    else:
                        cnt+=X[i+1][0]
                i+=1
        return cnt
    elif i==n-2:
        return X[i][1]+X[i][0]
    elif i==n-1:
        return 0
    

for i in range(n):
    print(dis(i))

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

for i in range(n):
    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+=l[j][2]-t%l[j][2]
        t+=l[j][0]
    print(t)

Solution (Python):
def next(t, f):
    if t % f: return t + f - (t%f)
    else: return t
def time(t, i):
    if i == n-1: return t
    else:
        c, s, f = info[i]
        if t <= s: return time(s+c, i+1)
        else: return time(next(t, f)+c, i+1)
n = int(input())
info = [tuple(map(int, input().split())) for _ in range(n-1)]
for i in range(n):
    print(time(0, i))

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


def arrivalTime( time, loc ):
    if loc == N-1: return time
    if time <= A[loc][1]:
        return arrivalTime( A[loc][1]+A[loc][0], loc+1 )
    else:
        n = (time - A[loc][1] + (A[loc][2] - 1) ) // A[loc][2]
        return arrivalTime( A[loc][1]+A[loc][0] + n*A[loc][2], loc+1 )

for i in range(N-1):
    print( arrivalTime( A[i][1], i ) )
print( 0 )

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

Solution (Python):
n = int(input())
index=0
timeCounterL=[0]*n
while index < n-1:
    c, s, f = map(int, input().split())
    index2=0
    while index2 < n:
        if index2 == index:
            timeCounterL[index2]+=s+c
        else:
            if index2 > index:
                break
            else:
                if timeCounterL[index2] > s:
                    amari = timeCounterL[index2]-s
                    if amari%f == 0:
                        timeCounterL[index2]+=c
                    else:
                        extraT = amari%f
                        timeCounterL[index2]+=f-extraT+c
                else:
                    timeCounterL[index2] = s+c
        index2+=1
    index+=1

for time in timeCounterL:
    print(time)

Solution (Python):
N = int(input())
A = [[int(i) for i in input().split()] for i in range(N - 1)]

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

Solution (Python):
N = int(input())
A = [[int(i) for i in input().split()] for i in range(N - 1)]

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

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

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

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

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

for t in time:
  print(t)

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

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

Solution (Python):

N=int(input())
csf=[]
for n in range(N-1):
	csf.append(list(map(int,input().split())))
for nn in range(N):
	
	t=0
	for n in range(nn,N-1):
		
		if t>csf[n][1]:
			t=csf[n][1]+((t-csf[n][1]+csf[n][2]-1)//csf[n][2])*csf[n][2]+csf[n][0]
			
		else:
			t=csf[n][1]+csf[n][0]
		
	print(t)