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:
#!/usr/bin/env python3
import sys
import math


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    for i in range(N-1): ##i駅からスタート
        t = 0
        for j in range(i,N-1):
            if t > S[j]:
                t = (S[j]+(math.ceil((t-S[j])/F[j]))*F[j]) + C[j]
            else:
                t = S[j] + C[j]
        print(t)
    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:
# c, s, f

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


def main():
    import math
    import collections
    import itertools

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

    for i in range(n - 1):
        time = 0
        for j in range(i, n - 1):
            times_j = times[j]
            if times_j[1] > time:
                time = times_j[1] + times_j[0]
            else:
                time = times_j[1] + ((time - times_j[1] + times_j[2] - 1) // times_j[2]) * times_j[2] + times_j[0]
        print(time)
    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)]
ans = []

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

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

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]:
      if t%csf[j][2]!=0:
        t+=csf[j][2]-t%csf[j][2]+csf[j][0]
      else:
        t+=csf[j][0]
    else:
      t=csf[j][1]+csf[j][0]
  print(t)

Submission status: Accepted

Solution code:
N = int(input())
L = [[int(x) for x in input().split()] for _ in range(N-1)]

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

# 到着時刻と駅のインデックスを渡すと、次の駅への到着時刻を返す関数
def time_arrive_next_sta(arrival_time, idx):
    if S[idx] <= arrival_time and arrival_time%F[idx] == 0:
        return arrival_time + C[idx]
    elif S[idx] > arrival_time:
        return S[idx] + C[idx]
    else:
        return arrival_time + C[idx] + (F[idx] - arrival_time%F[idx])

ans = []
for i in range(N-1):
    tmp = 0
    for j in range(i, N-1):
        tmp = time_arrive_next_sta(tmp, j)
    ans.append(tmp)

ans.append(0)

