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):
import sys

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

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

DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y
from collections import namedtuple

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


if __name__ == '__main__':
    main()

Solution (Python):
def abc084_c():
  n = int(input())
  train = [tuple(map(int, input().split())) for _ in range(n-1)]

  def arrive_time(st):
    time = 0
    for i in range(st, n-1):
      c, s, f = train[i]
      
      departure = f * ((max(time, s) + f - 1) // f)
      
      time = departure + c
      
    return time

  for i in range(n):
    ans = arrive_time(i)
    print(ans)

abc084_c()

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

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

for i in range(N):
    t = 0
    for j in range(i, N - 1):
        if t <= lst_s[j]:
            t = lst_s[j]
        else:
            t = (t + lst_f[j] - 1) // lst_f[j] * lst_f[j]
        t += lst_c[j]
    print(t)

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

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


for i in range(N):
  sec=0
  for j in range(i,N-1):
    c,s,f=csflist[j]
    if sec<s:
      sec=s
    elif sec%f>0:
      sec+=f-(sec%f)
    sec+=c
    
  print(sec)

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


def next(i,t):
    if t<=lst[i][1]:
        return lst[i][0]+lst[i][1]
    elif t%lst[i][2]==0:
        return t+lst[i][0]
    else:
        return t+lst[i][0]+lst[i][2]-(t%lst[i][2])

for i in range(n-1):
    time = 0
    for j in range(i,n-1):
        time = next(j,time)
    print(time)
print(0)

Solution (Python):
ma = lambda : map(int,input().split())
ni = lambda : int(input())
import math
ceil = math.ceil
n = ni()
csf = []
for i in range(n-1):
    csf.append(tuple(ma()))
for i in range(n-1):
    ans = csf[i][1] + csf[i][0]
    for j in range(i+1,n-1):
        if ans<=csf[j][1]:
            ans =csf[j][1]+csf[j][0]
        else:
            ans = ceil(ans/csf[j][2])*csf[j][2] +csf[j][0]
    print(ans)
print(0)

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

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


for i in range(N):
  sec=0
  for j in range(i,N-1):
    c,s,f=csflist[j]
    if sec<s:
      sec=s
    elif sec%f>0:
      sec+=f-(sec%f)
    sec+=c
    
  print(sec)

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

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


for i in range(N-1):
  sec=0
  for j in range(i,N-1):
    c,s,f=csflist[j]
    if sec<=s:
      sec=s
    else:
      sec=f*((sec-s-1)//f+1)+s
    sec+=c
    
  print(sec)
  
print(0)

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

if __name__ == '__main__':
    main()

Solution (Python):
import math

n = int(input())
csf = [list(map(int, input().split())) for i in range(n-1)]
ANS = []
for i in range(n):
  ans = 0
  for c,s,f in csf[i:]:
    if ans <= s:
      ans = s + c
    else:
      ans = s + math.ceil((ans-s)/f) * f + c
  ANS.append(ans)
for i in ANS:
  print(i)

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

def to_sta(time_used, sta_num):
    if time_used < s_ls[sta_num]:
        return s_ls[sta_num] + c_ls[sta_num]
    else:
        if (time_used - s_ls[sta_num]) % f_ls[sta_num] == 0:
            return time_used + c_ls[sta_num]
        else:
            return time_used + c_ls[sta_num] + f_ls[sta_num] - ((time_used - s_ls[sta_num]) % f_ls[sta_num])
for start in range(n):
    time_used = 0
    for nex in range(start, n-1):
        time_used = to_sta(time_used, nex)
    print(time_used)

Solution (Python):
import sys
input = sys.stdin.readline
n = int(input())
chk = []
for i in range(n-1):
  c = [int(i) for i in input().split()]
  chk.append(c)
  
if n == 1:
  print(0)
  exit()
  
for i in range(n-2):
  ans = chk[i][1]
  ans += chk[i][0]
  for j in range(i,n-2):
    if chk[j+1][1] > ans:
      ans = chk[j+1][1]+chk[j+1][0]
    else:
      p = (ans-chk[j+1][1]-1)//chk[j+1][2]+1
      
      ans = p*chk[j+1][2]+chk[j+1][1]+chk[j+1][0]
  print(ans)
print(chk[n-2][0]+chk[n-2][1])
print(0)

Solution (Python):
def main():
  N = int(input())
  CSF = [[int(_) for _ in input().split()] for __ in range(N-1)]
  for i in range(N-1):
    t = CSF[i][1] + CSF[i][0]
    for j in range(i+1, N-1):
      c, s, f = CSF[j]
      if t <= s:
        t = s + c
      else:
        k = (t - s + f - 1)//f
        t = s + k * f + c
    print(t)
  print(0)
  return

if __name__ == '__main__':
  main()

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


if __name__ == '__main__':
    N = int(input())
    C = [0 for _ in range(N - 1)]
    S = [0 for _ in range(N - 1)]
    F = [0 for _ in range(N - 1)]
    for i in range(N - 1):
        c, s, f = map(int, input().split())
        C[i] = c
        S[i] = s
        F[i] = f

    for i in range(N - 1):
        t = S[i]
        for j in range(i, N - 1):
            t += C[j]
            if j < N - 2:
                next_t = S[j + 1]
                if t > next_t:
                    next_t += math.ceil((t - next_t) / F[j + 1]) * F[j + 1]
                t = next_t
        print(t)
    print(0)

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


if __name__ == '__main__':
    N = int(input())
    C = [0 for _ in range(N - 1)]
    S = [0 for _ in range(N - 1)]
    F = [0 for _ in range(N - 1)]
    for i in range(N - 1):
        c, s, f = map(int, input().split())
        C[i] = c
        S[i] = s
        F[i] = f

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

Solution (Python):


import io
import sys
import math

data = int(input())

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

for i in range(data-1):
    counter = 0
    for j in range(i, data-1):
        if counter < array[j][1]:
            counter = array[j][1]
        elif counter % array[j][2] != 0:
            counter += array[j][2] - (counter % array[j][2])
 
        counter += array[j][0]
 
    print(counter)
print(0)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    mat = [list(map(int, readline().split())) for _ in range(n - 1)]

    for i in range(n):
        ct = 0
        for c, s, f in mat[i:]:
            if ct < s:
                ct = s
            if (ct-s) % f != 0:
                ct = ct + (f - ((ct-s) % f))
            ct += c
        print(ct)


if __name__ == '__main__':
    main()

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

Solution (Python):
import math

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

def time(t, i):
    if t <= data[i][1]:
        return data[i][0] + data[i][1]
    else:
        k = math.ceil((t - data[i][1]) / data[i][2])
        return data[i][0] + data[i][1] + k * data[i][2]

for i in range(N):
    ans = 0
    for j in range(i, N - 1):
        ans = time(ans, j)
    print(ans)

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

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

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

Solution (Python):
N = int(input())
li = []
for i in range(N-1):
    c, s, f = map(int, input().split())
    li.append((c,s,f))
for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        t = max(li[j][1], t)
        t += (li[j][2] - t)%li[j][2]
        t += li[j][0]
    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] = list(map(int,(input().split())))
for i in range(N):
    time = 0
    for j in range(i,N-1):
        if time < s[j]:
            time = s[j]
        time += (-time) % f[j]
        time += c[j]
    print(time)

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

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

Solution (Python):
import math

n = int(input())
csf = [list(map(int, input().split())) for i in range(n-1)]
ANS = []
for i in range(n):
  ans = 0
  for c,s,f in csf[i:]:
    if ans <= s:
      ans = s + c
    else:
      ans = s + math.ceil((ans-s)/f) * f + c
  ANS.append(ans)
for i in ANS:
  print(i)

Solution (Python):
N = int(input())
CSF = [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 < 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):
import math
N = int(input())

CSF = []

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

ans = []

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

print(*ans)

Solution (Python):
def resolve():
    N = int(input())
    CSF = [list(map(int, input().split(" "))) for i in range(N-1)]
    for i in range(N-1):
        time = 0
        for j in range(i, N-1):
            n = 0
            while True:
                if CSF[j][1] + n*CSF[j][2] >= time:
                    break
                n += 1
            time = CSF[j][0] + CSF[j][1] + n*CSF[j][2]
        print(time)
    print(0)



if '__main__' == __name__:
    resolve()

Solution (Python):

import math
N = int(input())
sta_info = []
for i in range(N-1):
    l = list(map(int,input().split()))
    sta_info.append(l)

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

Solution (Python):

import math
N = int(input())
sta_info = []
for i in range(N-1):
    l = list(map(int,input().split()))
    sta_info.append(l)

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

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

for i in range(N-1):
    duration, start, freq = data[i]
    total = start + duration
    for j in range(i+1, N-1):
        d, s, f = data[j]
        if total < s:
            total = s + d
        elif total % f == 0:
            total += d
        else:
            total = f * (total // f) + f + d
    print(total)
print(0)

Solution (Python):
import sys

n, *csf = map(int, sys.stdin.read().split())
csf = list(zip(*[iter(csf)] * 3))

def main():
    for i in range(n - 1):
        t = 0
        for c, s, f in csf[i:]:
            if t <= s: t = s + c
            else: t = s + ((t - s + f - 1) // 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):
    a, b, d = map(int, input().split())
    c.append(a)
    s.append(b)
    f.append(d)
for i in range(n - 1):
    tot = s[i] + c[i] 
    for j in range(i + 1, n - 1):
        if(tot >= s[j]):
            if(tot % f[j] == 0): tot += c[j]
            else: tot += f[j] - (tot % f[j]) + c[j]
        else:
            tot += (s[j] - tot) + c[j]
    print(tot)
print(0)

Solution (Python):
n = int(input())
train = []
for i in range(n-1):
    c,s,f = map(int,input().split())
    train.append((c,s,f))
for i in range(1,n+1):
    time = 0
    for j in range(i,n):
        if time <= train[j-1][1]:
            time = train[j-1][1]
        else:
            time = train[j-1][1] + (time - train[j-1][1] + train[j-1][2] - 1) // train[j-1][2] * train[j-1][2]

        time += train[j-1][0]
    print(time)

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

Solution (Python):
N = int(input())
l = []
for i in range(N-1):
  s = [int(x) for x in input().split()]
  l.append(s)
for i in range(N-1):
  t = 0
  for j in range(i,N-1):
      t = max(t,l[j][1]) 
      if t % l[j][2] == 0:
        t += l[j][0]
      else:
        t += l[j][2]- t % l[j][2] +l[j][0]
  print(t)
print(0)

Solution (Python):


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n = int(input())
    C = []
    S = []
    F = []
    for i in range(n-1):
        c,s,f = readInts()
        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)




if __name__ == '__main__':
  main()

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

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

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

        ans += C[j]

    print(ans)

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

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

Solution (Python):
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

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

ans = [0] * N

for i in range(N):
    cur = S[i] + C[i]
    for j in range(i + 1, N - 1):
        if cur < S[j]:
            cur = S[j] + C[j]
        else:
            d = (cur - S[j])
            cnt = (d + F[j] - 1) // F[j]
            cur = S[j] + cnt * F[j] + C[j]
    ans[i] = cur

for a in ans:
    print(a)

Solution (Python):
import math
from collections import namedtuple

Station = namedtuple('Station', 'c s f')

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

  
def measure(start):
  if start > len(stations) - 1:
    return 0
  
  time = 0
  for station in stations[start:]:
    depart_at = station.s\
      if station.s >= time\
      else math.ceil(time / station.f) * station.f
    time = depart_at + station.c
  return time

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

Solution (Python):






def main():
    N = int(input())
    C, S, F = [None] * (N-1), [None] * (N-1), [None] * (N-1)
    for i in range(N-1):
        C[i], S[i], F[i] = map(int, input().split())
    
    ans = [None] * N
    for i in range(N-1):
        tim = 0
        for j in range(i, N-1):
            if tim <= S[j]:
                tim = S[j]
            else:
                if (tim-S[j]) % F[j] > 0:
                    tim = S[j] + ((tim-S[j]) // F[j] + 1) * F[j]
            tim += C[j]
        
        ans[i] = tim
    
    ans[-1] = 0

    for a in ans:
        print(a)


main()

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

Solution (Python):
n=int(input())
info=[]
for i in range(n-1):
    c,s,f=map(int,input().split())
    info.append([c,s,f])
def cal(i):
    global info,n
    time=0
    s=(n-1)-i 
    for i in range(i):
        if i==0:
            time+=(info[s][1]+info[s][0])
            s+=1
            continue
        if time<=info[s][1]: 
            time=info[s][1]+info[s][0]
        else:
            sa=time-info[s][1] 
            if sa%info[s][2]==0: 
                time+=info[s][0]
            else:
                time+=((sa//info[s][2]+1)*info[s][2]-sa+info[s][0])
        s+=1
    return time
for i in range(n-1,-1,-1): 
    print(cal(i))

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

def tr(s,n):
    time = c[s-1][1] + c[s-1][0]
    for j in range(s,n-1):
        if (time <= c[j][1]):
            time = c[j][1]+c[j][0]
        else:        
            a = (time - c[j][1]) // c[j][2]
            if ((time - c[j][1])%c[j][2] != 0):
                a = a+1
            time = c[j][1]+c[j][2]*(a)+c[j][0]
    return time

ans = []
for k in range(1,n):
    ans.append(tr(k,n))
ans.append(0)
print(*ans, sep='\n')

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

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

n = int(readline())
cfs = [list(map(int, readline().split())) for i in range(n - 1)]
for i in range(n - 1):
    cnt = 0
    for j in range(i, n - 1):
        if cnt < cfs[j][1]:
            cnt = cfs[j][1]
        elif cnt % cfs[j][2] == 0:
            pass
        else:
            cnt += cfs[j][2] - (cnt % cfs[j][2])
        cnt += cfs[j][0]
    print(cnt)
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())
for i in range(n-1):
  ans=s[i]+c[i]
  for j in range(i+1,n-1):
    if s[j]>ans:
      ans=s[j]+c[j]
    else:
      ans+=(f[j]-ans%f[j])%f[j]+c[j]
  print(ans)
print(0)

Solution (Python):
import math

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


for start in range(1, N):
    time = CSF[start][0] + CSF[start][1]
    for transit in range(start+1, N):
        temp = math.ceil(time / CSF[transit][2]) * CSF[transit][2]
        time = max(temp, CSF[transit][1]) + CSF[transit][0]
    print(time)
print(0)

Solution (Python):
from math import ceil
N=int(input())
trains=[list(map(int,input().split())) for _ in range(N-1)]
t=0
cnt=0
for i in range(N):
    t=0
    for j in range(i,N-1,1):
        t=max(ceil(t/trains[j][2]),ceil(trains[j][1]/trains[j][2]))*trains[j][2]
        t=t+trains[j][0]
        
        
    print(t)

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

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

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

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

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

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    def f(i: int, s: int):
        if i == N - 1:
            return s
        s = max(s, S[i])
        return f(i + 1, -(-s // F[i]) * F[i] + C[i])
    for i in range(N):
        print(f(i, 0))


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

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

CSF = [tuple(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 = 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)
print(0)

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>0:
            t+=f-t%f
        t+=c
    print(t)

Solution (Python):
x = int(input())
l = []
st = 0
ans = 0
k = 0
for i in range(x-1):
  a,b,c = map(int,input().split())
  l.append([a,b,c])

for i in range(x):
  st = 0
  ans = 0
  k = i + 1
  if i == x - 1:
    print(0)
  else:
    ans += l[i][0] + l[i][1]
    while k < x - 1:

      if ans < l[k][1]:
        ans = l[k][1] + l[k][0]
      elif ans >= l[k][1] and ans % l[k][2] != 0:
        ans += l[k][2] - ans % l[k][2] + l[k][0]
      else:
        ans += l[k][0]

      k += 1
    print(ans)

Solution (Python):

import sys
input = sys.stdin.readline











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

Ans = []
for i in range(N):
    ans = 0
    for j in range(i,N-1):
        c,s,f = CSF[j]
        if ans < s:
            ans = s
        if ans%f != 0:
            ans += f - ans%f
        ans += c
    Ans.append(ans)

for ans in Ans:
    print(ans)

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):
	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):
n=int(input())
n-=1
c=[0]*n
s=[0]*n
f=[0]*n
for i in range(n):
    c[i],s[i],f[i]=map(int,input().split())
for i in range(n):
    t=0
    for j in range(i,n):
        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)
print(0)

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

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

print(0)

Solution (Python):
n=int(input())
a=[list(map(int,input().split())) for i in range(n-1)]
def t(x,k):
    if a[k][1]<=x:
        return (x+a[k][2]-1)//a[k][2]*a[k][2]+a[k][0]
    return a[k][1]+a[k][0]
for i in range(n-1):
    p=t(0,i)
    for j in range(i+1,n-1):
        p=t(p,j)
    print(p)
print(0)