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

ans = [0]*(n+1)
for i in range(1, n):
    t = S[i]+C[i]
    for j in range(i+1, n):
        t = S[j]+C[j]+[0, -(-(t-S[j])//F[j])*F[j]][S[j] < t]
    ans[i] = t

print(*(x for x in ans[1:]), sep="\n")

Submission status: Accepted

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

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

for index in range(len(stations)):
  time = 0
  sum_time = 0
  for c, s, f in stations[index:]:
    if time <= s:
      time = s + c
    else:
      diff = time - s
      count = math.ceil(diff/f)
      time = s + f*count + c
  print(time)
print(0)

Submission status: Accepted

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






print(0)

Submission status: Accepted

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

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):
    ans=0
    for j in range(i,n-1):
        c,s,f=map(lambda x:x,csf[j])
        if ans<=s: ans=s+c
        else: ans=math.ceil(ans/f)*f+c

    print(ans)

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    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)
elif icase==1:
    n=3
    c=[6,1]
    s=[5,10]
    f=[1,1]
elif icase==2:
    n=4
    c=[12,52,99]
    s=[24,16,2]
    f=[6,4,2]
elif icase==3:
    n=4
    c=[12,44,66]
    s=[13,17,4096]
    f=[1,17,64]

def nipf(ii,tt,s,f):
#    print(ii)
    if tt<=s[ii]:
        return 0
    else:
        n=(tt-s[ii]-1)//f[ii]+1
        return n

for i in range(n-1):
    tt=s[i]+c[i]
    for ii in range(i+1, n-1):
#        print("1: i:",i,"ii:",ii,"tt:",tt,"n-2:",n-2)
        nip=nipf(ii,tt,s,f)
#        print("2: i:",i,"ii:",ii,"tt:",tt,"nip:",nip)
        tt=s[ii]+c[ii]+nip*f[ii]
    print(tt)
print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
CSF=[list(map(int,input().split())) for _ in range(1,N)]
for i,csf in enumerate(CSF):
    c,s,f=csf[0],csf[1],csf[2]
    ans=c+s
    for j in range(i+1,N-1):
        csf_=CSF[j]
        c_,s_,f_=csf_[0],csf_[1],csf_[2]
        if ans<s_:
            ans=s_
        elif ans%f_!=0:
            ans=ans+f_-ans%f_
        ans+=c_
    print(ans)
print(0)

Submission status: Accepted

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

for i,csf in enumerate(CSF):
    c,s,f=csf[0],csf[1],csf[2]
    ans=c+s
    for j in range(i+1,N-1):
        csf_=CSF[j]
        c_,s_,f_=csf_[0],csf_[1],csf_[2]
        if ans<s_:
            ans=s_
        elif ans%f_!=0:
            ans=ans+f_-ans%f_
        ans+=c_
    print(ans)
print(0)

Submission status: Accepted

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

for i,csf in enumerate(CSF):
    c,s,f=csf[0],csf[1],csf[2]
    ans=c+s
    for j in range(i+1,N-1):
        csf_=CSF[j]
        c_,s_,f_=csf_[0],csf_[1],csf_[2]
        while True:
            if (ans>=s_) and (ans%f_==0):
                ans+=c_
                break
            ans+=1
    print(ans)
print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin 
input=stdin.readline
def main():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=(now+d-1)//d*d+a
    print(now)
if __name__=="__main__":
  main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=(now+d-1)//d*d+a
    print(now)
if __name__=="__main__":
  main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=(now+d-1)//d*d+a
    print(now)
if __name__=="__main__":
  f()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=-(-now//d)*d+a
    print(now)
if __name__=="__main__":
  f()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Submission status: Accepted

Solution code:
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Submission status: Accepted

Solution code:
def f():
  n=int(input())
  l=[list(map(int,input().split())) for i in range(n-1)]+[[0,0,1]]
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Submission status: Accepted

Solution code:
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]+[[0,0,1]]
al=[]
mati=0
for i in range(n):
  now=l[i][1]+l[i][0]
  for j in range(i+1,n):
    now=l[j][0]+l[j][1]-(-max(0,now-l[j][1])//l[j][2])*l[j][2]
  al.append(now)
print(*al,sep="\n")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
C, S, F = list(range(N)), list(range(N)), list(range(N))
for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split(' '))

import math
for c in range(N):
    ret = 0
    for next_c in range(c, N-1):
        if ret <= S[next_c]:
            ret = S[next_c]

        else:
            i = int(math.ceil((ret - S[next_c]) / F[next_c]))
            ret = S[next_c] + F[next_c] * i

        ret += C[next_c]

    print(ret)

