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:
n = int(input())
temp = 0
stations = list()

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


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

Submission status: Accepted

Solution code:
import math
N=int(input())
csf=[tuple(map(int, input().split())) for _ in range(N-1)]
for i in range(N):
	t=0
	for c,s,f in csf[i:]:
		t = math.ceil(max(t, s) / f) * f + c
	print(t)

Submission status: Accepted

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

o = []
for i in range(N):
    s = 0
    while i < N - 1:
        C = CSF[i][0]
        S = CSF[i][1]
        F = CSF[i][2]
        s = (s//F+1)*F if s%F else s
        s = max(s,S)
        s += C
        i += 1
    o.append(s)

print('\n'.join(map(str,o)))

Submission status: Accepted

Solution code:

def read_input():
    n = int(input())

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

    return n, stations


# 時刻currにてstationにいるとして、次の駅にたどり着く時刻を求める
def time_calc(curr, station):
    if curr <= station[1]:
        return station[0] + station[1]

    diff = curr - station[1]
    if diff % station[2] == 0:
        coef = diff // station[2]
    else:
        coef = diff // station[2] + 1
    return station[0] + station[1] + coef*station[2]


def total_time(stations):
    curr = 0
    for station in stations:
        curr = time_calc(curr, station)

    return curr


def submit():
    n, stations = read_input()

    for i in range(n - 1):
        print(total_time(stations[i:]))
    print(0)

if __name__ == '__main__':
    submit()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    csf = []
    for _ in range(N - 1):
        C, S, F = map(int, input().split())
        csf.append((C, S, F))
    
    ans = []
    for i in range(N - 1):
        c, s, _  = csf[i]
        t = c + s
        for ii in range(i + 1, N - 1):
            nc, ns, nf = csf[ii]
            if t > ns:
                ns += ((t - ns) // nf) * nf
                if (t - ns) % nf != 0:
                    ns += nf
            t += nc + ns - t
        ans.append(t)
    ans.append(0)
    
    for t in ans:
        print(t)
    

main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    csf = []
    for _ in range(N - 1):
        C, S, F = map(int, input().split())
        csf.append((C, S, F))
    
    ans = []
    for i in range(N - 1):
        c, s, _  = csf[i]
        t = c + s
        for ii in range(i + 1, N - 1):
            nc, ns, nf = csf[ii]
            if t > ns:
                if (t - ns) % nf == 0:
                    ns += ((t - ns) // nf) * nf
                else:
                    ns += ((t - ns) // nf + 1) * nf
            t += nc + ns - t
        ans.append(t)
    ans.append(0)
    
    for t in ans:
        print(t)
    

main()

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

    print(time)

Submission status: Accepted

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

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):
    p = i
    t = 0
    while p!=n-1:
        # 出発時刻
        if t > l[p][1]:
            if t%l[p][2] != 0:
                t += l[p][2]-t%l[p][2]
        else:
            t = l[p][1]
        # 到着時刻
        t += l[p][0]
        p += 1
    print(t)

Submission status: Accepted

Solution code:
n = int(input())
times = [0]
for i in range(n - 1):
    c, s, f = map(int, input().split())
    for j, t in enumerate(times):
        now = max(t, s)
        times[j] = now + (f - now) % f + c
    times.append(0)
for t in times:
    print(t)

Submission status: Accepted

Solution code:
n = int(input())
lis = [tuple(map(int, input().split())) for i in range(n - 1)]
for i in range(n):
    time = 0
    for t in lis[i:]:
        c, s, f = t
        reg = (time + (f - 1)) // f * f
        time = max(reg, s) + c
    print(time)

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):
        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)
print(0)

Submission status: Accepted

Solution code:
n=int(input())
m=[]
for _ in range(n-1):
  c,s,f=map(int,input().split())
  m.append(0)
  for i in range(len(m)):
    if m[i]>s:
      m[i]=s+((m[i]-s)//f+((m[i]-s)%f>0))*f+c
    else:#m[i]<=s
      m[i]=s+c
m.append(0)
for i in m:
  print(i)

Submission status: Accepted

Solution code:
N = int(input())
C,S,F = [],[],[]
time = []
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 = S[i]+C[i] #駅i -> 駅i+1
  for j in range(i+1,N-1):
    if(t<S[j]): #始発前についたら
     t = S[j]
    else: #始発後についたら(次発以降のとき）
     #tmp = (t-S[j])%F[j]
     if(t%F[j] == 0): tmp = 0
     else: tmp = F[j]-(t%F[j]) 
     t += tmp
    t += C[j] #駅j -> 駅j+1
  time.append(t)
time.append(0)

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

Submission status: Accepted

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

for i in range(N):
    t = 0
    while i < N-1:
        if t < data[i][1]:
            t = data[i][1]
        if (t-data[i][1]) % data[i][2] != 0:
            t += data[i][2] - (t-data[i][1]) % data[i][2]
        t += data[i][0]
        i += 1
    print(t)

Submission status: Accepted

Solution code:
N = int(input())
csf = [[int(i) for i in input().split()] for j in range(N-1)]

for i in range(N-1):
    t = csf[i][1] + csf[i][0]

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

print(0)

Submission status: Accepted

Solution code:
n=int(input())

x=[list(map(int,input().split()))for i in range(n-1)]
for i in range(n):
    time=0
    for j in range(i,n-1):
        c,s,f=x[j]
        if time==0:
            time=c+s
        else:
            if time<s:
                time=s+c
            else:
                time=(time//f+(time%f>0))*f+c
        #print(time)
    print(time)

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):
  t = 0
  for j in range(i,n-1):
    if t < S[j]:
      t = S[j]
    elif t % F[j] == 0:
      pass#到着タイミングと発車タイミングが同じなので待ち時間0
    else:
      t = t + F[j] - (t % F[j])  
    t += C[j]
  print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))