for x in ans:
    print(x)

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):
  t = S[i] + C[i]
  i += 1
  while i < N - 1:
    if t == S[i]:
      pass
    elif t > S[i]:
      if t - S[i] % F[i] == 0:
        pass
      else:
        t += F[i] * -(-(t - S[i]) // F[i]) - (t - S[i])
    else:
      t = S[i]
    t += C[i]
    i += 1
  print(t)
print(0)

Submission status: Accepted

Solution code:
n=int(input())
C=list(list(map(int,input().split())) for i in range(n-1))
ans=0
for i in range(n-1):
    start=0
    for j in range(i,n-1):
        if i==j:
            start=C[i][0]+C[i][1]
            continue
        else:
            if start<=C[j][1]:start=C[j][1]
            elif start%C[j][2]==0:start +=0
            else:start +=C[j][2]-(start%C[j][2])
            start +=C[j][0]
    print(start)
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

n = int(input())
stations = []

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

def solve(t,i,stations):
    if i == n-1:
        return t
    c,s,f = stations[i]
    t = max(int((t-0.1)//f + 1)*f,s)
    return solve(t+c,i+1,stations)

for i in range(n):
    print(solve(0,i,stations))

Submission status: Accepted

Solution code:
n = int(input())
l = [[int(x) for x in input().split()] for _ in range(n-1)]
for i in range(n-1):
    ans = 0
    ans += l[i][1] + l[i][0]
    for j in range(i+1, n-1):
        if ans < l[j][1]: ans = l[j][1]
        if ans % l[j][2] != 0:
            ans += l[j][2] - ans % l[j][2]
        ans += l[j][0]
    print(ans)
print(0)

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):
    ct, st, ft = map(int, input().split())
    c[i] = ct
    s[i] = st
    f[i] = ft

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

Submission status: Accepted

Solution code:
import math
N = int(input())  # N個の駅
station = []  # 駅の情報
for _ in range(N-1):
    c, s, f = map(int, input().split())  # 次の駅までc秒, 開始からs秒後に最初の電車, 以後f秒置きに発車する
    station.append((c, s, f))

ans = []  # 最後に0を追加することを忘れないように
time = 0
for i in range(N-1):
    # 今i駅にいる状態
    time = station[i][1]  # 出発するまでにかかる時間
    time += station[i][0]  # 駅i+1にいくまでにかかる時間
    for j in range(i+1, N-1):  # 開始時は駅i+1にいる
        # まだ最初の電車が出ていないなら待つ
        if station[j][1] >= time:  # timeは今経過している時間
            time = station[j][1]  # 最初の時間まで待って出発
            time += station[j][0]  # 次の駅へc秒かかる
            continue  # 次の駅へ
        else:  # もし最初の電車はすでに出発していたなら（time > s）
        # 次の電車まで待つ必要がある
            tmp = time
            tmp -= station[j][1]
            teisuubai = math.ceil(tmp/station[j][2])
            time = station[j][1] + teisuubai * station[j][2]
            time += station[j][0]
    ans.append(time)

ans.append(0)

for a in ans:
    print(a)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input())
ans=[0]*N
def nex(a,ls):
  x=(-a)%ls[2]
  return max([ls[1],a+x])+ls[0]
M=N-1
for i in range(M):
  station=[int(s) for s in input().split()]
  for j in range(i+1):
    ans[j]=nex(ans[j],station)
for e in ans:
  print(e)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
n = int(input())
ary = [list(map(int,input().split())) for i in range(n-1)]
time = 0
dp = [0]*n
for i in range(n-1):
    time = 0
    for j in range(i,n-1):
        if time <= ary[j][1]: time = ary[j][1]
        elif time > ary[j][1]:
            if time % ary[j][2] == 0:time += 0
            else:time += ary[j][2] - time % ary[j][2]
        time += ary[j][0]
    print(time)
print(0)

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    stations = list(map(string_to_int, inputs))
    N = len(stations)
    ret = []
    for i, s in enumerate(stations):
        [C, S, F] = s
        t = S + C
        for j in range(i+1, N):
            if t < stations[j][1]:
                t = stations[j][0] + stations[j][1]
            else:
                w = (t - stations[j][1]) % stations[j][2]
                waiting = 0 if w == 0 else stations[j][2] - w
                t += waiting + stations[j][0]
        ret.append(t)
    ret.append(0)
    return ret


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N-1))
    for r in ret:
        print(r)

Submission status: Accepted

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

