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



Sample input:
3
6 5 1
1 10 1


Sample output:
12
11
0

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
C, S, F = [], [], []

for _ in range(N-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for station in range(N):
    now = station
    time = 0

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

        now += 1

    print(time)

Submission status: Accepted

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


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


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

Submission status: Accepted

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


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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

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

Submission status: Accepted

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

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

        

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

Submission status: Accepted

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

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

freaq[n-1] = 1

t = 0

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

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

Submission status: Accepted

Solution code:
n=int(input())
c=[]
s=[]
f=[]

for i in range(n-1):
    C,S,F=map(int,input().split())
    c.append(C)
    s.append(S)
    f.append(F)
T=[-1]*n
T[-1]=0
for i in range(n-1):
    p=i
    t=0
    for j in range(n-i-1):
        if t<=s[p]:
            t=s[p]
            t+=c[p]
        else:
            m=(t+f[p]-1)//f[p]
            t=m*f[p]
            t+=c[p]
        p+=1
    T[i]=t
for i in range(n):
    print(T[i])

Submission status: Accepted

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

for i in l:print(i)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

n = int(input())
c,s,f = [0],[0],[0]
for i in range(n-1):
    ci,si,fi = map(int,input().split())
    c.append(ci)
    s.append(si)
    f.append(fi)
#print(c,s,f)
for i in range(1,n+1):
    print(jikan(0,i))

Submission status: Accepted

Solution code:
N = int(input())
Cls = [0]
Sls = [0]
Fls = [0]
lsans = []
for i in range(1,N):
    c,s,f = map(int,input().split())
    Cls.append(c)
    Sls.append(s)
    Fls.append(f)
for i in range(1,N):
    t = 0
    for j in range(i,N):
        if t < Sls[j]:
            t = Sls[j] + Cls[j]
        elif t%Fls[j] == 0:
            t += Cls[j]
        else:
            t += Fls[j]-(t%Fls[j])+Cls[j]
    lsans.append(t)
lsans.append(0)
for i in lsans:
    print(i)

Submission status: Accepted

Solution code:
N = int(input())
T = 0
t = 0
ans = []
for i in range(N-1):
    C, S, F = map(int, input().split())
    for j in range(len(ans)):
        if ans[j] <= S:
            ans[j] = S+C
        elif ans[j]%F != 0:
            ans[j] = ans[j]+F-(ans[j] % F)+C
        else:
            ans[j] += C
    ans.append(S+C)
for a in ans:
    print(a)
print(0)

Submission status: Accepted

Solution code:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())


N = I()
CSF = [tuple(MI()) for i_ in range(N-1)]

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

Submission status: Accepted

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

ans = [0]
time_matrix = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(i+1):
        if i < n-1:
            if time_matrix[i][j] % stations[i][2] == 0:
                waiting = 0
            else:
                waiting = stations[i][2] - (time_matrix[i][j] % stations[i][2])
            time_matrix[i+1][j] = max(time_matrix[i][j] + stations[i][0] + waiting, stations[i][0] + stations[i][1])

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

Submission status: Accepted

Solution code:
def LIHW(h):
    return [list(map(int, input().split())) for _ in range(h)]


N = int(input())
X = LIHW(N-1)

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

Submission status: Accepted

Solution code:
from math import ceil

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

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

print(0)

Submission status: Accepted

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

for i in range(N-1):
    c1,s1,f1 = Plan[i]
    time = s1+c1
    for j in range(i+1,N-1):
        c,s,f = Plan[j]
        if time <= s:
            time = s
        elif (time-s)%f != 0:
            time += f-(time-s)%f
        time += c
    print(time)
print(0)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = [list(map(int,input().split())) for _ in range(N-1)]
A.insert(0,0)
for i in range(1,N):
    C,S,F = A[i]
    T = S+C
    j = i+1
    while j<N:
        C,S,F = A[j]
        T = max(S,math.ceil(T/F)*F)
        T += C
        j += 1
    print(T)
print(0)

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline())

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

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

    print(t)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
csf = [list(map(int, input().split())) for _ in range(N-1)]
ans = [None]*N
ans[-1] = 0
for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        if now <= csf[j][1]:
            now = csf[j][1]
        else:
            t  = (now - csf[j][1] + csf[j][2]-1)//csf[j][2]
            now = csf[j][1] + t*csf[j][2]
        now += csf[j][0]
    ans[i] = now
[print(a) for a in ans]

Submission status: Accepted

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

for i in range(n - 1):
    c, s, f = csf[i]
    a = s + c
    now = i
    for j in range(i + 1, n - 1):
        nc, ns, nf = csf[j]
        # next = ns + nf * x
        if a <= ns:
            a = ns
        else:
            x = (a - ns + nf - 1) // nf
            a = ns + nf * x
        a += nc

    print(a)
print(0)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
CSF = [tuple(MI()) for i_ in range(N-1)]

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

Submission status: Accepted

Solution code:
n=int(input())
yo=[]
for _ in range(n-1):
  a=list(map(int,input().split()))
  yo.append(a)
  
