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 numpy as np

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)
# cumsum_C = np.array(C)[::-1].cumsum()
# print(f'{cumsum_C=}')

for i in range(N):
    x = 0
    for j in range(i, N - 1):
        if S[j] > x:
            x = S[j]
        else:
            # S[j] + a * F[j] > x
            a = ((x - S[j]) + (F[j] - 1)) // F[j]
            x = S[j] + F[j] * a
        x += C[j]
        # print(f'{x=}')
    print(x)
# T = [0] * (N - 1)
# T[-1] = C[-1] + S[-1]
# for i in range(N - 2, -1, -1):
#     if C[i] + S[i] > S[i + 1]:
#         T[i] = C[i] + S[i]
#     else:
#         T[i] = C[i] + S[i] + C[i + 1]
# 後ろから考えていき、その駅の始発に乗れない場合はプラスで待ち時間を加える
# 後ろからのCのcumsumがいる
# 12 24 6 -> 12 + 24 > 16 -> 12 + 24 + 0 + 52 + 99
# 52 16 4 -> 52 + 16 > 2 -> 52 + 16 + 99
# 99 2 2 -> 101

# やっぱりDPっぽくする必要ありそう？

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
csf = [lr() for i in range(n-1)]
ans = []
for i in range(n):
    time = 0
    for j in range(i,n-1):
        c,s,f = csf[j]
        if time >= s:
            k = time%f
            if k != 0:
                time = (time//f+1)*f+c
            else:
                time = time+c
        else:
            time = s+c
    ans.append(time)
for num in ans:
    print(num)

Submission status: Accepted

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

import numpy as np
for i in range(N-1):
    elapsed_time = 0
    for k in range(i, N-1):
        c, s, f = stations[k]
        # 出発前での時間を求める
        if elapsed_time <= s:
            wait_time = s - elapsed_time
        else:
            x = elapsed_time - s
            next_train = f * np.ceil(x/f)
            wait_time = next_train - x
        elapsed_time += wait_time + c
    print(int(elapsed_time))
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):
    ans = 0
    for j in range(i, n - 1):
        c, s, f = csf[j][0], csf[j][1], csf[j][2]
        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())

Station=[]
for n in range(N-1):
    Station.append(list(map(int,input().split())))
    
S=range(N)
for i in range(len(S)):
    t=0
    for s in range(i,len(S)-1):
        if t <= Station[s][1]:
            t = Station[s][1] + Station[s][0]
        else:
            if t%Station[s][2] != 0:
                t = t + (Station[s][2]-t%Station[s][2]) + Station[s][0]
            else:
                t = t + Station[s][0]
    print(t)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    ans = [0] * N
    for i in range(N - 1):
        time = 0
        for c, s, f in zip(C[i:], S[i:], F[i:]):
            if time < s:
                time = s
            r = (time - s) % f
            time += f - r if r > 0 else 0
            time += c
        ans[i] = time

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


if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
import sys,math
input = sys.stdin.readline

N = int(input())
CSF = [[0,0,0]]
for i in range(1,N):
    CSF.append(list(map(int,input().split())))
for i in range(1,N+1):
    nowtime = 0
    for j in range(i,N):
        if nowtime <=CSF[j][1]:
            depT =CSF[j][1]
        else:
            depT =CSF[j][1] + math.ceil((nowtime-CSF[j][1])/CSF[j][2])*CSF[j][2]

        nowtime = depT+CSF[j][0]
        #print(nowtime,depT)
    print(nowtime)

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

Submission status: Accepted

Solution code:
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())

C = [0] * N
S = [0] * N
F = [0] * N

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

Submission status: Accepted

Solution code:
N = int(input())
csf = [0] * (N - 1)

for i in range(N - 1):
  c, s, f = map(int, input().split())
  csf[i] = [c, s, f]
  
def depart(n):
  now_time = 0
  if n == N - 1:
    return 0
  while n != N - 1:
    next_st = csf[n]
    if now_time <= next_st[1]:
      now_time = next_st[1] + next_st[0]
    else:
      while now_time % next_st[2] != 0:
        now_time += 1
      now_time += next_st[0]
    n += 1
    #print(n, now_time)
  return now_time

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

Submission status: Accepted

Solution code:
def nx(t,s,f):
    if t<s:
        return s
    elif (t-s)%f==0:
        return t
    else:
        return t+f-t%f
n = int(input())
C,S,F = [0]*n, [0]*n, [0]*n
for i in range(n-1):
    C[i], S[i], F[i] = map(int, input().split())

for i in range(n):
    ans = 0
    for j in range(i, n-1):
        ans = nx(ans,S[j],F[j])+C[j]
    print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    csf = [tuple(in_nn()) for _ in range(N - 1)]

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def readinput():
    n=int(input())
    c=[0]
    s=[0]
    f=[0]
    for _ in range(1,n):
        l=list(map(int,input().split()))
        c.append(l[0])
        s.append(l[1])
        f.append(l[2])
    return n,c,s,f