for i, (c, s, f) in enumerate(csf):
    t = s + c
    for j in range(i + 1, n - 1):
        C, S, F = csf[j][0], csf[j][1], csf[j][2]
        t = max(t, S)
        t = -(-t // F) * F + 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, (c, s, f) in enumerate(csf):
    t = s + c
    for j in range(i + 1, n - 1):
        C, S, F = csf[j][0], csf[j][1], csf[j][2]
        if t < S:
            t = S + C
        else:
            if (t - S) % F == 0:
                t += C
            else:
                t += F - (t-S) % F + C
    print(t)
print(0)

Submission status: Accepted

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

f = 0
station = 0
for i, (c, s, f) in enumerate(csf):
    t = s + c
    for j in range(i + 1, n - 1):
        C, S, F = csf[j][0], csf[j][1], csf[j][2]
        if t < S:
            t = S + C
        else:
            if (t - S) % F == 0:
                t += C
            else:
                t += F - (t-S) % F + C
    print(t)
print(0)

Submission status: Accepted

Solution code:
N=int(input())

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


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

Submission status: Accepted

Solution code:
import sys
import itertools
from itertools import accumulate
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
N = int(input())
c = [inputs() for _ in range(N-1)]
ans = [0]*(N)
start = [[0]*N for _ in range(N)]
for i in range(N-1):
    start[i][i] = c[i][1]
    for j in range(i,N-1):
        if ans[i]<c[j][1]:
            start[i][j] = c[j][1]
            ans[i] = c[j][1]+c[j][0]
        else:
            ttim=0
            if ans[i]%c[j][2]!=0:
                ttim=c[j][2]-(ans[i])%c[j][2]
            start[i][j] = ttim+ans[i]
            ans[i] = ttim+ans[i]+c[j][0]
print(*ans)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
c = []
s = []
f = []
for i in range(n-1):
    a,b,z = inpl()
    c.append(a)
    s.append(b)
    f.append(z)

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

Submission status: Accepted

Solution code:
N=int(input())
CSF=[]
for i in range(N-1):
    CSF.append(list(map(int,input().split())))
C=[]  #運行時間
S=[]  #スタート
F=[]  #周期
for i in range(N-1):
    C.append(CSF[i][0])
    S.append(CSF[i][1])
    F.append(CSF[i][2])

A=[0]*N

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

for i in A:
    print(i)

Submission status: Accepted

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

for i in range(n):
    s_total = 0
    for j in range(i, n-1):
        if s_total < s[j]:
            s_total += s[j] - s_total
        tmp = (s[j] - s_total) % f[j]
        s_total += tmp
        s_total += c[j]

    print(s_total)

Submission status: Accepted

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


for i in range(0,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:
      time = time
    else:
      time = time + CSF[j][2] - (time % CSF[j][2])
    time = time + CSF[j][0]
  ans.append(time)

for i in ans:
  print i

Submission status: Accepted

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

for i in range(n-1):
	time = li[i][0] + li[i][1]
	for j in range(i+1, n-1):
		now = li[j][1]
		if now < time:
			now += li[j][2] * (-(-(time-now)//li[j][2]))
		time = now
		time += li[j][0]
	print(time)
print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import math

def main(N,C,S,F):
    ans = [0]*N
    for i in range(N-2):
        tmp = S[i]+C[i]
        for j in range(i+1,N-1):
            if tmp<S[j]:
                tmp = S[j]
            elif tmp>S[j] and (tmp-S[j])%F[j]!=0:
                part = math.ceil((tmp-S[j])/F[j])
                tmp = S[j]+F[j]*part
            tmp += C[j]
        ans[i] = tmp
    ans[-2] = C[-1]+S[-1]
    
    for i in ans:
        print(i)

if __name__ == '__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)
    main(N,C,S,F)

Submission status: Accepted

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

for i in range(n):
    res = 0
    for j in range(i, n-1):
        c, s, f = station[j]
        res += max(s - res, (res+f-1)//f*f - res) + c
    print(res)

Submission status: Accepted

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

for i in range(n):
    res = 0
    for j in range(i, n-1):
        c, s, f = station[j]
        res += max(s-res, ((res+(f-1))//f)*f - res) + c
    print(res)

Submission status: Accepted

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

for i in range(n-1):
    res = 0
    for j in range(i, n-1):
        c, s, f = station[j]
        if res == 0:
            res += s + c
        else:
            res += max(s-res, ((res+(f-1))//f)*f - res) + c
    print(res)
else:
    print(0)

Submission status: Accepted

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

res = []
for i in range(0,n-1):
    c = csfs[i][0]
    s =csfs[i][1]
    f = csfs[i][2]
    syuppatu = s
    toutyaku = s+c
    for j in range(i+1,n-1):
        if toutyaku < csfs[j][1]:
            syuppatu = csfs[j][1]
            toutyaku = syuppatu+csfs[j][0]
        else:
            syuppatu = ((toutyaku+csfs[j][2]-1) // csfs[j][2]) * csfs[j][2]
            toutyaku = syuppatu + csfs[j][0]
    res.append(toutyaku)
res.append(0)
for re in res:
    print(re)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

import sys
# input = sys.stdin.readline
sys.setrecursionlimit(100000)
MOD = 10 ** 9 + 7

#N = int(input())
#A = [int(x) for x in input().split()]
#V = [[0] * 100 for _ in range(100)]

N = int(input())
CSF = []
for _ in range(N-1):
    C, S, F = [int(x) for x in input().split()]
    CSF.append((C, S, F))

def f(i):
    ans_r = [0]
    cur = 0
    for c, s, f in CSF[i:]:
        cur = max(cur, s)
        if cur % f != 0:
            cur = cur + (f - (cur % f))
        # print("出発：{}".format(cur))
        cur += c
        # print("到着：{}".format(cur))
        ans_r.append(cur)

    return ans_r[-1]

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

Submission status: Accepted

Solution code:
n = int(input())
csf = zip(*[list(map(int,input().split())) for i in range(n-1)])
c, s, f = [list(i) for i in csf]
ans = [0]
for i in range(n-2, -1, -1):
    for j in range(i, n-2):
        if s[j]+c[j] > s[j+1]: s[j+1] += ((s[j]+c[j] - s[j+1] + f[j+1]-1)//f[j+1])*f[j+1]
    ans.append(c[n-2] + s[n-2])
for i in ans[::-1]: print(i)

Submission status: Accepted

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

for i in range(n):
  time = 0
  for j in range(i,n-1):
    
    time = max(-(-(time-Route[j][1])//Route[j][2])*Route[j][2],0)+Route[j][0]+Route[j][1]
    
  Station[i] = time
for s in Station:
  print(s)

Submission status: Accepted

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

def main():
    N = int(input())
    C = []
    S = []
    F = []
    for _ in range(N-1):
        c,s,f = map(int,input().split())
        C.append(c)
        S.append(s)
        F.append(f)
    
    for i in range(N-1):
        t = 0
        for j in range(i,N-1):
            k = max(0, math.ceil((t - S[j])/F[j]))
            t = S[j] + k*F[j] + C[j]
        print(t)
    print(0)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(n-1):
    if i==0:
        ans.append(st[0][0]+st[0][1])
    else:
        for j in range(len(ans)):
            if ans[j]>=st[i][1] and ans[j]%st[i][2]==0:
                ans[j] += st[i][0]
            elif ans[j]<st[i][1]:
                ans[j] = st[i][0]+st[i][1]
            else:
                a = (ans[j]-st[i][1])%st[i][2]
                a = ans[j]-a
                ans[j] = a+st[i][2]+st[i][0]
        ans.append(st[i][0]+st[i][1])

ans.append(0)
for i in range(len(ans)):
    print(ans[i])

Submission status: Accepted

Solution code:
N = int(input())
c = [list(map(int, input().split())) for _ in range(N - 1)]
anslst = [0] * N
for i in range(N - 1):
    ans = c[i][1] + c[i][0]
    for j in range(i + 1, N - 1):
        if ans <= c[j][1]:
            ans += (c[j][1] - ans) + c[j][0]
        else:
            sho, amari = divmod(ans, c[j][2])
            if amari == 0:
                ans += c[j][0]
            else:
                ans += c[j][0] + (((sho + 1) * c[j][2]) - ans)

    anslst[i] = ans

for i in anslst:
    print(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[i],S[i],F[i] = map(int,input().split())

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline

N = int(input())

ans = [0]

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

    for i in range(len(ans)):
        if s > ans[i]:
            ans[i] = s + c
        else:
            ans[i] = -(-ans[i] // f) * f + c

    ans.append(0)

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

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)

ans = [0] * N
for i in range(N-1):
    for j in range(i+1):
        ans[j] = max(S[i], math.ceil(ans[j]/F[i]) * F[i]) + C[i]

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

Submission status: Accepted

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

# 最初の駅から順に考えていく
for i in range(n):
    time=0
    for j in range(i,n):
        
        if time<table[j][1]: # 今いる駅の最初の出発がまだの時
            time=table[j][1]
        
        elif time%table[j][2]==0: # 次の出発時間ちょうどに到着している時
            pass
        
        else: # 次の出発まで時間がある時
            time+=table[j][2]-(time%table[j][2])
        
        time+=table[j][0] # 次の駅に向かう
    print(time)
print(0)

Submission status: Accepted

Solution code:
import sys


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


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

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

    print(*ans, sep=" ")


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):
    t = 0

    for i in range(start, n - 1):
        if S[i] <= t:
            t = F[i] * (t // F[i] + (t % F[i] != 0))
        else:
            t = S[i]

        t += C[i]

    print(t)

print(0)

Submission status: Accepted

Solution code:
def resolve():
    n = int(input())
    csf = list(list(map(int, input().split())) for _ in range(n - 1))
    for i in range(n - 1):
        now = 0
        for c, s, f in csf[i:]:
            if now <= s:
                now = s + c
            elif now % f == 0:
                now += c
            else:
                now += f - ((now - s) % f) + c
        print(now)
    print(0)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n-1)]
    arr = []
    for i in range(len(csf)):
        arr.append(csf[i:])

    for x in arr:
        ans = x[0][0] + x[0][1]
        for c, s, f in x[1:]:
            if ans > s:
                if ans % f == 0:
                    ans += c
                else:
                    ans += c + f - ans % f
            else:
                ans = c + s
        print(ans)
    print(0)


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)

ans = [0] * N

for i in range(N-1):
    cnt = i
    ans[i] += S[i] + C[i]
    while cnt<N-2:
        if ans[i]<S[cnt+1]:
            ans[i] = S[cnt+1]
        if ans[i]%F[cnt+1]!=0:
            ans[i] += F[cnt+1] - ans[i]%F[cnt+1]
        ans[i] += C[cnt+1]
        cnt += 1

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

Submission status: Accepted

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

for sta in range(n):
  current = 0
  for i in range(sta, n-1):
    if(trains[i][1] >= current):
      current = trains[i][1]
    else:
      if(current % trains[i][2] != 0):
        current += trains[i][2] - (current % trains[i][2])
    current += trains[i][0]
  print(current)

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())
    
    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] + 1) + C[j]
        print(t)
    print(0)


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 i in range(N-1): # iは出発駅,0からN-2
    t = 0
    for j in range(i, N-1): # jは今いる駅,iからN-2
        # 待ち時間の加算
        if t < S[j]:
            t += S[j] - t
        else:
            t += (F[j] - (t % F[j])) % F[j]

        # 移動時間の加算
        t += C[j]
    print(t)
print(0)

Submission status: Accepted

Solution code:
def calc2(time,i):
    c1,s1,f1 = Data[i]

    t = max(time,s1)
    if t % f1 == 0:
        pass
    else:
        t = (t//f1+1)*f1
    return t+c1;

def calc(n,N):
    time = 0
    for i in range(n,N-1):
        time = calc2(time,i)
    return time

N = int(input())
Data = []
Ans = []
for _ in range(N-1):
    c,s,f = map(int,input().split())
    Data.append([c,s,f])
for i in range(N-1):
    print(calc(i,N))
print(0)

Submission status: Accepted

Solution code:
n=int(input())
lists=[list(map(int,input().split())) for _ in range(n-1)]  
for x in range(n):
    nums=x+1
    if nums==n:
        print(0)
    elif nums!=n:
        times=0
        while nums<n:
            if times>lists[nums-1][1]:
                if (times-lists[nums-1][1])%lists[nums-1][2]!=0:
                    a=(times-lists[nums-1][1])%lists[nums-1][2]  
                    times=times+lists[nums-1][2]-a
                    times+=lists[nums-1][0]
                    nums+=1  
                else:
                    times+=lists[nums-1][0]
                    nums+=1
            else:
                times=lists[nums-1][1]
                times+=lists[nums-1][0]   
                nums+=1 
        print(times)

Submission status: Accepted

Solution code:
# ABC084C - Special Trains
def main():
    N, *A = map(int, open(0).read().split())
    CSF = [i for i in zip(*[iter(A)] * 3)]
    ans = []
    for i in range(N):
        cur = 0
        for c, s, f in CSF[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c
        ans.append(cur)
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()