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
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    CSF=LLIN(N-1)
    def solve(CSF):
        now = 0
        for c,s,f in CSF:
            if now<=s:
                now = s
            else:
                over = now-s
                if over%f:
                    now += (f-(over%f))
            now += c
        print(now)
                
    for i in range(N):
        solve(CSF[i:])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [[int(i) for i in input().split()] for j in range(N-1)]
    for i in range(N-1):
        ans = 0
        for j in range(i, N-1):
            if ans < A[j][1]:
                ans = A[j][1]
            elif A[j][1] < ans and ans % A[j][2] != 0:
                ans += A[j][2] - (ans % A[j][2])
            ans += A[j][0]
        print(ans)
    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
CSF=[list(map(int,input().split())) for _ in range(N-1)]
INF=10**9+7

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

Submission status: Accepted

Solution code:

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

for i in range(N-1):
    tm = 0 #時刻を表す
    for j in range(i, N-1):
        if tm < M[j][1]: #開通していない
            tm = M[j][1]
        elif tm % M[j][2] != 0: #発車していない
            tm += M[j][2] - (tm % M[j][2])
 
        tm += M[j][0]
 
    print(tm)
print(0)

Submission status: Accepted

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

ans=[]
for i in range(n):
    time=0
    for j in range(i,n-1):
        c,s,f=csf[j][0],csf[j][1],csf[j][2]
        if time>s:
            time=s -(-(time-s)//f)*f
        else:
            time=s
        time+=c

        #print(i,j,c,s,f,time)
    ans.append(time)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
# 駅jjを出発する時刻は、
#S[j]+F[j]×kS[j]+F[j]×kとなる(kは車両数)。
#出発する時刻は現在時刻tt以上である必要があるので、
#S[j]+F[j]×k≥tS[j]+F[j]×k≥tとする。 式変形
import math
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N): # 駅iを始点とする
  t = 0 # 現在時刻
  for j in range(i, N-1):
    c, s, f = CSF[j]
    if t <= s: # 始発がまだ
      t = s+c
    else: # 始発以降      
      t = math.ceil(t / f) * f + c
  print(t)

Submission status: Accepted

Solution code:
# 駅jjを出発する時刻は、
#S[j]+F[j]×kS[j]+F[j]×kとなる(kは車両数)。
#出発する時刻は現在時刻tt以上である必要があるので、
#S[j]+F[j]×k≥tS[j]+F[j]×k≥tとする。 式変形

N = int(input())
C = [0]*(N+1)
S = [0]*(N+1)
F = [0]*(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): # 駅iを始点とする
  t = 0 # 現在時刻
  for j in range(i, N-1):
    # kはマイナスの値になる場合もあるので、その時はk=0k=0にする。
    k = max(0, (t-S[j]+F[j]-1) // F[j])
    t = S[j] + F[j]*k + C[j]
  print(t)

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):
    tm = 0 #時刻を表す
    for j in range(i,n-1):
        if tm < li[j][1]: #開通していない
            tm = li[j][1]
        elif tm%li[j][2] != 0: #発車していない
            tm += li[j][2]-(tm%li[j][2])
        else:
            pass

        tm += li[j][0]

    print(tm)
print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    # 駅間をC秒ではしる
    for i in range(N-1):
        cur = 0
        for j in range(i,N-1):
            if cur <= S[j]:
                cur = S[j]
            else:
                cur = -(-(cur-S[j])//F[j])*F[j]+S[j]
            cur += C[j]
        print(cur)
    print(0)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int()] * (N - 1)  # type: "List[int]"
    S = [int()] * (N - 1)  # type: "List[int]"
    F = [int()] * (N - 1)  # type: "List[int]"
    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()

Submission status: Accepted

Solution code:
n=int(input())
csf=[0]
for i in range(n-1):
    csf.append(list(map(int,input().split())))
for i in range(1,n):
    t=0
    for j in range(i,n):
        if t<=csf[j][1]:
            t=csf[j][1]+csf[j][0]
        else:
            if t%csf[j][2]!=0:
                t=t+csf[j][2]-t%csf[j][2]+csf[j][0]
            else:
                t+=csf[j][0]
    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)