n = II()
train = [list(MI()) for _ in range(n-1)]

for i in range(n-1):
    # 開通式が開始するまでの時間+次の駅に到着するまでの時間
    time = train[i][0] + train[i][1]
    for j in range(i+1, n-1):
        # 駅に着いた時まだ開通式後の最初の電車が駅を発車していない場合
        if time < train[j][1]:
            # 駅を出発する時刻は開通式の時刻になる
            time = train[j][1]
        elif time % train[j][2] == 0:  # そのまま出発可能
            pass
        else: # time % train[j][2] != 0 待ち時間を加算する必要がある
            time += (train[j][2] - (time % train[j][2]))

        time += train[j][0]  # 次の駅へ行くための時間

    print(time)
print(0)

Submission status: Accepted

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

for i in range(N-1):
    a = input().split()
    C.append(int(a[0]))
    S.append(int(a[1]))
    F.append(int(a[2]))

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

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):
    ans = S[i] + C[i]
    j = i + 1
    while j < n-1:
        if ans < S[j]:
            ans += (S[j] - ans) + C[j]
        else:
            if (ans-S[j])%F[j] == 0:
                ans += C[j]
            else:
                ans += C[j] + F[j] - (ans%F[j])
        j += 1
    print(ans)
print(0)

Submission status: Accepted

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

def kaisuu(s,i):
    t = s[i][0] + s[i][1]
    if i != n-1:
        for j in range(i+1,n-1):
            if  t <= s[j][1]:
                t = s[j][0] + s[j][1]
            elif t % s[j][2] == 0:
                t = t + s[j][0]
            else:
                t = t + s[j][0] + (s[j][2] - t % s[j][2])
    return t

for i in range(0,n-1):
    print(kaisuu(s,i))

print(0)

Submission status: Accepted

Solution code:
from sys import stdin

n = int(input())
s = [stdin.readline().rstrip().split() for i in range(n-1)]

def kaisuu(s,i):
    t = int(s[i][0]) + int(s[i][1])
    if i != n-1:
        for j in range(i+1,n-1):
            if  t <= int(s[j][1]):
                t = int(s[j][0]) + int(s[j][1])
            elif t % int(s[j][2]) == 0:
                t = t + int(s[j][0])
            else:
                t = t + int(s[j][0]) + (int(s[j][2]) - t % int(s[j][2]))
    return t

for i in range(0,n-1):
    print(kaisuu(s,i))

