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())
c_list=[]
s_list=[]
f_list=[]
for i in range(n-1):
    c,s,f=map(int,input().split())
    c_list.append(c)
    s_list.append(s)
    f_list.append(f)
for i in range(n):
    now=0
    j=i
    while j<n-1:
        if now>=s_list[j]:
            now=f_list[j]*((now+f_list[j]-1)//f_list[j])+c_list[j]
        else:
            now=s_list[j]+c_list[j]
        j=j+1
    print(now)

Submission status: Accepted

Solution code:
n=int(input())-1
csf=[list(map(int,input().split())) for i in range(n)]
# print(csf)
for i in range(n):
    time=0
    for j in range(i,n):
        if time<csf[j][1]:
            time=csf[j][1]+csf[j][0]
        elif time%csf[j][2]!=0:
            time+=csf[j][2]-(time%csf[j][2])+csf[j][0]
        else:
            time+=csf[j][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):
    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:
import sys
input = sys.stdin.readline

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

for i in range(N - 1):
    time = L[i][0] + L[i][1]
    
    for j in range(i + 1, N - 1):
        time = max(time, L[j][1])
        t = time - L[j][1]
        if t % L[j][2] == 0:
            time += L[j][0]
        else:
            time += L[j][0] + (L[j][2] - t % L[j][2])
        
    print(time)

print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def nextsta(t,c,s,f):
    if t<=s:return s
    elif t%f == 0:return t
    else:return(t + f - t%f)
N=int(input())-1
CSF = [[int(i) for i in input().split()] for i in range(N)]
for StartSt in range(N):
    cursta = StartSt
    curtime = 0
    for st in range(StartSt,N):
        c,s,f = CSF[cursta]
        curtime = nextsta(curtime,c,s,f) + c
        cursta += 1
    print(curtime)
print(0)

Submission status: Accepted

Solution code:
# ABC084C - Special Trains
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().split())) for _ in range(n - 1))
    for i in range(n):
        cur = 0
        for c, s, f in arr[i:]:
            if cur <= s:
                cur = s + c
            elif cur % f == 0:
                cur += c
            else:
                cur += f - cur % f + c
        print(cur)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC084C - Special Trains
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().split())) for _ in range(n - 1))
    for i in range(n):
        cur = 0
        for c, s, f in arr[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c
        print(cur)


if __name__ == "__main__":
    main()

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

Submission status: Accepted

Solution code:
N=int(input())

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


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

## x 以上の最小の　y の倍数
def ceil(x,y):
    if x % y == 0:
        return x
    else:
        return (x//y+1)*y

for i in range(n):
    t = 0
    for j in range(i,n-1):
        t = max(ceil(t,f[j]),s[j])+c[j]
    print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
c = [0]*n
s = [0]*n
f = [0]*n
ans = [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] is 0:
      t = t
    else:
      t = t + f [j] - t % f [j];
    t += c[j];
  print(t)

Submission status: Accepted

Solution code:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N = n()
stations = []
for i in range(N-1):
    stations.append(nl())

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

print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def start(x,s,f):
  # x 以降での最初の出発時刻
  if x <= s:
    return s
  return (x+f-1)//f*f

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

def F(i):
  x = 0
  for c,s,f in CSF[i:]:
    x = start(x,s,f)
    x += c
  return x

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

Submission status: Accepted

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


def solve(i):
    curStation = i
    ans = CSF[curStation][1]
    while curStation < N-1:
        if ans >= CSF[curStation][1]:
            t = (ans - CSF[curStation][1]) // CSF[curStation][2]
            if (ans - CSF[curStation][1]) % CSF[curStation][2] == 0:
                ans = CSF[curStation][1] + CSF[curStation][2] * t
            else:
                ans = CSF[curStation][1] + CSF[curStation][2] * (t+1)
        else:
            ans = CSF[curStation][1]
        ans += CSF[curStation][0]
        curStation += 1
        if curStation == N-1:
            break
    return ans


for i in range(N):
    if i == N-1:
        print(0)
    else:
        print(solve(i))

Submission status: Accepted

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

time=[]
for i in range(n-1):
    t=train[i][1]+train[i][0]
    for j in range(i+1,n-1):
        if t<train[j][1]:
            t=train[j][1]+train[j][0]
        elif (t-train[j][1])%train[j][2]==0:
            t+=train[j][0]
        else:
            t+=train[j][2]-(t-train[j][1])%train[j][2]+train[j][0]
    print(t)

print(0)

Submission status: Accepted

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

for i in range(N-1):
    t=arr[i][0]+arr[i][1]
    #print('station No',i)
    for j in range(N-1-i-1):
        #print('arrive',t)
        c,s,f=arr[i+j+1][0],arr[i+j+1][1],arr[i+j+1][2]
        t=max(s,((t-s-1)//f+1)*f+s)
        #print(c,s,f)
        #print(t)
        #print('deperture',t)
        t+=c
        #print('arrive next',t)
    print(t)
print(0)

Submission status: Accepted

Solution code:
import math

N = int(input())

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

for i in range(0, N - 1):
    arrive_time = CSFs[i][0] + CSFs[i][1]
    for j in range(i + 1, N - 1):
        if arrive_time <= CSFs[j][1]:
            arrive_time = CSFs[j][1]
        elif arrive_time % CSFs[j][2] == 0:
            arrive_time = arrive_time
        else:
            # t <= S + F * k (k = integer)
            k = math.ceil((arrive_time - CSFs[j][1]) / CSFs[j][2])
            arrive_time = CSFs[j][1] + CSFs[j][2] * k
        arrive_time += CSFs[j][0]
    print(arrive_time)
print(0)

Submission status: Accepted

Solution code:
N = int(input())

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

for i in range(0, N - 1):
    initial_move_time = CSFs[i][0] + CSFs[i][1]
    for j in range(i + 1, N - 1):
        if initial_move_time <= CSFs[j][1]:
            initial_move_time = CSFs[j][1]
        elif initial_move_time % CSFs[j][2] == 0:
            initial_move_time = initial_move_time
        else:
            initial_move_time = initial_move_time + CSFs[j][2] - initial_move_time % CSFs[j][2]
        initial_move_time += CSFs[j][0]
    print(initial_move_time)
print(0)

Submission status: Accepted

Solution code:
import math
N = int(input())
ST = [[int(i) for i in input().split()] for j in range(N-1)]
for i in range(N-1):
    t = ST[i][1] + ST[i][0]
    for j in range(i+1,N-1):
        t = max(t, ST[j][1])
        k = math.ceil((t-ST[j][1])/ST[j][2])
        t = k * ST[j][2] + ST[j][1] + ST[j][0]
    else:
        print(t)
print(0)

Submission status: Accepted

Solution code:
l = input().split()
N = int(l[0])

C = []
S = []
F = []

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

# print(N, C, S, F)

for i in range(N - 1):
    spent = 0
    for j in range(i, N - 1):
        c = C[j]
        s = S[j]
        f = F[j]
        if spent < s:
            spent = s
        remain = (spent - s) % f
        if remain != 0:
            spent += f - remain
        spent += c
    print(spent)
print(0)

Submission status: Accepted

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


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):

    CSF = list(zip(C,S,F))

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

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int()] * (N-1)  # type: "List[int]" 
    S = [int()] * (N-1)  # type: "List[int]" 
    F = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
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())


def solve(c,s,f,i,cnt,n):
    if i == n-1:
        return print(cnt)
    else:
        if cnt < s[i]:
            cnt = s[i]
        loss = (cnt-s[i])%f[i]
        if loss == 0:
            return solve(c,s,f,i+1,cnt+c[i],n)
        else:
            return solve(c,s,f,i+1,cnt+c[i]+(f[i]-loss),n)

for i in range(n):
    solve(c,s,f,i,0,n)

Submission status: Accepted

Solution code:
N = int(input())
para = [[i for i in map(int,input().split())] for i in range(N-1)]
dp = [0]*(N)

for i in range(N):
    for j in range(N-i-1):
        if dp[i] >= para[i+j][1] and dp[i]%para[i+j][2] == 0 :
            dp[i] += para[i+j][0]
        elif  dp[i] < para[i+j][1]: 
            dp[i] = para[i+j][1] + para[i+j][0]
        else:
            a = dp[i] // para[i+j][2] 
            dp[i] = (a+1)*para[i+j][2] + para[i+j][0]
    print(dp[i])

Submission status: Accepted

Solution code:
# 基本シミュレーション
# Nが小さいので予めN回の入力を保存しておく方針

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

for i in range(n - 1):
    current_time = 0
    for data in inputs[i:]:
        c, s, f = data
        if current_time < s:
            # 開通式前なので待つ（始発に乗る）
            current_time = s
        else:
            # すでに開通式を終えて運行が開始されている
            # 次に出る最も速いやつまで待つ
            # c + f * nを満たすnのうちcurrenttimeを超える最小のnを求める
            # にぶたんでええか
            left, right = 0, 10 ** 9
            while left < right:
                mid = (left + right) // 2
                if (s + f * mid) >= current_time:
                    right = mid
                else:
                    left = mid + 1
            # left が n
            current_time = s + f * left
        # 乗車時間
        current_time += c
    print(current_time)
# N番目からN番目には0秒
print(0)

Submission status: Accepted

Solution code:
N = int(input())

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



def next_start_time(arrive, C, S, F):
    for i in range(1000):
        if arrive > S:
            i = (arrive - S) // F
            if arrive <= S + i * F:
                break
            else:
                i = i + 1
                break
        elif arrive <= S + i * F:
            break
    return S + (i * F) + C


for i in range(N - 1):
    ans = 0
    for j in range(i, N - 1):
        ans = next_start_time(ans, station[j][0], station[j][1], station[j][2])
    print(ans)

print(0)

Submission status: Accepted

Solution code:
N = int(input())
ans = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    
    for i,a in enumerate(ans):
        if (a-s)%f == 0 and a > s:
            ans[i] += c
        elif a < s:
            ans[i] = c + s
        else:
            ans[i] += c + f - (a-s) % f
    ans.append(c+s)

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

Submission status: Accepted

Solution code:
N = int(input())

C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)