def main(n,c,s,f):
    tList=[]
    t=[0]*(n+1)
    #print(s)
    #print(t)
    for e in range(1,n):
        t[e]=s[e]
        for i in range(e+1,n):
            t[i]=t[i-1]+c[i-1]
            if t[i]<=s[i]:
                t[i]=s[i]
            else:
                if t[i]%f[i]==0:
                    pass
                else:
                    t[i]=((t[i]//f[i])+1)*f[i]
        t[n]=t[n-1]+c[n-1]
        tList.append(t[n])
    tList.append(0)
    return tList

if __name__=='__main__':
    n,c,s,f=readinput()
    ans=main(n,c,s,f)
    for t in ans:
        print(t)

Submission status: Accepted

Solution code:
n = int(input())
train = [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 = train[j]
        t = max(t, s)
        t += (f - t % f) % f
        t += c
    print(t)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    S = []
    for _ in range(N-1):
        c,s,f = map(int,input().split())
        S.append([c,s,f])

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

        print(t)

    print(0)


main()

Submission status: Accepted

Solution code:
n=int(input())
l=[0 for _ in range(n)]

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

Submission status: Accepted

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

print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    CSF = []
    for _ in range(N-1):
        c, s, f = MII()
        CSF.append((c, s, f))

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
tmp=[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):
      data=tmp[j]
      if time<data[1]:
         time=data[1]+data[0]
      else:
         if time%data[2]==0:
            time+=data[0]
         else:
            time+=data[2]-(time%data[2])+data[0]
   print(time)
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):
    res = S[i] + C[i]
    for j in range(i+1,N-1):
        if res < S[j]:
            res = S[j] + C[j]
        else:
            t = (res - S[j]) % F[j]
            res += (F[j] - t) % F[j] + C[j]
    print(res)

print(0)

Submission status: Accepted

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

for i in range(n-1):  
  t = 0
  for j in range(i, n-1):
    c,s,f = l[j]
    while t > s:
      s += f
    t = s+c
  print(t)
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):
    ans=0
    for j in range(i,n-1):
        c = csf[j][0]
        s = csf[j][1]
        f = csf[j][2]
        if j==i:
            ans+=s+c
        else:
            if ans<s:
                ans=s+c
            else:
                ans+=(f-(ans-s)%f)%f+c
    print(ans)
print(0)

Submission status: Accepted

Solution code:
n=int(input())
cost=[]
start=[]
fre=[]

from math import ceil

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


for i in range(n):
    if i==n-1:
        print(0)
        break

    time=start[i]+cost[i]

    for j in range(i+1,n-1):
        if time>=start[j] and time%fre[j]==0:
            time+=cost[j]
        elif time>=start[j] and time%fre[j]!=0:
            time+=fre[j]*ceil(time/fre[j])-time+cost[j]
        else:
            time=start[j]+cost[j]

    print(time)

Submission status: Accepted

Solution code:
def solve(k):
    t = 0
    for i in range(k, N-1):
        if t < S[i]:
            t = S[i] + C[i]
        else:
            if (t - S[i]) % F[i] == 0:
                t += C[i]
            else:
                t = t + (F[i] - (t - S[i]) % F[i]) + C[i]
    return t

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())
res = [0] * N
for i in range(N):
    res[i] = solve(i)
print(*res, sep='\n')

Submission status: Accepted

Solution code:
#coding: utf-8
import math
N = int(input())
L = []
for i in range(N-1):
    l = list(map(int,input().split()))
    L.append(l)

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

print(0)

Submission status: Accepted

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

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 = csf[i][1]
    t += csf[i][0]
    for j in range(i+1, N-1):
        st = csf[j][1]
        f = csf[j][2]
        t = max(st, ((t-1)//f+1)*f)
        t += csf[j][0]

    print(t)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
c,s,f = [],[],[]
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)
    
ans = []
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 += c[j] + f[j]*(0!=time%f[j]) - time%f[j]
    ans.append(time)
        
print('\n'.join(map(str,ans)),'\n0')

Submission status: Accepted

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

for i in range(n):
    t = 0
    for c, s, f in l[i:]:
        t = max(s, t)
        mod = abs(t - s)%f
        if mod != 0:
            t += f - mod
        t += c
    print(t)

Submission status: Accepted

Solution code:
n = int(input())
l = [[0]*3 for i in range(n)]

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 = 0
    for j in range(i, n - 1):
        t = max(l[j][1], t)
        mod = abs(t - l[j][1])%l[j][2]
        if mod != 0:
            t += l[j][2] - mod
        t += l[j][0]
    print(t)

print(0)

Submission status: Accepted

Solution code:
import sys

N = int(input())
CSF = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N - 1)]

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    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)
            break
        c, s, f = CSF[i]
        now = s + c
        for j in range(i + 1, n - 1):
            c, s, f = CSF[j]
            if now >= s:
                diff = now - s
                if diff % f == 0:
                    now += c
                else:
                    now += f - diff % f + c
            else:
                now = s + c
        print(now)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from collections import deque

N = int(input())

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

h = deque([0])

