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())
CSF=[]

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

for i in range(N):
    T=[]
    for j in range(i,N):
        if j==i:
            T.append(0)
        else:
            Next_T=max(-(-T[-1]//CSF[j-1][2])*CSF[j-1][2],CSF[j-1][1])+CSF[j-1][0]
            T.append(Next_T)
    
    print(T[-1])

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

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

Solution (Python):
import math

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

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if t >= csf[j][1]:
            t = math.ceil(t/csf[j][2])*csf[j][2]+csf[j][0]
        else: t = csf[j][1] + csf[j][0]
    print(t)
print(0)

Solution (Python):

def resolve():
    N=int(input())
    C, S, F = [0] * (N-1), [0] * (N-1), [0] * (N-1)
    for d in range(N-1):
        C[d], S[d], F[d] = map(int, input().split())

    for l in range(N-1):
        time=0
        for i in range(l,N-1):
            if time<=S[i]:
                time=S[i]+C[i]
                continue
            else:
                time=S[i]+F[i]*(-(-(time-S[i])//F[i]))+C[i]
        print(time)
    print(0)





resolve()

Solution (Python):


N = int(input())    
C_list = []         
S_list = []         
F_list = []         

for n 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 - 1):

    t = 0
    for j in range(i, N - 1):
        
        
        
        if t <= S_list[j]:
            t = S_list[j] + C_list[j]
        
        
        elif t % F_list[j] == 0:
            t += C_list[j]

        
        else:
            t += F_list[j] - (t % F_list[j]) + C_list[j]

    print(t)

print(0)

Solution (Python):




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


if __name__ == "__main__":
    main()

Solution (Python):
def solve():
    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 fr in range(N-1):
        t = S[fr]
        for to in range(fr+1,N):
            t += C[to-1]
            if to != N-1:
                waittime = 0
                if t < S[to]:
                    waittime = S[to] - t
                elif t % F[to] == 0:
                    waittime = 0
                else:
                    waittime = F[to] - (t%F[to])
                t += waittime
        print(t)
            
    print(0)

if __name__ == '__main__':
    solve()

Solution (Python):
import math

N = int(input())
ARR = []

for i in range(N-1):
    ARR.append([int(s) for s in input().split(" ")])


def calculate(n, arr):
    result = []
    for i in range(n-1):
        m = arr[i][1] + arr[i][0]
        for j in range(i+1,n-1):
            nextStart = arr[j][1]
            nextCost = arr[j][0]
            nextFrequency = arr[j][2]

            if m <= nextStart:
                m = nextStart

            if m  > nextStart:
                m = nextStart + math.ceil((m - nextStart)/ nextFrequency)*nextFrequency

            m = m + nextCost
        result.append(m)

    result.append(0)
    return result


result = calculate(N, ARR)


for res in result:
    print(res)

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

for j in range(n-1):
    now=0
    for i in range(j,n-1):
        if csf[i][1]>=now:
            now=csf[i][1]+csf[i][0]
        else:
            now=csf[i][1]-((csf[i][1]-now)//csf[i][2])*csf[i][2]+csf[i][0]
    print(now)
print(0)

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

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

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

Solution (Python):
def main():
    N = int(input())
    time = [0]*N
    data = [list(map(int,input().split()))for _ in range(N-1)]
    for i in range(N-1):
        for j  in range(i,N-1):
            c,s,f = data[j]
            if time[i] > s:
                tmp = time[i]-s
                if tmp % f != 0:
                    tmp //= f
                    tmp += 1
                else:
                    tmp //= f
                time[i] = s+tmp*f+c
            else:
                time[i] = s+c
    for t in time:
        print(t)

if __name__ == "__main__":
    main()

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

def arrive_time(i,s): 
  if i == N-1:
    return s
  if s>B[i]:
    
    start = (s-B[i]+C[i]-1)//C[i]*C[i]+B[i]
  else:
    start = B[i]
  return arrive_time(i+1,start+A[i])
ans = [0]*(N)
for i in range(N):
  ans[i] = arrive_time(i,0)

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

Solution (Python):
n = int(input())-1
a = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    t = 0
    for c,s,f in a[i:n]:
        if t<=s: t = s+c
        else:t = s+-(-(t-s)//f)*f+c
    print(t)
print(0)

Solution (Python):
n=int(input())
C=[0]*(n-1)
S=[0]*(n-1)
F=[0]*(n-1)
for i in range(n-1):
  C[i],S[i],F[i]=map(int,input().split())
for i in range(n-1):
  ans=0
  for j in range(i,n-1):
    ans=max((ans+F[j]-1)//F[j]*F[j],S[j])+C[j]
  print(ans)
print(0)

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

ans = [0]*(n+1)
for i in range(1, n):
    t = S[i]+C[i]
    for j in range(i+1, n):
        t = S[j]+C[j]+[0, -(-(t-S[j])//F[j])*F[j]][S[j] < t]
    ans[i] = t

print(*(x for x in ans[1:]), sep="\n")

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

stations = []
for n in range(N-1):
  tmp = tuple(map(int, input().split()))
  stations.append(tmp)

for index in range(len(stations)):
  time = 0
  sum_time = 0
  for c, s, f in stations[index:]:
    if time <= s:
      time = s + c
    else:
      diff = time - s
      count = math.ceil(diff/f)
      time = s + f*count + c
  print(time)
print(0)

Solution (Python):
n=int(input())
c=[0 for _ in range(n-1)]
s=c[:]
f=c[:]
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
for i in range(n-1):
  t=0
  for j in range(i,n-1):
    cc,ss,ff=c[j],s[j],f[j]
    if t>=ss:
      if t%ff==0:
        t+=t%ff+cc
      else:
        t+=(ff-t%ff)+cc
    else:
      t=ss+cc
      
  print(t)






print(0)

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

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

for i in range(n):
    ans=0
    for j in range(i,n-1):
        c,s,f=map(lambda x:x,csf[j])
        if ans<=s: ans=s+c
        else: ans=math.ceil(ans/f)*f+c

    print(ans)

Solution (Python):
icase=0
if icase==0:
    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)
elif icase==1:
    n=3
    c=[6,1]
    s=[5,10]
    f=[1,1]
elif icase==2:
    n=4
    c=[12,52,99]
    s=[24,16,2]
    f=[6,4,2]
elif icase==3:
    n=4
    c=[12,44,66]
    s=[13,17,4096]
    f=[1,17,64]

def nipf(ii,tt,s,f):

    if tt<=s[ii]:
        return 0
    else:
        n=(tt-s[ii]-1)//f[ii]+1
        return n

for i in range(n-1):
    tt=s[i]+c[i]
    for ii in range(i+1, n-1):

        nip=nipf(ii,tt,s,f)

        tt=s[ii]+c[ii]+nip*f[ii]
    print(tt)
print(0)

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

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

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

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

for i,csf in enumerate(CSF):
    c,s,f=csf[0],csf[1],csf[2]
    ans=c+s
    for j in range(i+1,N-1):
        csf_=CSF[j]
        c_,s_,f_=csf_[0],csf_[1],csf_[2]
        if ans<s_:
            ans=s_
        elif ans%f_!=0:
            ans=ans+f_-ans%f_
        ans+=c_
    print(ans)
print(0)

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

for i,csf in enumerate(CSF):
    c,s,f=csf[0],csf[1],csf[2]
    ans=c+s
    for j in range(i+1,N-1):
        csf_=CSF[j]
        c_,s_,f_=csf_[0],csf_[1],csf_[2]
        while True:
            if (ans>=s_) and (ans%f_==0):
                ans+=c_
                break
            ans+=1
    print(ans)
print(0)

Solution (Python):
n=int(input())
c,s,f=[0]*(n-1),[0]*(n-1),[0]*(n-1)
for i in range(n-1):
  c[i],s[i],f[i]=map(int,input().split())
arr=[0]*n
for i in range(n-1):
  for j in range(i,n-1):
    l=s[j]
    if arr[i]>l:
      while arr[i]>l:
        l+=f[j]
    arr[i]=l
    arr[i]+=c[j]
  print(arr[i])
print(0)

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

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

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

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

Solution (Python):
from sys import stdin 
input=stdin.readline
def main():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=(now+d-1)//d*d+a
    print(now)
if __name__=="__main__":
  main()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=(now+d-1)//d*d+a
    print(now)
if __name__=="__main__":
  main()

Solution (Python):
import sys
input = sys.stdin.readline
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=(now+d-1)//d*d+a
    print(now)
if __name__=="__main__":
  f()

Solution (Python):
import sys
input = sys.stdin.readline
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=-(-now//d)*d+a
    print(now)
if __name__=="__main__":
  f()

Solution (Python):
import sys
input = sys.stdin.readline
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Solution (Python):
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Solution (Python):
def f():
  n=int(input())
  l=[list(map(int,input().split())) for i in range(n-1)]+[[0,0,1]]
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Solution (Python):
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]+[[0,0,1]]
al=[]
mati=0
for i in range(n):
  now=l[i][1]+l[i][0]
  for j in range(i+1,n):
    now=l[j][0]+l[j][1]-(-max(0,now-l[j][1])//l[j][2])*l[j][2]
  al.append(now)
print(*al,sep="\n")

Solution (Python):

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

import math
for c in range(N):
    ret = 0
    for next_c in range(c, N-1):
        if ret <= S[next_c]:
            ret = S[next_c]

        else:
            i = int(math.ceil((ret - S[next_c]) / F[next_c]))
            ret = S[next_c] + F[next_c] * i

        ret += C[next_c]

    print(ret)

Solution (Python):
from math import ceil

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

for i in range(n):
    if i != n-1:
        time = 0
        for k in range(i, n-1):
            if time < s[k]:
                time += s[k] - time
            else:
                time += s[k] + ceil((time-s[k])/f[k])*f[k] - time
            time += c[k]
        print(time)
    else:
        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())
time=0
ans0=[0]
for j in range(N-1):
    time=0
    for i in range(j,N-1):
        if time<=s[i]:
            time=s[i]+c[i]
            ans0.append(time)
        else:
            q=time//f[i]
            if time%f[i]==0:
                q-=1
            time=(q+1)*f[i]+c[i]
    print(time)
print(0)

Solution (Python):
import sys

N = int(input())

c = [list(map(int, sys.stdin.readline().split())) for i in range(N-1)]

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

print(0)

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

for ikimasuyo in range(N):
  t = 0
  for i in range(ikimasuyo, N - 1):
    c, s, f = ekis[i]
    if t < s:
      t = s + c
    elif t >= s:
      t = -((s - t) // f) * f + s + c
    
  print(t)

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

def next_station(Time,s):
    Time+=path[s][0]
    ns=s+1
    if ns==N-1:
        print(Time)
    elif Time<=path[ns][1]:
        Time=path[ns][1]
        next_station(Time,ns)
    else:
        if Time%path[ns][2]==0:
            next_station(Time,ns)
        else:
            Time+=(path[ns][2]-Time%path[ns][2])
            next_station(Time,ns)

for i in range(N-1):
    next_station(path[i][1],i)
print(0)

Solution (Python):

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

def train(i, t):
    if i==n-1:
        return t
    
    c, s, f = csf[i]
    
    if t < s:
        return train(i+1, s+c)
    else:
        return train(i+1, -(-t//f)*f+c)
    
for i in range(n):
    print(train(i, 0))

Solution (Python):
import math
N=int(input())
numbers=[]
for a in range(N-1):
    list=[]
    C,S,F=input().split()
    list.append(int(C))
    list.append(int(S))
    list.append(int(F))
    numbers.append(list)
if N==1:
    print(0)
elif N==2:
    print(numbers[0][0]+numbers[0][1])
    print(0)
else:
    for a in range(N - 1):
        b = numbers[a][0] + numbers[a][1]
        while a < N - 2:
            if b>=numbers[a+1][1]:
                c = b - numbers[a + 1][1]
                d =math.ceil (c / numbers[a + 1][2])
                e = numbers[a + 1][1] + numbers[a + 1][2] * d
                b = e + numbers[a + 1][0]
            else:
                b=numbers[a+1][1]+numbers[a+1][0]
            a+=1
        print(round(b))
    print(0)

Solution (Python):
def solve():
    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())
    
    ans = [0] * N
    for i in range(N - 1):
        t = C[i] + S[i]
        for j in range(i + 1, N - 1):
            if S[j] <= t and t % F[j] == 0:
                t += C[j]
            elif t < S[j]:
                t = C[j] + S[j]
            else:
                t += C[j] + F[j] - (t % F[j])
        ans[i] = t
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    solve()

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

Solution (Python):
n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]
ans = []
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]:
      time = csf[j][1]
    elif (time-csf[j][1]) % csf[j][2] != 0:
      time = csf[j][1]+((time-csf[j][1])//csf[j][2]+1)*csf[j][2]
    time += csf[j][0]
  ans.append(time)
ans.append(0)
for k in range(n):
  print(ans[k])

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:
            t+=c[j]
            continue
        else:
            t=t+f[j]-(t%f[j])
        t+=c[j]
    print(t)

Solution (Python):
n=int(input())
cs=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    t=0
    for c,s,f in cs[i:]:
        t=max(t,s)
        if t%f:
            t+=-t%f
        t+=c
    print(t)
print(0)

Solution (Python):
from math import ceil


def train(i, t):
    if i == n - 1:
        return t
    c, s, f = d[i]
    tt = f * ceil(t / f) if t > s else s
    return train(i + 1, tt + c)


if __name__ == '__main__':
    n = int(input())
    d = [[int(i) for i in input().split()] for _ in range(n - 1)]
    print(*[train(i, 0) for i in range(n)], sep="\n")

Solution (Python):
def main():
  import math
  n=int(input())
  CSF=[list(map(int,input().split())) for _ in [0]*(n-1)]
  t=0
  for i in range(n-1):
    t=CSF[i][1]
    for csf in CSF[i:]:
      c,s,f=csf[0],csf[1],csf[2]
      t=math.ceil(max(s,t)/f)*f+c    
    print(t)
  print(0)
if __name__=='__main__':
  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)

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
        elif t % F[j] !=0:
            t += F[j] - (t%F[j])
        t += C[j]
    print(t)

Solution (Python):
n = int(input())
res = [0]*n

for x in range(n-1):
  c,s,f = map(int,input().split())
  for y in range(x+1):
    if res[y] < s:
      res[y] = s + c
    else:
      res[y] = ((res[y]-1)//f +1)*f + c
  
for asldijfgherab in range(n):
  print(res[asldijfgherab])

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

Solution (Python):
n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t < s[m][1]:
                t = s[m][1]
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)

Solution (Python):
n=int(input())
ab = []
for _ in range(n-1):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
CSF = [LIST() for i in range(N-1)]

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

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

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

for i in range(N-1) :
    temp = CSF[i][1] + CSF[i][0]
    t = i + 1
    while t < N-1 :
        if temp < CSF[t][1] :
            temp = CSF[t][1] + CSF[t][0]
        else :
            temp = ((temp+CSF[t][2]-1)//CSF[t][2])*CSF[t][2] + CSF[t][0]
        t += 1
    ans[i] = temp

for answer in ans :
    print(answer)

Solution (Python):
n=int(input())
L=[[0,0,0] for _ in range(n)]
for i in range(n-1):
    c,s,f=map(int,input().split())
    L[i]=[c,s,f]
for j in range(n):
    ans=0
    if j==n:
        print(0)
    else:
        for k in range(len(L)-1):
            if k==0:
                ans+=L[k][1]
                ans+=L[k][0]
            else:
                ans=max(-(-ans//L[k][2])*L[k][2],L[k][1])
                ans+=L[k][0]
        print(ans)
        L.pop(0)

Solution (Python):
import sys
import numpy as np


n = int(input())


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

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

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())

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

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)
time = 0


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

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 



 




 


 





 


 



def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
inf = float('inf')
mod = 1000000007
 

def main():
    N = inputInt()
    csf = []
    for _ in range(N-1):
        c,s,f = inputMap()
        csf.append((c,s,f))
        
    ans = []
    for i in range(N-1):
        c,s,f = csf[i]
        tmp = s+c
        for j in range(i+1,N-1):
            c,s,f = csf[j]
            
            if tmp < s:
                tmp = tmp + (s-tmp) + c
            else:
                if (tmp-s)%f == 0:
                    tmp = tmp + c
                else:
                    tmp = tmp + ((-(-(tmp-s) // f))*f + s)-tmp + c
        print(tmp)
        
    print(0)
    
     




def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
 
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y
         
if __name__ == "__main__":
	main()

Solution (Python):
import math
import itertools
import statistics

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

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

print(0)

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

        while s2 < ans[i]:
            s2 += f[j]
        ans[i] = c[j] + s2

for i in range(n):
    print(ans[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):
    t = S[i]
    while i != (n-1):
        if t < S[i]:  
            wait = (S[i] - t)
        else:
            r = (t - S[i])%F[i]
            if r == 0:
                wait = 0 
            else:
                wait = F[i] - r
        t += wait
        t += C[i]  
        i += 1
    print(t)
print(0)

Solution (Python):




import sys
read = sys.stdin.readline


def read_a_int():
    return int(read())


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
C, S, F = read_col(N - 1, 3)


def f(i):
    
    now = S[i]  
    for j in range(i, N - 2):  
        now += C[j]  
        
        f, s = F[j + 1], S[j + 1]
        
        now_tmp = (int((now - 0.5) // f) + 1) * f
        now = max(now_tmp, s)
    now += C[N - 2]
    return now


for i in range(N - 1):
    print(f(i))
print(0)

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

ans_list=[]

for i in range(n):
    now=0
    for g in range(i,n-1):
        c,s,f=csf[g]
        if now<=s:
            now=s
        if now%f==0:
            now+=c
        else:
            now+=(f-now%f)+c
    ans_list.append(now)

for l in range(n):
    print(ans_list[l])