for n in range(N - 1):
    C[n], S[n], F[n] = map(int, input().split())

for t in range(0, N - 1):
    route_time = S[t]
    for i in range(t, N - 1):
        route_time = route_time + C[i]
        if i != N - 2:
            if route_time >= S[i + 1] and route_time % F[i + 1] == 0:
                continue
            elif route_time >= S[i + 1] and route_time % F[i + 1] != 0:
                route_time = (route_time // F[i + 1]) * F[i + 1] + F[i + 1]
            else:
                route_time = S[i + 1]
    print(route_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):
  time = 0
  for j in range(i, N):
    if j == N-1:
      print(time)
      break ## (まあどうせここで処理終わりなんだけど、高速化のため)
    if time < CSF[j][1]:
      time = CSF[j][0] + CSF[j][1]
    elif time % CSF[j][2] == 0:
      time += CSF[j][0]
    else:
      time += CSF[j][0] + (CSF[j][2] - time % CSF[j][2])
    #print(i,j,time)

Submission status: Accepted

Solution code:
n = int(input())
CSF = [list(map(int,input().split())) for _ in range(n-1)]
Ans = []
from math import ceil
count = 0
for c,s,f in CSF:
    for i in range(count):
        Ans[i] = max(ceil(Ans[i]/f)*f + c , s + c)
    count += 1
    Ans.append(s+c)
print(*Ans,sep = "\n")
print(0)

Submission status: Accepted

Solution code:
import math


def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num - 1)]

    for i in range(num - 1):
        c, s, f = data[i]
        now_time = s + c
        for j in range(i + 1, num - 1):
            c_now, s_now, f_now = data[j]
            if now_time <= s_now:
                now_time = s_now + c_now
            else:
                now_time = math.ceil(now_time / f_now) * f_now + c_now
        print(now_time)
    print(0)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
  ci, si, fi = list(map(int, input().split()))
  c.append(ci)
  s.append(si)
  f.append(fi)