for i in range(N-2,-1,-1):
  t = CSFs[i][1]
  t += CSFs[i][0]
  for j in range(i+1,N-1):
    if t < CSFs[j][1]:
      t = CSFs[j][1]
    else:
      if t%CSFs[j][2] > 0:
        t += CSFs[j][2] - (t%CSFs[j][2])
    t += CSFs[j][0]
  h.appendleft(t)
  
while h:
  print(h.popleft())

Submission status: Accepted

Solution code:
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
    t = 0
    for c, s, f in CSF[i:]:
        if t > s:
            if t % f:
                t += f - t % f
        else:
            t = s
        t += c
    print(t)

Submission status: Accepted

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

if n ==1:
    print(0)
    exit()

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            if temp <= ab[j+1][1]:
                temp = ab[j+1][1] + ab[j+1][0]
            else:
                if temp % ab[j+1][2] ==0:
                    temp += ab[j+1][0]
                else:
                    temp = ((temp//ab[j+1][2])+1) * ab[j+1][2] +ab[j+1][0]
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])

Submission status: Accepted

Solution code:
n = int(input())
stations = [list(map(int, input().split())) for _ in range(n-1)]
for idx in range(n-1):
    t = 0
    for idx2 in range(idx, n-1):
        c, s, f = stations[idx2]
        t = max(t, s)
        if t <= f:
            t = f
        else:
            if t%f > 0:
                t += f - t%f
        t += c
    print(t)
print(0)

Submission status: Accepted

Solution code:
import math

N,*CSFf = map(int, open(0).read().split())
C = [x for x in CSFf[0::3]]
S = [x for x in CSFf[1::3]]
F = [x for x in CSFf[2::3]]
ans = [0] * N
for i in range(N-1):
    temp = S[i] + C[i]
    for j in range(i+1,N-1):
        if temp <= S[j]:
            temp = S[j] + C[j]
        else:
            temp = math.ceil(temp/F[j]) * F[j] + C[j]
    ans[i] = temp
for x in ans:
    print(x)

Submission status: Accepted

Solution code:
n = int(input())
c = [0]*(n-1)
for i in range(n-1):
    c[i] = list(map(int,input().split()))
for i in range(n-1):
    t = c[i][1]
    for j in range(i,n-1):
        if t <= c[j][1]:
            t = c[j][1]
            t += c[j][0]
        else:
            t +=  -(-t//c[j][2])*c[j][2] - t + c[j][0]
    print(t)
print(0)

Submission status: Accepted

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

outputs = [0] * n
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
        else:
            if t%f != 0:
                t = t+f - 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):
  i, j, k = map(int, input().split())
  c.append(i)
  s.append(j)
  f.append(k)

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

print(0)

Submission status: Accepted

Solution code:
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    cc,ss,ff=map(int,input().split())
    c.append(cc)
    s.append(ss)
    f.append(ff)

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

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    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:
            x = csf[i][1]
            for j in range(i + 1, n - 1):
                cj1, sj1, fj1 = csf[j - 1]
                cj, sj, fj = csf[j]
                # print(i, j, x, csf[j - 1], csf[j])
                if x + cj1 + (fj1 - x % fj1) % fj1 <= sj:
                    x = sj
                else:
                    x += cj1 + (fj1 - x % fj1) % fj1
            x += csf[-1][0] + (csf[-1][2] - x % csf[-1][2]) % csf[-1][2]
            print(x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Accepted

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

l=[]
for i in range(n-1):
    cnt=0
    for j in range(i,n-1):
        if cnt>=csf[j][1]:
            tmp_cnt=(cnt-csf[j][1]-1)//csf[j][2]
            cnt=csf[j][1]+(tmp_cnt+1)*csf[j][2]
        else:
            cnt=csf[j][1]
        cnt+=csf[j][0]
    l.append(cnt)

l.append(0)
for l_i in l:
    print(l_i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    C, S, F = [], [], []
    for _ 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):
        t = 0
        for j in range(i, n - 1):
            if t <= S[j]:
                t = S[j]
            elif t % F[j] != 0:
                t += F[j] - t % F[j]
            t += C[j]
        print(t)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

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

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

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
#import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


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


def solve(N, CSF, SMAX=200000):
    A = []
    for c, s, f in CSF:
        for i in range(len(A)):
            if A[i] % f == 0:
                A[i] = max(A[i], s) + c
            else:
                A[i] = max(A[i] - A[i] % f + f, s) + c
        A.append(s + c)
    A.append(0)
    for a in A:
        print(a)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

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

def arrive(time,now):
  if time>a[now][1]:
    time=(time+a[now][2]-1)//a[now][2]*a[now][2]+a[now][0]
  else: time=a[now][1]+a[now][0]
  if now==n-2:
    return time
  else:
    return arrive(time,now+1)

for i in range(n-1):
  print(arrive(a[i][1],i))
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s
        elif (time - s) % f != 0:
            time += (f - (time - s) % f) #待ち時間を足す
        time += c
    print(time)
    
def main2():    
    for i in range(n-1):
        main(i)
    print(0)
main2()