for i in range(N - 1):
    t = 0
    
    for j in range(i, N - 1):    
        n = 0
        
        while t > S[j] + F[j] * n:
            n += 1
        
        t = S[j] + F[j] * n + C[j]

    print(t)
print(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    C, S, F = [], [], []
    for _ in range(N-1):
        c, s, f = LI()
        C.append(c)
        S.append(s)
        F.append(f)
    for i in range(N-1):
        cur_t = 0
        for j in range(i, N-1):
            c, s, f = C[j], S[j], F[j]
            if cur_t > s:
                if cur_t % f == 0:
                    pass
                else:
                    cur_t += (f - cur_t % f)
            else:
                cur_t = s
            cur_t += c
        print(cur_t)
    print(0)
main()

Submission status: Accepted

Solution code:
N = int(input())
CSF = []

for i in range(N - 1):
  csf = list(map(int,input().split()))
  CSF.append(csf)
  
for i in range(0,N - 2):
  time = CSF[i][0] + CSF[i][1]
  for j in range(i + 1,N - 1):
    C = CSF[j][0]
    S = CSF[j][1]
    F = CSF[j][2]
    
    if time < S:
      time = S
    
    if (time - S) % F == 0:
      time = time + C
    else:
      time = time + (F - (time - S) % F) + C
      
  print(time)
print(CSF[-1][0] + CSF[-1][1])
print(0)

Submission status: Accepted

Solution code:
n = int(input())
c=[]; s=[]; f=[]
for i in range(n-1):
    ci,si,fi = map(int,input().split())
    c.append(ci); s.append(si); f.append(fi)
for k in range(n-1):
    ans = [0]*(n)
    ans[k+1] = s[k] + c[k]
    for i in range(k+2,n):
        if ans[i-1] <= s[i-1]:
            ans[i] = s[i-1] + c[i-1]
        else:
            dpt = s[i-1]
            if (ans[i-1]-dpt)%f[i-1]==0:
                dpt = ans[i-1]
            else:
                dpt += ((ans[i-1]-dpt)//f[i-1]+1)*f[i-1]
            ans[i] = dpt + c[i-1]
    print(ans[n-1])
print(0)

Submission status: Accepted

Solution code:
import sys

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

def main(): 
    take_time = [None] * n

    for i in range(n):
        cur = i
        t = 0
        while cur < n - 1:
            c, s, f = csf[cur]
            if t < s:
                t = s
            else:
                t = s + f * ((t - s + f - 1) // f)
            t += c
            cur += 1
        take_time[i] = t
    return take_time
        
if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Submission status: Accepted

Solution code:
n = int(input())

l = [[0, 0, 0] for _ in range(n-1)]

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

for i in range(n-1):
  t = l[i][1] + l[i][0]
  for j in range(i+1, n-1):
    if t%l[j][2] == 0 and t >= l[j][1]:
      pass
    elif t%l[j][2] != 0 and t >= l[j][1]:
      t = (t//l[j][2]+1)*l[j][2]
    else:
      t = l[j][1]
    t += l[j][0]
  print(t)
else:
  print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = []
for _ in range(N-1):
    temp = [int(x) for x in input().split()]
    A.append(temp)
for i in range(N-1):
    t = A[i][0] + A[i][1]
    for j in range(i+1,N-1):
        if t < A[j][1]:
            t = A[j][1]
        elif t % A[j][2] != 0:
            t += A[j][2] - t % A[j][2]
        t += A[j][0]
    print(t)
print(0)

Submission status: Accepted

Solution code:
n = int(input())

l = [[0, 0, 0] for _ in range(n-1)]

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

for i in range(n-1):
  t = l[i][1] + l[i][0]
  for j in range(i+1, n-1):
    if t%l[j][2] == 0 and t >= l[j][1]:
      pass
    elif t%l[j][2] != 0 and t >= l[j][1]:
      t = (t//l[j][2]+1)*l[j][2]
    else:
      t = l[j][1]
    t += l[j][0]
  print(t)
else:
  print(0)

Submission status: Accepted

Solution code:
n = int(input())

stations = []
for i in range(n-1):
    time_to_next, first, interval = map(int, input().split())
    stations.append([time_to_next, first, interval])

for start in range(n):
    now = 0
    for pos in range(start, n):
        if pos == n-1:
            print(now)
            break

        time_to_next, first, interval = stations[pos]
        if first >= now:
            now = first + time_to_next
            continue
        else:
            num = (now-first)//interval + bool((now-first)%interval)
            now = first + interval*num + time_to_next
            continue

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

Submission status: Accepted

Solution code:
n=int(input())
t = [list(map(int,input().split())) for i in range(n-1)]
for i in range(n-1):
  ans=t[i][1]+t[i][0]
  for j in range(i+1,n-1):
    if ans>=t[j][1]:
      ans+= -ans%t[j][2]+t[j][0]
    else:
      ans+=t[j][1]-ans+t[j][0]
  print(ans)
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):
    ans = 0
    for c, s, f in CSF[i:]:
        if ans < s:
            ans = s
        elif ans % f != 0:
            ans += f - ans % f
        ans += c
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())
st = [tuple(map(int, input().split())) for i in range(N-1)]
for i in range(N):
  res = 0  
  for j in range(i, N-1):
    c, s, f = st[j]
    if res < s:
      res = s
    else:
      res = -(-res // f) * f
    res += c
  print(res)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
t = [tuple(map(int, input().split())) for _ in range(N)]
res = [0] * N
for i in range(N):
  p = 0
  for j in range(i, N - 1):
    if p <= t[j][1]:
      p = t[j][1]
    else:
      p += (-p % t[j][2])
      #print(px)
    p += t[j][0]
    #print(i, p)
  res[i] = p
for r in res: print(r)

Submission status: Accepted

Solution code:
N = int(input())
arr = [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 < arr[j][1]:
      t = arr[j][1]
    else:
      if t%arr[j][2]==0:
        t = t
      else:
        t = t+arr[j][2]-t%arr[j][2]
    t += arr[j][0]
  print(t)

Submission status: Accepted

Solution code:
N = int(input())
train = [list(map(int, input().split())) for i in range(N-1)]
anslist = [0]
for i in range(N-1):
    ans = 0
    for j in range(i, N-1):
        ans = max(train[j][1], ans)
        ans = ((ans-1) // train[j][2] + 1) * train[j][2]
        ans += train[j][0]
    print(ans)
print(0)

Submission status: Accepted

Solution code:
import math as m

N = int(input())
CSF = []
for i in range(N - 1):
    CSF.append([int(i) for i in input().split()])


def next_stat_arrival(here, time):
    if here == N - 1:
        return time
    if time < CSF[here][1]:
        return CSF[here][1] + CSF[here][0]
    return m.ceil(time / CSF[here][2]) * CSF[here][2] + CSF[here][0]


for i_start in range(N):
    time = 0
    for jth_station in range(i_start, N - 1):
        time = next_stat_arrival(jth_station, time)
    print(time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
C=[None];S=[None];F=[None]
for i in range(1,N):
    Ci,Si,Fi=map(int,input().split())
    C.append(Ci);S.append(Si);F.append(Fi)

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

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
train = [tuple(map(int, input().split())) for _ in range(n - 1)]
for i in range(n - 1):
    total = train[i][0] + train[i][1]
    for j in range(i + 1, n - 1):
        diff = total - train[j][1]
        if diff <= 0:
            total = train[j][1]
        elif diff % train[j][2] != 0:
            total += train[j][2] - diff % train[j][2]
        total += train[j][0]
    print(total)
print(0)

Submission status: Accepted

Solution code:
N = int(input())

C = []
S = []
F = []
N -= 1

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

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

Submission status: Accepted

Solution code:
N, *D = map(int, open(0).read().split())
C, S, F = D[0::3], D[1::3], D[2::3]
for start in range(N):
  ans = 0
  for i in range(start, N-1):
    ans = max(S[i], (ans + F[i]-1) // F[i] * F[i])
    ans += C[i]
  print(ans)

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

Submission status: Accepted

Solution code:
import math
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 j in range(n-1):
    t=s[j]
    for i in range(j,n-1):

        if t<=s[i]:
            t=s[i]+c[i]
        else:
            k=t-s[i]
            t=s[i]+math.ceil(k/f[i])*f[i]+c[i]
    print( t)

print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    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().strip().split()))
    for k in range(n-1):
        t = 0
        for i in range(k, n-1):
            if t < s[i]:
                # ans += s[i] - t
                t = s[i]
            else:
                # ans += f[i] - (t - s[i]) % f[i]
                t = f[i] * ((t + f[i] - 1) // f[i])

            # ans += c[i]
            t += c[i]
        print(t)
    print(0)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
lst = []
for _ in range(n - 1):
  lst.append([int(i) for i in input().split()])

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2000)

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

def time_cost(i, now, lst):
  if i == n - 1:
    return now
  if now >= lst[i][1]:
    if now % lst[i][2] == 0:
      now += lst[i][0]
    else:
      now += lst[i][0] + lst[i][2] - now % lst[i][2]
  else:
    now = lst[i][1] + lst[i][0]
  return time_cost(i+1, now, lst)

for i in range(n):
  print(time_cost(i, 0, lst))

Submission status: Accepted

Solution code:
import sys


if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
T = [MAP() for _ in range(N-1)]

S = [0] * N

for i in range(N-1):
	m = 0
	for j in range(i, N-1):
		c, s, f = T[j]
		# 最初の駅
		if m == 0:
			m += c+s
		else:
			# 2駅目以降に到着してすぐに出発できるケース
			if m % f == 0:
				m = max(s, m)
				m += c
			# 次の電車を待つケース(f分刻みで出発する電車の次のやつに乗りたい)	
			else:
				m = max(s, m+f-(m%f))
				m += c
	S[i] = m

#print(S)

for s in S:
	print(s)

Submission status: Accepted

Solution code:
N = int(input())
arr = []
for _ in range(N-1):
    arr.append(list(map(int, input().split())))
for i in range(N-1):
    start = i
    tmp = 0
    while start < N-1:
        if tmp < arr[start][1]:
            tmp = arr[start][1]
        elif (tmp-arr[start][1]) % arr[start][2] == 0:
            pass
        else:
            tmp += arr[start][2]-((tmp-arr[start][1]) % arr[start][2])
        tmp += arr[start][0]
        start += 1
    print(tmp)
print(0)

Submission status: Accepted

Solution code:


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

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

    for i in ans.values():
        print(i)

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 i in range(n-1):
    #i=0, 1つめの駅発を対象とする
    time = S[i] + C[i]
    for j in range(i+1, 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)
print(0)

Submission status: Accepted

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def main():
    N = I()
    C = [0] * (N-1)
    S = [0] * (N-1)
    F = [0] * (N-1)

    for i in range(N-1):
        C[i], S[i], F[i] = MI()

    for i in range(0, N-1):
        ans = S[i]
        # show(ans)
        for j in range(i, N-1):
            ans = max(ans, S[j])
            diff = S[j] - ans
            ans += diff % F[j]
            ans += C[j]
            # show(j, ans)
        print(ans)
    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

sum_val = 0
for i in range(N - 1):
    sum_val = StartTimeList[i] + TravelTimeList[i]
    for j in range(i + 1 , N - 1):
        sum_val = max(sum_val , StartTimeList[j])
        WaitTime = (WaitTimeList[j] - ((sum_val - StartTimeList[j]) % WaitTimeList[j])) % WaitTimeList[j]
        sum_val += TravelTimeList[j] + WaitTime
    print(sum_val)
print("0")

Submission status: Accepted

Solution code:
N = int(input())

CSF = []
for i in range(N-1):
    tmp = list(map(int, input().split()))
    CSF.append(tmp)
    
for i in range(N-2):
    time = CSF[i][0] + CSF[i][1]
    #print("time1", time)
    for j in range(i+1, N-1):
        if time <= CSF[j][1]:
            time = CSF[j][1] + CSF[j][0]
        else:
            if time % CSF[j][2] == 0:
                time += CSF[j][0]
            else:
                time += CSF[j][2] - (time % CSF[j][2]) + CSF[j][0]
                #print("time", time)
    print(time)

print(CSF[N-2][0] + CSF[N-2][1])
print(0)

Submission status: Accepted

Solution code:
N=int(input())
C=[]
S=[]
T=[]
for i in range(N-1):
  c,s,t=map(int,input().split())
  C += [c]
  S += [s]
  T += [t]
answer=[]
for i in range(N-1):
  Time=0
  for j in range(i,N-1):
    if Time <= S[j]:
      Time=S[j]+C[j]
    else:
      Time=-(-(Time-S[j])//T[j])*T[j]+S[j]+C[j]
  answer += [Time]

for i in range(N-1):
  print(answer[i])
print(0)

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


for i in range(N):
    calc(i)

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

Submission status: Accepted

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

for i in range(N-1):
    time = L[i][1]
    for j in range(i, N-1):
        c, s, f = L[j]
        if time < s:
            time = s
        elif time % f == 0:
            pass
        else:
            time += f - time % f
        time += c
    ans.append(time)

ans.append(0)
print(*ans, sep="\n")

Submission status: Accepted

Solution code:
import sys
import math
n = int(input())
ls = []
for i in range(n-1):
    c, s, f = [int(i) for i in sys.stdin.readline().split()]
    ls.append((c, s, f))
for start in range(n):
    _sum = 0
    for c, s, f in ls[start:]:
        _sum = max(math.ceil(_sum / f) * f, s)
        _sum += c
    print(_sum)

Submission status: Accepted

Solution code:
import sys
from math import ceil
input = sys.stdin.readline
N = int(input())
csf = [[int(i) for i in input().split()] for _ in range(N-1)]
ans = []
for i, sa in enumerate(csf):
    t = sa[0]+sa[1]
    for gc, gs, gf in csf[i+1:]:
        t = max(ceil((t-gs)/gf)*gf+gs+gc, gc+gs)
    ans.append(t)
ans.append(0)
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
N = int(input())

CSF = [list(map(int, input().strip().split())) for _ 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)

Submission status: Accepted

Solution code:
N = int(input())

CSF = [list(map(int, input().strip().split())) for _ 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]
    else:
      for k in range(CSF[j][2]):
        if (time + k) % CSF[j][2] == 0:
          time = time + k
          break
    time += CSF[j][0]
  print(time)

Submission status: Accepted

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


def time_calc(TC):
  pl = 0
  time = 0
  for info in TC:
    c, s, f = info
    if time <= s:
      time = s
    elif (time - s) % f != 0:
      time = time + f - (time % f)
    time += c
  return time
for i in range(n):
  print(time_calc(TC[i:]))

Submission status: Accepted

Solution code:
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N-1)]
for i in range(N-1):
    ans = 0
    for j in range(i, N-1):
        C, S, F = CSF[j]
        if ans < S:
            ans = S
        else:
            diff = ans - S
            if diff % F != 0:
                ans += F - (diff % F)
        ans += C
    print(ans)
print(0)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(N - 1):
    time = 0
    for j in range(i, N - 1):
        c = params[j][0]
        s = params[j][1]
        f = params[j][2]
        if s > time:
            time += s - time + c
        else:
            time += (s - time) % f + c
    print(time)
    
print(0)

Submission status: Accepted

Solution code:
n = int(input())
csfl = []

for _ in range(n-1):
    c,s,f = map(int,input().split())
    csfl.append((c,s,f))

while csfl:
    time = 0
    for c,s,f in csfl:
        if time % f == 0:
            time = max(s, time)
        else:
            time = max(s, time+f-(time%f))
        time += c
    print(time)
    csfl.pop(0)

print(0)

Submission status: Accepted

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

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

      
for i in range(N):
  print(Ans[i])

Submission status: Accepted

Solution code:
N = int(input())
ans = [0 for i in range(N)]

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