print(0)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n = II()
    train = [LI() for _ in range(n - 1)]

    for i in range(n):
        res = 0
        for c, s, f in train[i:]:
            if res <= s:
                res = c + s
            else:
                res += (f - (res - s) % f) % f + c

        print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

n = int(input())
c = [0] * n
s = [0] * n
f = [0] * n

for i in range(1, n):
    c[i], s[i], f[i] = [int(i) for i in input().split(" ")]

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

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import math


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

ans = [0] * n

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

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

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)
t = [0]*N

for i in range(N): #駅iから発車した列車が駅jに着いた
  for j in range(i, N-1):
    if t[i] % F[j] == 0 and t[i] >= S[j]:
      t[i] += C[j]
    elif t[i] < S[j]:
      t[i] = S[j]+C[j]
    elif t[i] >= S[j]:
      t[i] = ((t[i]-S[j])//F[j]+1)*F[j]+S[j]+C[j]
  print(t[i])
#    if j+1 == N:
#      break
#    train(i,j+1)

Submission status: Accepted

Solution code:
from math import ceil
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]

for j in range(N):
    if j == N - 1:
        print(0)
        exit()
    cc, ss, ff = CSF[j]
    t = ss + cc
    for i in range(j + 1, N - 1):
        c, s, f = CSF[i]
        if t <= s:
            t = s + c
        else:
            num = ceil(t / f)
            t = num * f + c
    print(t)

Submission status: Accepted

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

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        # wait for start
        if total_time < s:
            time += s - total_time
        # wait for next train
        else:
            time += (f - total_time % f) % f
        # take train
        time += c
        total_time += time
    print(total_time)

Submission status: Accepted

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

N = int(input())
train = [[int(_) for _ in input().split()] for _ in range(N-1)]

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

print(0)

Submission status: Accepted

Solution code:
n = int(input())
lis = []
for i in range(n - 1):
    lis.append(list(map(int, input().split())))
for j in range(n):
    now = 0
    for i in range(j, n - 1):
        if now < lis[i][1]:
            now += lis[i][1] - now + lis[i][0]
        else:
            if now % lis[i][2] == 0:
                now += lis[i][0]
            else:
                now += lis[i][2] - (now % lis[i][2]) + lis[i][0]
    print(now)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-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 pf(s): return print(s, flush=True)


N = I()
CSF = []
for i in range(1, N):
    CSF.append(LI())

for i in range(N-1):
    # i駅から出発する場合
    current = i
    time = 0
    for csf in CSF[i:]:
        if time < csf[1]:
            # timeのほうが小さい場合、初発まで待つ
            time = csf[1] + csf[0]
        elif time % csf[2] == 0:
            time += csf[0]
        else:
            # timeが初発を超えていた場合、きりのいい次発までまつ
            div = time % csf[2]
            time -= div
            time += csf[2]
            time += csf[0]
        current += 1
    print(time)

print(0)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
  x,y,z=map(int,input().split())
  c.append(x)
  s.append(y)
  f.append(z)
def needtime(t,i):
  if s[i]>=t:
    T=s[i]
  else:
    if (t-s[i])%f[i]==0:
      T=t
    else:
      T=t+f[i]-(t-s[i])%f[i]
  return T+c[i]
for i in range(n):
  t=0
  for j in range(i,n-1):
    t=needtime(t,j)
  print(t)

Submission status: Accepted

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

n = int(input())

c =[]
s =[]
f =[]

for i in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

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

print(0)

Submission status: Accepted

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

def solve(n):
    ans=0
    for i in range(n,N):
        if ans < S[i]:
            ans = S[i]
        a = ans % F[i]
        if a > 0:
            ans += F[i] - a
        ans += C[i]
    return ans

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

Submission status: Accepted

Solution code:
n = int(input())
l = []
for _ in range(n-1):
    l.append([int(i) for i in input().split()])