def ans(x):
  if x==n-1:
    return 0
  else:
    t=0
    for i in range(x,n-1):
      if t<=yo[i][1]:
        t=yo[i][1]+yo[i][0]
      else:
        s=t-yo[i][1]
        if s%yo[i][2]==0:
          t=t+yo[i][0]
        else:
          mo=s%yo[i][2]
          t=t+yo[i][2]-mo+yo[i][0]
    return t
    
for j in range(n):
  print(ans(j))

Submission status: Accepted

Solution code:
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)
S.append(0)

import numpy as np
def theta(x): #ヘヴィサイドの段差関数
    return x if x > 0 else 0

def DptTimeAtNextSt(i, T): #時刻Tに駅iを出発した時、駅i+1を出発する時間
    global C, S, F
    arrT = T + C[i]
    if i == N-2: return arrT 
    return S[i+1] + np.ceil(theta(arrT-S[i+1])/F[i+1]) * F[i+1]

def solve(i, S): #駅iに対する解を再帰的に解く関数
    if i == N-1:
        return int(S)
    else:
        return solve(i+1, DptTimeAtNextSt(i,S))

for i in range(N):
    print(solve(i,S[i]))

Submission status: Accepted

Solution code:
n = int(input())
ans = [0] * n

for i in range(1, n):
    c, s, f = list(map(int, input().split()))

    for j in range(i):
        ans[j] = max(ans[j], s)
        ans[j] = ((ans[j]+f-1)//f) * f
        ans[j] += c

for a in ans:
    print(a)

Submission status: Accepted

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

lst = []

for i in range(N - 1):
    c, s, f = station[i]

    for j in range(len(lst)):
        a = lst[j]

        if a >= s:
            if a % f == 0:
                a += c
            else:
                a += (f - a % f) + c
        else:
            a = s + c

        lst[j] = a

    lst.append(s + c)


lst.append(0)
for a in lst:
    print(a)

Submission status: Accepted

Solution code:
import math

n = int(input())
cL = []
sL = []
fL = []
for i in range(n - 1):
    c, s, f = map(int, input().split(" "))
    cL.append(c)
    sL.append(s)
    fL.append(f)

ans = 0
for i in range(n - 1):
    sm = 0
    for j in range(i, n - 1):
        c = cL[j]
        s = sL[j]
        f = fL[j]
        if sm < s:
            sm = s + c
            continue
        df = f - (sm - s) % f
        if df == f:
            df = 0
        sm += c + df
    print(sm)
print(0)

Submission status: Accepted

Solution code:
import sys
import itertools
import math


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


def main():
    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):
        t = i
        time=0
        while t<N-1:

            if time <=S[t]:
                time =S[t]+C[t]
            else:
                if time %F[t] ==0:
                    time +=C[t]
                else:
                    div = time //F[t]
                    time = (div+1) *F[t] + C[t]
            t+=1

        print(time)

    print(0)





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())
C,S,F=map(list,zip(*[list(map(int,input().split())) for i in range(N-1)]))
r=[0]*N
for i in range(N-2,-1,-1):
    x=S[i]+C[i]
    for j in range(i+1,N-1):
        x=S[j]+C[j] if x<S[j] else -(-x//F[j])*F[j]+C[j]
    r[i]=x
print(*r,sep='\n')

Submission status: Accepted

Solution code:
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())

def arrive(st):
    time = C[st] + S[st]
    for i in range(st + 1, N-1):
        if time <= S[i]:
            time = C[i] + S[i]
        else:
            if time % F[i] != 0:
                time = time + C[i] + (F[i] - time % F[i])
            else:
                time = time + C[i]
    return time

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

Submission status: Accepted

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

for i in range(n-1):
    t = 0
    for c,s,f in csf[i:]:
        if s > t:
            # 始発を待つ
            t = s
        else:
            # 次発を待つ
            t += (s-t) % f
        t += c
    print(t)
print(0)

Submission status: Accepted

Solution code:
N=int(input())
C,S,F=[],[],[]

