Problem:


Score : 300 points

Problem Statement

A railroad running from west to east in Atcoder Kingdom is now complete.

There are N stations on the railroad, numbered 1 through N from west to east.

Tomorrow, the opening ceremony of the railroad will take place.

On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.

The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.

Here, it is guaranteed that F_i divides S_i.

That is, for each Time t satisfying S_i≤t and t％F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A％B denotes A modulo B, and there will be no other trains.

For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.

Constraints

1≤N≤500

1≤C_i≤100

1≤S_i≤10^5

1≤F_i≤10

S_i％F_i=0

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}

Output

Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x.

Sample Input 1

3
6 5 1
1 10 1

Sample Output 1

12
11
0

We will travel from Station 1 as follows:

5 seconds after the beginning: take the train to Station 2.

11 seconds: arrive at Station 2.

11 seconds: take the train to Station 3.

12 seconds: arrive at Station 3.

We will travel from Station 2 as follows:

10 seconds: take the train to Station 3.

11 seconds: arrive at Station 3.

Note that we should print 0 for Station 3.

Sample Input 2

4
12 24 6
52 16 4
99 2 2

Sample Output 2

187
167
101
0

Sample Input 3

4
12 13 1
44 17 17
66 4096 64

Sample Output 3

4162
4162
4162
0



Sample input:
3
6 5 1
1 10 1


Sample output:
12
11
0

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    mat = [list(map(int, readline().split())) for _ in range(n - 1)]

    for i in range(n):
        ct = 0
        for c, s, f in mat[i:]:
            if ct < s:
                ct = s
            if (ct-s) % f != 0:
                ct = ct + (f - ((ct-s) % f))
            ct += c
        print(ct)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

def time(t, i):
    if t <= data[i][1]:
        return data[i][0] + data[i][1]
    else:
        k = math.ceil((t - data[i][1]) / data[i][2])
        return data[i][0] + data[i][1] + k * data[i][2]

for i in range(N):
    ans = 0
    for j in range(i, N - 1):
        ans = time(ans, j)
    print(ans)

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])

ans = []
for i in range(N-1):
    T = 0
    for j in range(i, N-1):
        if T <= A[j][1]:
            T += A[j][0] + A[j][1] - T
        elif (T-A[j][1])%A[j][2] == 0:
            T +=  A[j][0] 
        else:
            T += A[j][2]  - (T-A[j][1])%A[j][2] + A[j][0] 
    print(T)
    
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] = list(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]
        time += (-time) % f[j]
        time += c[j]
    print(time)

Submission status: Accepted

Solution code:
N = int(input())
li = []
for i in range(N-1):
    c, s, f = map(int, input().split())
    li.append((c,s,f))
for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        t = max(li[j][1], t)
        t += (li[j][2] - t)%li[j][2]
        t += li[j][0]
    print(t)
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] = list(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]
        time += (-time) % f[j]
        time += c[j]
    print(time)

Submission status: Accepted

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

for i in range(n-1):
  now=s[i]+c[i]
  for j in range(i+1,n-1):
    if now<=s[j]:
      now=s[j]+c[j]
    else:
      while (now-s[j])%f[j]!=0:
        now+=1
      now+=c[j] 
  print(now)
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 range(i, N-1):
        if t < CSF[j][1]: #tがまだ最初の運行時刻でない場合
            t = CSF[j][1] #t = Si (始発を待たないといけないので)
        elif t % CSF[j][2] == 0:
            pass
        else:
            t += CSF[j][2] - t % CSF[j][2] 
        t += CSF[j][0] 
    print(t)

Submission status: Accepted

Solution code:
import math
N = int(input())

CSF = []

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

ans = []

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

print(*ans)

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    CSF = [list(map(int, input().split(" "))) for i in range(N-1)]
    for i in range(N-1):
        time = 0
        for j in range(i, N-1):
            n = 0
            while True:
                if CSF[j][1] + n*CSF[j][2] >= time:
                    break
                n += 1
            time = CSF[j][0] + CSF[j][1] + n*CSF[j][2]
        print(time)
    print(0)



if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

for i in range(N-1):
    start = i
    t = 0
    ans = 0
    for j in range(i,N-1):
        c, s, f = sta_info[j][0], sta_info[j][1], sta_info[j][2]
        #print('到着時 ' + str(t))
        if t <= s:
            t = s
            #print('!!!')
        else:
            n = math.ceil((t - s) / f)
            t += s + n * f - t
        #print('発車時 ' + str(t))
        t += c
        
    print(t)