Submission status: Accepted

Solution code:
from math import ceil

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

for i in range(n):
    if i != n-1:
        time = 0
        for k in range(i, n-1):
            if time < s[k]:
                time += s[k] - time
            else:
                time += s[k] + ceil((time-s[k])/f[k])*f[k] - time
            time += c[k]
        print(time)
    else:
        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())
time=0
ans0=[0]
for j in range(N-1):
    time=0
    for i in range(j,N-1):
        if time<=s[i]:
            time=s[i]+c[i]
            ans0.append(time)
        else:
            q=time//f[i]
            if time%f[i]==0:
                q-=1
            time=(q+1)*f[i]+c[i]
    print(time)
print(0)

Submission status: Accepted

Solution code:
import sys

N = int(input())

c = [list(map(int, sys.stdin.readline().split())) for i in range(N-1)]

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

print(0)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
ekis = []
for _ in range(N - 1):
  c, s, f = map(int, input().split())
  ekis.append((c, s, f))

for ikimasuyo in range(N):
  t = 0
  for i in range(ikimasuyo, N - 1):
    c, s, f = ekis[i]
    if t < s:
      t = s + c
    elif t >= s:
      t = -((s - t) // f) * f + s + c
    #print(ikimasuyo, t)
  print(t)

Submission status: Accepted

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

def next_station(Time,s):
    Time+=path[s][0]
    ns=s+1
    if ns==N-1:
        print(Time)
    elif Time<=path[ns][1]:
        Time=path[ns][1]
        next_station(Time,ns)
    else:
        if Time%path[ns][2]==0:
            next_station(Time,ns)
        else:
            Time+=(path[ns][2]-Time%path[ns][2])
            next_station(Time,ns)

for i in range(N-1):
    next_station(path[i][1],i)
print(0)

Submission status: Accepted

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

def train(i, t):
    if i==n-1:
        return t
    
    c, s, f = csf[i]
    
    if t < s:
        return train(i+1, s+c)
    else:
        return train(i+1, -(-t//f)*f+c)
    
for i in range(n):
    print(train(i, 0))

Submission status: Accepted

Solution code:
import math
N=int(input())
numbers=[]
for a in range(N-1):
    list=[]
    C,S,F=input().split()
    list.append(int(C))
    list.append(int(S))
    list.append(int(F))
    numbers.append(list)
if N==1:
    print(0)
elif N==2:
    print(numbers[0][0]+numbers[0][1])
    print(0)
else:
    for a in range(N - 1):
        b = numbers[a][0] + numbers[a][1]
        while a < N - 2:
            if b>=numbers[a+1][1]:
                c = b - numbers[a + 1][1]
                d =math.ceil (c / numbers[a + 1][2])
                e = numbers[a + 1][1] + numbers[a + 1][2] * d
                b = e + numbers[a + 1][0]
            else:
                b=numbers[a+1][1]+numbers[a+1][0]
            a+=1
        print(round(b))
    print(0)

Submission status: Accepted

Solution code:
def solve():
    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())
    
    ans = [0] * N
    for i in range(N - 1):
        t = C[i] + S[i]
        for j in range(i + 1, N - 1):
            if S[j] <= t and t % F[j] == 0:
                t += C[j]
            elif t < S[j]:
                t = C[j] + S[j]
            else:
                t += C[j] + F[j] - (t % F[j])
        ans[i] = t
    print('\n'.join(map(str, ans)))


if __name__ == '__main__':
    solve()

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

Submission status: Accepted

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

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:
            t+=c[j]
            continue
        else:
            t=t+f[j]-(t%f[j])
        t+=c[j]
    print(t)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil


def train(i, t):
    if i == n - 1:
        return t
    c, s, f = d[i]
    tt = f * ceil(t / f) if t > s else s
    return train(i + 1, tt + c)


if __name__ == '__main__':
    n = int(input())
    d = [[int(i) for i in input().split()] for _ in range(n - 1)]
    print(*[train(i, 0) for i in range(n)], sep="\n")

Submission status: Accepted

Solution code:
def main():
  import math
  n=int(input())
  CSF=[list(map(int,input().split())) for _ in [0]*(n-1)]
  t=0
  for i in range(n-1):
    t=CSF[i][1]
    for csf in CSF[i:]:
      c,s,f=csf[0],csf[1],csf[2]
      t=math.ceil(max(s,t)/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):
    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
        elif t % F[j] !=0:
            t += F[j] - (t%F[j])
        t += C[j]
    print(t)

Submission status: Accepted

Solution code:
n = int(input())
res = [0]*n

for x in range(n-1):
  c,s,f = map(int,input().split())
  for y in range(x+1):
    if res[y] < s:
      res[y] = s + c
    else:
      res[y] = ((res[y]-1)//f +1)*f + c
  
for asldijfgherab in range(n):
  print(res[asldijfgherab])

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

Submission status: Accepted

Solution code:
n=int(input())
ab = []
for _ in range(n-1):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

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

Submission status: Accepted

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

ans = [0 for _ in range(N)]

for i in range(N-1) :
    temp = CSF[i][1] + CSF[i][0]
    t = i + 1
    while t < N-1 :
        if temp < CSF[t][1] :
            temp = CSF[t][1] + CSF[t][0]
        else :
            temp = ((temp+CSF[t][2]-1)//CSF[t][2])*CSF[t][2] + CSF[t][0]
        t += 1
    ans[i] = temp

for answer in ans :
    print(answer)

Submission status: Accepted

Solution code:
n=int(input())
L=[[0,0,0] for _ in range(n)]
for i in range(n-1):
    c,s,f=map(int,input().split())
    L[i]=[c,s,f]
for j in range(n):
    ans=0
    if j==n:
        print(0)
    else:
        for k in range(len(L)-1):
            if k==0:
                ans+=L[k][1]
                ans+=L[k][0]
            else:
                ans=max(-(-ans//L[k][2])*L[k][2],L[k][1])
                ans+=L[k][0]
        print(ans)
        L.pop(0)

Submission status: Accepted

Solution code:
import sys
import numpy as np

# N 駅の数
n = int(input())

# C　次の駅までかかる時間、S 開始後発射時間、F　間隔
act = [list(map(int, input().split())) for ii in range(n-1)]

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

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-1):            #各駅について時間計算
    cnt = C[i]+S[i]
    for j in range(i+1, N-1):     #次の電車について計算
        if(S[j] <= cnt):
            if(cnt % F[j] == 0):
                cnt += C[j]
            else:
                cnt += C[j] + (F[j] - cnt%F[j])
        else:
            cnt = S[j]+C[j]
    print(cnt)
print(0)

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)
time = 0

#それぞれの駅から出発する
for i in range(n-1):
	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 += f[j]-(time%f[j]) + c[j]
	print(time)
	time = 0
print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
inf = float('inf')
mod = 1000000007
 
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
    N = inputInt()
    csf = []
    for _ in range(N-1):
        c,s,f = inputMap()
        csf.append((c,s,f))
        
    ans = []
    for i in range(N-1):
        c,s,f = csf[i]
        tmp = s+c
        for j in range(i+1,N-1):
            c,s,f = csf[j]
            #print("{} {}".format(tmp,s))
            if tmp < s:
                tmp = tmp + (s-tmp) + c
            else:
                if (tmp-s)%f == 0:
                    tmp = tmp + c
                else:
                    tmp = tmp + ((-(-(tmp-s) // f))*f + s)-tmp + c
        print(tmp)
        
    print(0)
    
     
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
 
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y
         
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import math
import itertools
import statistics
#n = int(input())
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    x,y,z = [int(j) for j in input().split()]
    c.append(x)
    s.append(y)
    f.append(z)

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

print(0)

Submission status: Accepted

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

        while s2 < ans[i]:
            s2 += f[j]
        ans[i] = c[j] + s2
#print(ans)
for i in range(n):
    print(ans[i])

Submission status: Accepted

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

for i in range(n-1):
    t = S[i]
    while i != (n-1):
        if t < S[i]:  # 最初の列車の発車時刻前に到着
            wait = (S[i] - t)
        else:
            r = (t - S[i])%F[i]
            if r == 0:
                wait = 0 
            else:
                wait = F[i] - r
        t += wait
        t += C[i]  # 移動時間
        i += 1
    print(t)
print(0)  # すでに駅Nにいる

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc084/tasks/abc084_c
# 制約によりたかだか500行 O(N*N)でも間に合うのでは？

# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_a_int():
    return int(read())


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
C, S, F = read_col(N - 1, 3)


def f(i):
    # 駅iからN-1までに向かう最短時間
    now = S[i]  # はじめは運転開始時刻
    for j in range(i, N - 2):  # 駅N-1の手前まで
        now += C[j]  # 移動時間
        # 駅の待ち時刻まで待機
        f, s = F[j + 1], S[j + 1]
        # だけど割り切れるときは余分に＋1されてしまうので-0.5してつじつま合わせ
        now_tmp = (int((now - 0.5) // f) + 1) * f
        now = max(now_tmp, s)
    now += C[N - 2]
    return now


for i in range(N - 1):
    print(f(i))
print(0)

Submission status: Accepted

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

ans_list=[]

for i in range(n):
    now=0
    for g in range(i,n-1):
        c,s,f=csf[g]
        if now<=s:
            now=s
        if now%f==0:
            now+=c
        else:
            now+=(f-now%f)+c
    ans_list.append(now)

for l in range(n):
    print(ans_list[l])

Submission status: Accepted

Solution code:
n = int(input())
a = []
n -= 1
for i in range(n):
    N, S, F = map(int, input().split())
    a.append([N, S, F])

for i in range(n + 1):
    cnt = 0
    for j in range(i, n):
        # print(i, j,n)
        if j == i:
            cnt += a[j][1] + a[j][0]
        else:
            if cnt >= a[j][1]:
                amari = cnt % a[j][2]
                cnt += a[j][0] + (a[j][2] - amari if amari != 0 else 0)
            else:
                cnt = a[j][1] + a[j][0]
    print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
csf=[tuple(map(int,input().split(' '))) for i in range(N-1)]
for i in range(N-1):
    now = 0
    for j in csf[i:]:
        c,s,f= [k for k in j]
        while now > s:
            s += f
        now = s+c
    print(now)
print(0)

Submission status: Accepted

Solution code:
from math import ceil

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


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

Submission status: Accepted

Solution code:
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n-1)]
for i in range(n):
    t = 0  # 初期条件
    for j in range(i, n-1):
        ci, si, fi = arr[j]  # 各駅の条件を代入
        if t <= si:  # まだ始発が出発していないとき
            t = si
        elif t % fi == 0:
            pass
        else:  # すでに出発している時
            t = t + fi - (t % fi)
        t += ci  # 電車に乗っている時間
    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):
    t = 0  # 初期条件
    for j in range(i, n-1):
        ci, si, fi = arr[j]  # 各駅の条件を代入
        if t <= si:  # まだ始発が出発していないとき
            t = si
        else:  # すでに出発している時
            t = ((t + fi - 1)//fi) * fi
        t += ci  # 電車に乗っている時間
    print(t)

Submission status: Accepted

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    train=[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):
            c=train[j][0]
            s=train[j][1]
            f=train[j][2]
            if t>=s:
                if t%f!=0:
                    t+=f-t%f
                t+=c
            else:
                t=s+c
        print(t)
    print(0)
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
CSFlist = [list(map(int, input().split())) for _ in range(N-1)]
def calc_time(start):
    now = 0
    for i in range(start, N-1):
        C, S, F = CSFlist[i]
        now = max(now, S)
        if now % F != 0:
            now += F - now % F
        now += C
    return now
for _ in range(N-1):
    print(calc_time(_))
print(0)

Submission status: Accepted

Solution code:
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

N=I()
C=[0]*N
S=[0]*N
F=[0]*N

for i in range(N-1):
    C[i],S[i],F[i]=MI()
      
ans=[0]*N


#a秒後に，c,s,fな駅にいるとして，次の駅につく時間
def calc(a,c,s,f):
    st=s
    if a>s:
        st=((a+f-1)//f)*f
    return st+c
        
    

for i in range(N-1):
    for j in range(i+1):
        ans[j]=calc(ans[j],C[i],S[i],F[i])

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

Submission status: Accepted

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


def left_time(time, si, fi):
    if time>si:
        a = time-si
        if a%fi:
            b = a//fi + 1
            return si + fi*b
        else:
            return time
    else:
        return si

for i in range(n-1):
    total = 0
    total = l[i][0]+l[i][1]
    for j in range(i+1, n-1):
        total = (left_time(total, l[j][1], l[j][2]) + l[j][0])
    print(total)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
CSFlist = [list(map(int, input().split())) for _ in range(N-1)]
def calc_time(start):
    now = 0
    for i in range(start, N-1):
        C, S, F = CSFlist[i]
        if now < S:
            now = S
        if now % F != 0:
            now += F - now % F
        now += C
    return now
for _ in range(N-1):
    print(calc_time(_))
print(0)