for i in range(N-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

T=[0]*N
for i in range(N):
    A=0
    for j in range(i,N-1):
        if A>=S[j]:
            A=((A+F[j]-1)//F[j])*F[j]
        else:
            A=S[j]
        A+=C[j]
    T[i]=A

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

Submission status: Accepted

Solution code:
N = int(input())
from math import floor
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 start in range(N):
    ans = 0
    if start == N-1:
        print(ans)
        break
    for i in range(start, N-1):
        if ans <= S[i]:
            ans = S[i]
            ans += C[i]
        else:
            if ans % F[i] == 0:
                ans += C[i]
            else:
                ans += (F[i] - ans % F[i])
                ans += C[i]
            
    print(ans)

Submission status: Accepted

Solution code:
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
for i in l: print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import *

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

Submission status: Accepted

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

for i in range(N-1):
    ci,si,fi = li[i]
    time = si+ci
    for j in range(i+1,N-1):
        cj,sj,fj = li[j]
        if time%fj != 0:
            time = ((time//fj)+1)*fj
        #print(i,time)
        if time < sj:
            time = sj
        time += cj
    print(time)
print(0)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

for i in range(n):
    now = 0
    for c, s, f in csf[i::]:
        if now <= s:
            now = s
        else:
            if now % f == 0:
                pass
            else:
                now = (now // f + 1) * f
        now += c
    print(now)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
csf = [list(map(int,input().split())) for i in range(n-1)]
ans1=[]
for j in range(n-1):
  requ_time=csf[j][1]+csf[j][0]
  for i in range(j,n-1):
    if i!=j:
      if requ_time <= csf[i][1]:
        requ_time+=(csf[i][0]+(csf[i][1]-requ_time))
  #elif requ_time > csf[i][1] and csf[i][0]+csf[1] > requ_time:
      else:
        requ_time+=(csf[i][0]+(csf[i][2]-(requ_time-csf[i][1])%csf[i][2])%csf[i][2])
  ans1.append(requ_time)
for i in ans1:
  print(i)
print(0)

Submission status: Accepted

Solution code:

n=int(input())
c=[]
sf=[]
for _ in range(n-1):
    ci,s,f=map(int,input().split())
    c.append(ci)
    sf.append([s,f])
for i in range(n):
    temp=0
    for j in range(i,n-1):
        if temp<=sf[j][0]:
            temp=sf[j][0]+c[j]
        else:
            if temp%sf[j][1]==0:
                temp=temp+c[j]
            else:
                temp=temp+(sf[j][1]-temp%sf[j][1])+c[j]
            
    print(temp)

Submission status: Accepted

Solution code:
import math
def main():
    n=int(input())
    csf=[list(map(int,input().split())) for _ in range(n-1)]
    for i in range(n):
        if i == n-1:
            print(0)
        else:
            t=0
            for c,s,f in csf[i:]:
                t = max(s,t)
                t = math.ceil(t/f)*f+c
                #print("start:", i, t)
            print(t)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    CSF = list(list(map(int, readline().split())) for _ in range(N-1))
    T = []
    for i in range(N-1):
        t = 0
        for c, s, f in CSF[i:]:
            t = max(math.ceil(t/f)*f, s) + c
        T.append(t)
    T.append(0)
    for t in T:
        print(t)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N = int(input())
    starts = [[int(item) for item in input().split()] for _ in range(N-1)]

    for i in range(N):
        temp_time = 0
        if i == N-1:
            print(0)
        else:
            for j in range(i,N-1):
                c, s, f = starts[j]
                if temp_time <= s:
                    temp_time = s

                if temp_time % f == 0:
                    pass
                else:
                    temp_time = (temp_time // f + 1) * f
            
                temp_time += c
            print(temp_time)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
n = int(input())
route, ans = [], []
for i in range(n-1):
    a = list(map(int, input().split()))
    route.append(a)

for i in range(n-1):
    c = route[i][0]+route[i][1]
    for j in range(i+1, n-1):
        if c < route[j][1]:
            c = route[j][0]+route[j][1]
        elif (c-route[j][1])%route[j][2] == 0:
            c += route[j][0]
        else:
            c += route[j][0]+route[j][2]-(c-route[j][1])%route[j][2]
    ans.append(c)
ans.append(0)
for i in ans:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal

INF = 1 << 50

def eval(start, CSF):
    N = len(CSF)+1
    queue = []
    heappush(queue, (0, start))
    while queue:
        time, current = heappop(queue)
        #print(f'time : {time}, current : {current}')
        if current == N-1:break
        for i in range(current, current+1):
            c,s,f = CSF[i]
            first_s = s + c * (current-i)
            if time <= first_s:
                next_leave = first_s
            else:
                next_leave = first_s + math.ceil((time - first_s) / f) * f
            #print(f'i : {i}, c/s/f : {c}/{s}/{f}, next_leave : {next_leave}')
            heappush(queue, (next_leave + c, current+1))
    return time

def run():
    N = int(sysread())
    CSF = []
    for i in range(N-1):
        c,s,f = map(int, sysread().split())
        CSF.append((c,s,f))

    for i in range(N-1):
        print(eval(i, CSF))
    print(0)
    

if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
N = int(input())
CSF = [[0] * 3 for i in range(N-1)]

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

for i in range(N-1):
    now = CSF[i][1]+CSF[i][0]
    for j in range(i+1, N-1):
        # 1本目の前なら1本目まで待つ
        if now <= CSF[j][1]:
            now += CSF[j][0]+(CSF[j][1]-now)

        # 1本目以降なら待ち時間と移動時間を加算する
        else:
            while (now - CSF[j][1]) % CSF[j][2] != 0:
                now += 1
            now += CSF[j][0]
    print(now)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
C = [0]*(N-1)
S = [0]*(N-1)
F = [0]*(N-1)
for TN in range(0,N-1):
    C[TN],S[TN],F[TN] = (int(T) for T in input().split())
for TN in range(0,N):
    Time = 0
    for TS in range(TN,N-1):
        if Time>=S[TS]:
            Time += C[TS]+(F[TS]-(Time%F[TS]))%F[TS]
        else:
            Time += C[TS]+(S[TS]-Time)
    print(Time)