print(0)

Submission status: Accepted

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

for i in range(N-1):
    duration, start, freq = data[i]
    total = start + duration
    for j in range(i+1, N-1):
        d, s, f = data[j]
        if total < s:
            total = s + d
        elif total % f == 0:
            total += d
        else:
            total = f * (total // f) + f + d
    print(total)
print(0)

Submission status: Accepted

Solution code:
import sys

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

def main():
    for i in range(n - 1):
        t = 0
        for c, s, f in csf[i:]:
            if t <= s: t = s + c
            else: t = s + ((t - s + f - 1) // f) * f + c
        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):
    a, b, d = map(int, input().split())
    c.append(a)
    s.append(b)
    f.append(d)
for i in range(n - 1):
    tot = s[i] + c[i] # time to wait + time to travel
    for j in range(i + 1, n - 1):
        if(tot >= s[j]):
            if(tot % f[j] == 0): tot += c[j]
            else: tot += f[j] - (tot % f[j]) + c[j]
        else:
            tot += (s[j] - tot) + c[j]
    print(tot)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
train = []
for i in range(n-1):
    c,s,f = map(int,input().split())
    train.append((c,s,f))
for i in range(1,n+1):
    time = 0
    for j in range(i,n):
        if time <= train[j-1][1]:
            time = train[j-1][1]
        else:
            time = train[j-1][1] + (time - train[j-1][1] + train[j-1][2] - 1) // train[j-1][2] * train[j-1][2]

        time += train[j-1][0]
    print(time)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
l = []
for i in range(N-1):
  s = [int(x) for x in input().split()]
  l.append(s)
for i in range(N-1):
  t = 0
  for j in range(i,N-1):
      t = max(t,l[j][1]) 
      if t % l[j][2] == 0:
        t += l[j][0]
      else:
        t += l[j][2]- t % l[j][2] +l[j][0]
  print(t)
print(0)

Submission status: Accepted

Solution code:
#import collections
#aa = collections.Counter(a) # list to list
def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
    n = int(input())
    C = []
    S = []
    F = []
    for i in range(n-1):
        c,s,f = readInts()
        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 # t + Ci秒後に到着する
            else:
                t = t + F[j] - t % F[j] # 開通式は終わったけど、なんか途中
                # 今は10秒とすると、次発車するのは12秒、 t + 3 - 10 % 3 (1) 秒まで待つことになる
            t += C[j]
        print(t)




if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

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):
  ans = 0
  for j in range(i, n-1):
    ans = c[j] + max([s[j], (1+(ans-1)//f[j])*f[j]])
  print(ans)

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

        ans += C[j]

    print(ans)

Submission status: Accepted

Solution code:
n = int(input())

C, S, F = [0] * n, [0] * n, [0] * n

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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())

ans = [0] * N

for i in range(N):
    cur = S[i] + C[i]
    for j in range(i + 1, N - 1):
        if cur < S[j]:
            cur = S[j] + C[j]
        else:
            d = (cur - S[j])
            cnt = (d + F[j] - 1) // F[j]
            cur = S[j] + cnt * F[j] + C[j]
    ans[i] = cur

for a in ans:
    print(a)

Submission status: Accepted

Solution code:
import math
from collections import namedtuple

Station = namedtuple('Station', 'c s f')

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

  
def measure(start):
  if start > len(stations) - 1:
    return 0
  
  time = 0
  for station in stations[start:]:
    depart_at = station.s\
      if station.s >= time\
      else math.ceil(time / station.f) * station.f
    time = depart_at + station.c
  return time

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

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc084/tasks/abc084_c
# 18:09-18:34 done


def main():
    N = int(input())
    C, S, F = [None] * (N-1), [None] * (N-1), [None] * (N-1)
    for i in range(N-1):
        C[i], S[i], F[i] = map(int, input().split())
    
    ans = [None] * N
    for i in range(N-1):
        tim = 0
        for j in range(i, N-1):
            if tim <= S[j]:
                tim = S[j]
            else:
                if (tim-S[j]) % F[j] > 0:
                    tim = S[j] + ((tim-S[j]) // F[j] + 1) * F[j]
            tim += C[j]
        
        ans[i] = tim
    
    ans[-1] = 0

    for a in ans:
        print(a)


main()
# print(main())

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

Submission status: Accepted

Solution code:
n=int(input())
info=[]
for i in range(n-1):
    c,s,f=map(int,input().split())
    info.append([c,s,f])
def cal(i):
    global info,n
    time=0
    s=(n-1)-i #スタートの番号
    for i in range(i):
        if i==0:
            time+=(info[s][1]+info[s][0])
            s+=1
            continue
        if time<=info[s][1]: #sについた時点でまだ一本目が出発していない。
            time=info[s][1]+info[s][0]
        else:
            sa=time-info[s][1] #一本目が出発してからどのくらい経ったか
            if sa%info[s][2]==0: #ジャストで電車来る。
                time+=info[s][0]
            else:
                time+=((sa//info[s][2]+1)*info[s][2]-sa+info[s][0])
        s+=1
    return time
for i in range(n-1,-1,-1): #i=移動回数
    print(cal(i))

Submission status: Accepted

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

def tr(s,n):
    time = c[s-1][1] + c[s-1][0]
    for j in range(s,n-1):
        if (time <= c[j][1]):
            time = c[j][1]+c[j][0]
        else:        
            a = (time - c[j][1]) // c[j][2]
            if ((time - c[j][1])%c[j][2] != 0):
                a = a+1
            time = c[j][1]+c[j][2]*(a)+c[j][0]
    return time

ans = []
for k in range(1,n):
    ans.append(tr(k,n))
ans.append(0)
print(*ans, sep='\n')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
cfs = [list(map(int, readline().split())) for i in range(n - 1)]
for i in range(n - 1):
    cnt = 0
    for j in range(i, n - 1):
        if cnt < cfs[j][1]:
            cnt = cfs[j][1]
        elif cnt % cfs[j][2] == 0:
            pass
        else:
            cnt += cfs[j][2] - (cnt % cfs[j][2])
        cnt += cfs[j][0]
    print(cnt)
print(0)

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

Submission status: Accepted

Solution code:
import math

N = int(input())
CSF = [()]
for _ in range(N-1):
    CSF.append(tuple(map(int, input().split())))
#print(CSF)

for start in range(1, N):
    time = CSF[start][0] + CSF[start][1]
    for transit in range(start+1, N):
        temp = math.ceil(time / CSF[transit][2]) * CSF[transit][2]
        time = max(temp, CSF[transit][1]) + CSF[transit][0]
    print(time)
print(0)

Submission status: Accepted

Solution code:
from math import ceil
N=int(input())
trains=[list(map(int,input().split())) for _ in range(N-1)]
t=0
cnt=0
for i in range(N):
    t=0
    for j in range(i,N-1,1):
        t=max(ceil(t/trains[j][2]),ceil(trains[j][1]/trains[j][2]))*trains[j][2]
        t=t+trains[j][0]
        #print(t)
        #input()
    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):
    t = 0
    for j in range(i,N-1):
        if t < S[j]:
            t = S[j]
        elif t%F[j] != 0:
            t = t - t%F[j] + F[j] 
            
        t = t + C[j]
    print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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 += f - t % f
        t += c
    print(t)
print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    def f(i: int, s: int):
        if i == N - 1:
            return s
        s = max(s, S[i])
        return f(i + 1, -(-s // F[i]) * F[i] + C[i])
    for i in range(N):
        print(f(i, 0))


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 = [], [], []
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 - S[j]) % F[j] == 0:
             pass
        else:
            t += F[j] - (t - S[j]) % F[j]
        t += C[j]
    print(t)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x = int(input())
l = []
st = 0
ans = 0
k = 0
for i in range(x-1):
  a,b,c = map(int,input().split())
  l.append([a,b,c])

for i in range(x):
  st = 0
  ans = 0
  k = i + 1
  if i == x - 1:
    print(0)
  else:
    ans += l[i][0] + l[i][1]
    while k < x - 1:
#      print("mod:" + str(ans % l[k][2]))
      if ans < l[k][1]:
        ans = l[k][1] + l[k][0]
      elif ans >= l[k][1] and ans % l[k][2] != 0:
        ans += l[k][2] - ans % l[k][2] + l[k][0]
      else:
        ans += l[k][0]
#      print("ans:" + str(ans))
      k += 1
    print(ans)

Submission status: Accepted

Solution code:
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------

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

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

for ans in Ans:
    print(ans)

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())
n-=1
c=[0]*n
s=[0]*n
f=[0]*n
for i in range(n):
    c[i],s[i],f[i]=map(int,input().split())
for i in range(n):
    t=0
    for j in range(i,n):
        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)
print(0)

Submission status: Accepted

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

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

print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
N=int(input())
CSF=[]

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

for i in range(N):
    T=[]
    for j in range(i,N):
        if j==i:
            T.append(0)
        else:
            Next_T=max(-(-T[-1]//CSF[j-1][2])*CSF[j-1][2],CSF[j-1][1])+CSF[j-1][0]
            T.append(Next_T)
    
    print(T[-1])

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

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

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





resolve()

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc084/tasks/abc084_c

N = int(input())    # N個の駅
C_list = []         # 駅iからi+1に向かうまでにかかる時間
S_list = []         # 最初の列車が開通式開始後S秒後に駅iを出発
F_list = []         # F秒おきに発車

for n 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 - 1):

    t = 0
    for j in range(i, N - 1):
        
        # 時刻tにj番目の駅にいる
        # t <= Sなら時刻Sにjを出発して、S + C秒で次の駅に到着する
        if t <= S_list[j]:
            t = S_list[j] + C_list[j]
        
        # そうではなく、t % F == 0なら時刻tにjを出発する
        elif t % F_list[j] == 0:
            t += C_list[j]

        # そうでないなら、開通式開始 t + Fj − (t ％ Fj ) 秒後にjを出発する
        else:
            t += F_list[j] - (t % F_list[j]) + C_list[j]

    print(t)

print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def solve():
    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 fr in range(N-1):
        t = S[fr]
        for to in range(fr+1,N):
            t += C[to-1]
            if to != N-1:
                waittime = 0
                if t < S[to]:
                    waittime = S[to] - t
                elif t % F[to] == 0:
                    waittime = 0
                else:
                    waittime = F[to] - (t%F[to])
                t += waittime
        print(t)
            
    print(0)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import math

N = int(input())
ARR = []

for i in range(N-1):
    ARR.append([int(s) for s in input().split(" ")])


def calculate(n, arr):
    result = []
    for i in range(n-1):
        m = arr[i][1] + arr[i][0]
        for j in range(i+1,n-1):
            nextStart = arr[j][1]
            nextCost = arr[j][0]
            nextFrequency = arr[j][2]

            if m <= nextStart:
                m = nextStart

            if m  > nextStart:
                m = nextStart + math.ceil((m - nextStart)/ nextFrequency)*nextFrequency

            m = m + nextCost
        result.append(m)

    result.append(0)
    return result


result = calculate(N, ARR)


for res in result:
    print(res)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    time = [0]*N
    data = [list(map(int,input().split()))for _ in range(N-1)]
    for i in range(N-1):
        for j  in range(i,N-1):
            c,s,f = data[j]
            if time[i] > s:
                tmp = time[i]-s
                if tmp % f != 0:
                    tmp //= f
                    tmp += 1
                else:
                    tmp //= f
                time[i] = s+tmp*f+c
            else:
                time[i] = s+c
    for t in time:
        print(t)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = [0]*(N-1)
B = [0]*(N-1)
C = [0]*(N-1)
for i in range(N-1):
  A[i],B[i],C[i] = map(int, input().split())
  
#A秒で着く、B秒後に最初、c秒感覚で運行
def arrive_time(i,s): #i駅からN駅, s秒後から
  if i == N-1:
    return s
  if s>B[i]:
    #print(i,s,B[i],C[i])
    start = (s-B[i]+C[i]-1)//C[i]*C[i]+B[i]
  else:
    start = B[i]
  return arrive_time(i+1,start+A[i])
ans = [0]*(N)
for i in range(N):
  ans[i] = arrive_time(i,0)

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

Submission status: Accepted

Solution code:
n = int(input())-1
a = [list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    t = 0
    for c,s,f in a[i:n]:
        if t<=s: t = s+c
        else:t = s+-(-(t-s)//f)*f+c
    print(t)
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())
for i in range(n-1):
  ans=0
  for j in range(i,n-1):
    ans=max((ans+F[j]-1)//F[j]*F[j],S[j])+C[j]
  print(ans)
print(0)