for i in range(n-1):
  t = s[i]
  for j in range(i, n-2):
    t = t + c[j]

    if t > s[j+1]:
      cycle = math.ceil((t - s[j+1]) / f[j+1])
      t = s[j+1] + cycle * f[j+1]
    else:
      t = s[j+1]
  t = t + c[n-2]
  print(t)
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):
    t=0
    for j in csf[i:]:
        c,s,f=j
        if(s>=t):
            t=s+c
        else:
            t=f*-(-t//f)+c
    print(t)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    ci,si,fi=list(map(int,input().split()))
    c.append(ci)
    s.append(si)
    f.append(fi)

for start in range(n-1):
    time=0
    for i in range(start,n-1):
        time=max(s[i],math.ceil(time/f[i])*f[i])+c[i]
    print(time)
print(0)

Submission status: Accepted

Solution code:
from math import ceil

n = int(input())

cs = []
ss = []
fs = []

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

for i in range(n):
    t = 0
    for j in range(i, n-1):
        if t < ss[j]:
            t = ss[j]
        t = ceil(t / fs[j]) * fs[j]
        t += cs[j]
    print(t)

Submission status: Accepted

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


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    ret = []
    for i in range(N - 1):
        tmp = 1
        for j in range(i, N - 1):
            if tmp > S[j]:
                tmp = ((tmp - S[j] - 1) // F[j] + 1) * F[j] + S[j] + C[j]
            else:
                tmp = S[j] + C[j]
        ret.append(tmp)
    ret.append(0)
    for r in ret:
        print(r)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int()] * (N-1)  # type: "List[int]" 
    S = [int()] * (N-1)  # type: "List[int]" 
    F = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(len(CSF)):
    ans = 0
    ans += CSF[i][1] + CSF[i][0]
    for j in range(i + 1, len(CSF)):
        if ans < CSF[j][1]:
            ans += CSF[j][1] - ans
        if ans % CSF[j][2] == 0:
            pass
        else:
            ans += CSF[j][2] - ans % CSF[j][2]
        ans += CSF[j][0]

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

Submission status: Accepted

Solution code:
n=int(input())
l=[]
T=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
	t=0
	for c,s,f in T[i:]:
		t=max(t,s+f*max(0,(t-s-1)//f+1))+c
	l.append(t)
l.append(0)
for x in l:
    print(x)

Submission status: Accepted

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

ans = []
for i in range(N - 1):
    cnt = 0
    for j in range(i, N - 1):
        if cnt < X[j][1]:
            st = X[j][1]
        elif cnt % X[j][2] == 0:
            st = cnt
        else:
            st = cnt + X[j][2] - (cnt % X[j][2])
        cnt = st + X[j][0]
    ans.append(cnt)
ans.append(0) 
print(*ans, sep='\n')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):

    def hasha(curr, ith):
        if curr > S[ith]:
            return S[ith] + F[ith]*(-(-(curr-S[ith])//F[ith]))
        else:
            return S[ith]

    ans = []
    for i in range(N-1):        # 開始駅
        buf = 0
        for j in range(i, N-1):  # 現在駅
            buf = hasha(buf, j) + C[j]
        ans.append(buf)
    print(*ans, sep="\n")
    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:
#https://atcoder.jp/contests/abc084/tasks/abc084_c
N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(1,N+1):
    if i == N:
        print(0)
        break
    time = 0
    for j in range(i,N):
        if time == 0:
            time += CSF[j-1][1]  #はじめはS[j]秒経過  
        else:
            if time < CSF[j-1][1]:
                time = CSF[j-1][1]
           # lv = CSF[j-1][1]
            while time % CSF[j-1][2] != 0:  #timeがS[j]+F[j]またはS[j]より小さいなら
                time +=1   #F[j]経過
        time += CSF[j-1][0]  #その後C[j]秒経過
    print(time)

Submission status: Accepted

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

ans = [0] * N

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

    ans[i] = tmp
    print(ans[i])
        
print(ans[N-1])

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

ans = []

for n in range(N-1):
    c, s, f = CSF[n]
    cn, sn, fn = CSF[n+1]
    
    for m in range(N-n-2):
                
        if s+c > sn:
            sn = int(np.ceil((s+c)/fn)*fn)
        c, s, f = cn, sn, fn
        cn, sn, fn = CSF[n+m+2]
        
    ans.append(s+c)
    
ans.append(0)

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

Submission status: Accepted

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

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

        t += c
    print(t)

Submission status: Accepted

Solution code:
N = int(input())
trains = [list(map(int, input().split())) for _ in range(N-1)]
for i in range(N-1):
    t = 0
    t += trains[i][1] + trains[i][0]
    for j in range(i+1, N-1):
        c, s, f = trains[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:
N = int(input())
CSF = [list(map(int,input().split())) for i in range(N-1)]
ans = []

for i in range(N-1):
	res = 0
	for c,s,f in CSF[i:]:
		if res < s:
			res = s
		if res % f != 0:
			res += f - res % f
		res += c
	ans.append(res)
ans.append(0)
for a in ans:
	print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
ans=[0]*N
for i in range(1,N):
    C,S,F=map(int,input().split())
    for j in range(i):
        ans[j]=max(S,((F+ans[j]-1)//F)*F)+C
[print(x) for x in ans]

Submission status: Accepted

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

for i in range(n):
    point = i
    ans = 0
    while point < n-1:
        c, s, f = csf[point][0], csf[point][1], csf[point][2]
        if ans < s:
            ans += s-ans+c
        else:
            if ans%f != 0:
                ans += f-(ans%f)
            ans += c
        point += 1
    print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]
for k in range(N):
  t = 0
  for i in range(N-1-k):
    j = k + i
    if t <= CSF[j][1]:
      t = CSF[j][1] + CSF[j][0]
    else:
      t = math.ceil((t-CSF[j][1])/CSF[j][2])*CSF[j][2]+CSF[j][1]+CSF[j][0]
  print(t)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import math

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

    else:
        # start
        time = csf[i][1] + csf[i][0] # s_i + c_i

        if i != n - 2:
            station = i
            while True:
                station += 1
                c = csf[station][0]
                s = csf[station][1]
                f = csf[station][2]
                time = math.ceil(max(time - s, 0) / f) * f + s
                time += c

                if station == n-2:
                    break

        print(time)

Submission status: Accepted

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

def start_from(i,t):
  if i==N:
    return t
  else:
    c,s,f = CSF[i]
    departure = max(s, (t//f + bool(t%f))*f)
    return start_from(i+1, departure + c)
  
for i in range(1,N):
  print(start_from(i, 0))
print(0)

Submission status: Accepted

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n = f()[0]
    trains = []
    for i in range(n-1):
        trains.append(f())

    for i in range(n):
        time = 0
        for train in trains[i:]:
            start_time = (time//train[2] +  (0 if time%train[2]==0 else 1))* train[2] if time > train[1] else train[1]
            time = start_time + train[0]

        print(time)

        

solve()