for j in range(n):
    l_ = l[j:]
    c = 0
    for i in range(n-1-j):
        if c <= l_[i][1]:
            c = l_[i][1]
        elif (c % l_[i][2] != 0):
            c = (c // l_[i][2] + 1) * l_[i][2]
        else:
            c = (c // l_[i][2]) * l_[i][2]
        c += l_[i][0]
    print(c)

Submission status: Accepted

Solution code:
import math
import sys
N = int(input())
if N == 1:
    print(0)
    sys.exit()
c, s, f = [0]*(N-1),[0]*(N-1),[0]*(N-1)
for i in range(N-1):
    c[i], s[i], f[i] = map(int, input().split())
for i in range(N):
    cur = 0
    for j in range(i, N-1):
        if cur <= s[j]:
            cur = s[j] + c[j]
        else:
            cur += (s[j]+f[j]*math.ceil((cur-s[j])/f[j])-cur) + c[j]
    print(cur)

Submission status: Accepted

Solution code:
n = int(input())

c =[]
s =[]
f =[]

for i in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

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

print(0)

Submission status: Accepted

Solution code:
N = int(input())
train = [[] for _ in range(N)]
L = []
for cnt in range(N - 1):
    l = list(map(int,input().split()))
    L.append(l)

from math import ceil

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        k = max(0,ceil((now - L[i][1]) / L[i][2]))
        now = L[i][1] + L[i][2] * k
        now += L[i][0]
    print(now)

Submission status: Accepted

Solution code:
import math
N = int(input())
tc,ts,tf = 0,0,0
C, S, F, =[], [], []
t = 0
for i in range(N-1):
    tc,ts,tf = map(int,input().split())
    C.append(tc)
    S.append(ts)
    F.append(tf)
#print(C,S,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]
        else:
            t = math.ceil(t/F[j]) * F[j] + C[j]
    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):
    t = 0
    for j in range(i, N - 1):
        if t <= S[j]:
            t = S[j]
        else:
            t = (t // F[j] + (t % F[j] > 0)) * F[j]
        t += C[j]
    print(t)

Submission status: Accepted

Solution code:
N=int(input())
Info=[list(map(int,input().split(' '))) for i in range(N-1)] #[[C S F] [C S F] ...]
C=[info[0] for info in Info]
S=[info[1] for info in Info]
F=[info[2] for info in Info]

def gotoN(start): #startは駅番号と同一にする
	global C,S,F
	if start==N:
		return 0
	else:
		stn = start
		t = S[stn-1]
		while stn < N:
			t = max(((t-1)//F[stn-1]+1)*F[stn-1], S[stn-1])+C[stn-1]
			stn += 1
		return t

for i in range(1,N+1):
	print(gotoN(i))

Submission status: Accepted

Solution code:

n = int(input())


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

# print(csf)

for i in range(n-1):

    ans = csf[i][0] + csf[i][1]

    for j in range(i+1,n-1):
        here = csf[j]
        
        ans = max(ans,here[1])
        
        rm = ans % here[2]
        if rm != 0:
            ans += here[2] - rm
            
        ans += here[0]

#        print(ans)
    print(ans)

print(0)

Submission status: Accepted

Solution code:
from math import ceil


def solve(string):
    n, *csf = map(int, string.split())
    f_list = []
    for c, s, f in zip(csf[::3], csf[1::3], csf[2::3]):
        f_list = [c + ceil((max(_f, s)) / f) * f for _f in f_list]
        f_list.append(c + s)
    f_list.append(0)
    return "\n".join([str(_f) for _f in f_list])


if __name__ == '__main__':
    n = int(input())
    print(solve('{}\n'.format(n) + '\n'.join([input() for _ in range(n - 1)])))

Submission status: Accepted

Solution code:
N = int(input())
inputs = [list(map(int, input().split())) for i in range(N-1)]
if len(inputs) != N:
  inputs. append([0, 0, 1])

for i in range(N):
  reach = 0
  for j in range(i, N):
    info = inputs[j]
    if reach < info[1]:
      reach = info[1]
    if (reach-info[1])%info[2] != 0:
      reach += (info[2] - (reach-info[1])%info[2])
    reach += info[0]
    
  print(reach)

Submission status: Accepted

Solution code:
n=int(input())
ls=[]
for i in range(n-1):
  c,s,f=map(int,input().split())
  ls.append(s)
  ls=list(map(lambda x:(x+c+(0 if x%f==0 else (f-x%f)) if s<=x else s+c),ls))
ls=ls+[0]
print(*ls,sep="\n")

Submission status: Accepted

Solution code:
from math import ceil
n = int(input())
cur = [0]*n
for i in range(n-1):
	c,s,f = map(int,input().split())
	for j in range(i+1):
		cur[j] = max(s,ceil(cur[j]/f)*f)+c
print(*cur,sep='\n')

Submission status: Accepted

Solution code:
from math import ceil

n = int(input())
CSF = [list(map(int,input().split())) for i 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])%CSF[j][2] != 0 or time-CSF[j][1]<0:
			time = max(CSF[j][1],CSF[j][2]*(ceil(time/CSF[j][2])))
		time += CSF[j][0]
	print(time)
print(0)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    n = I()
    a = LIR(n-1)
    for i in range(n):
        t = 0
        x = i
        while x < n-1:
            if t < a[x][1]:
                t = a[x][1]
            t += (a[x][2]-t)%a[x][2]
            t += a[x][0]
            x += 1
        print(t)

#D
def D():
    def check(n):
        if n == 1:
            return False
        i = 2
        while i*i <= n:
            if n%i == 0:
                return False
            i += 1
        return True
    f = [0 for i in range(100001)]
    for i in range(1,100001):
        f[i] += f[i-1]
        if check(i):
            if check((i+1)//2):
                f[i] += 1
    q = I()
    for i in range(q):
        l,r = LI()
        print(f[r]-f[l-1])

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
def tcalc(station):
  time = 0
  for i in range(station-1,n-1):
    f = l[i][2]
    s = l[i][1]
    c = l[i][0]
    time = max(((time-1)//f+1)*f, s)+c
  return time
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n-1)]
for j in range(1,n+1):
  print(tcalc(j))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
al=[];bl=[];cl=[]
for _ in range(n-1):
  x,y,z=map(int,input().split())
  al.append(x);bl.append(y);cl.append(z)
for i in range(n-2):
  time=al[i]+bl[i]
  for j in range(i+1,n-1):
    if time<=bl[j]:
      time=bl[j]+al[j]
    else:
      time=time+(-1*time)%cl[j]+al[j]
  print(time)
print(al[-1]+bl[-1])
print(0)

Submission status: Accepted

Solution code:
#084-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
D=[]
for i in range(n-1):
    D.append(IL())
for i in range(n):
    t=0
    for j in range(i,n-1):
        if t<D[j][1]:
            t=D[j][1]+D[j][0]
        else:
            for k in range(100):
                if (t+k)%D[j][2]==0:
                    t+=k+D[j][0]
                    break
    print(t)

Submission status: Accepted

Solution code:
N = int(input())

CSFn = [[int(j) for j in input().split()] for i in range(N - 1)]


def next(s):
    t = 0

    for Ci, Si, Fi in CSFn[s:]:
        # 始発
        if t < Si:
            t = Si

        # タイムラグ
        elif t % Fi:
            t += Fi - t % Fi

        # 列車の移動時間
        t += Ci

    return t


def main():
    # 出発駅
    for i in range(N - 1):
        t = next(i)
        print(t)

    print(0)

    return


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)


def next(s, t):
    # 始発
    if t < S[s]:
        t = S[s]

    # タイムラグ
    elif t % F[s]:
        t += F[s] - t % F[s]

    # 列車の移動時間
    t += C[s]

    return t


def main():
    # 出発駅
    for i in range(N - 1):
        t = next(i, 0)

        # 途中駅
        for j in range(i + 1, N - 1):
            t = next(j, t)

        print(t)

    print(0)

    return


main()

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):
        C, S, F = csf[j]
        if t < S:
            t = S
        elif t % F:
            t = t + F - t%F
        t += C
    print(t)

Submission status: Accepted

Solution code:
def special_trains(N: int, CSF: list) -> list:
    res = []
    for i in range(N):
        t = 0
        for c, s, f in CSF[i:]:
            if t < s:
                t = s
            if t % f != 0:
                t = (t + f) - (t % f)
            t = t + c
        res.append(t)
    return res


if __name__ == "__main__":
    N = int(input())
    CSF = [tuple(map(int, input().split())) for _ in range(N-1)]
    ans = special_trains(N, CSF)
    for a in ans:
        print(a)