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())
CSF = []
for i in range(N - 1):
    c, s, f = map(int, input().split())
    CSF.append((c, s, f))

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

for a in ans:
    print(a[0])

Submission status: Accepted

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

for i in range(n-1): # i = 0,1,2,...,n-1
    c,s,f = csf[i]
    s += c
    #print("i=",i)
    for j in range(i+1,n-1): # j = i+1,i+2,...,n-1
        c1,s1,f1 = csf[j]
        s = ((math.ceil((s-s1)/f1))*f1 if s >= s1 else 0)+s1+c1
        #print("j=",j,"s=",s)
    print(s)
print(0)

Submission status: Accepted

Solution code:
N = int(input())

eki = []
for i in range(N - 1):
    eki.append([int(_) for _ in input().split()])

for i in range(N - 1):
    s = eki[i][0] + eki[i][1]
    for j in range(i + 1, N - 1):
        tmp = s - eki[j][1]
        if tmp < 0:
            s = eki[j][1]
        elif tmp % eki[j][2] != 0:
            s += eki[j][2] - (tmp % eki[j][2])
        s += eki[j][0]

    print(s)
print(0)

Submission status: Accepted

Solution code:
import math
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 j in range(N-1):
    ans = 0
    for i in range(j, N-1):
        tmp = math.ceil(ans/F[i]) * F[i]
        tmp2 = max(tmp, S[i])
        ans = tmp2
        ans += C[i]

    print(ans)
print(0)

Submission status: Accepted

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

for start in range(0, N):
    now = 0
    for c, s, f in trains[start:]:
        if now < s:
            now = s
        now += (f - now % f) % f
        now += c
    print(now)

Submission status: Accepted

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

for i in range(n):
    ans = 0
    while i<=n-2:        
        c = csf[i][0]
        s = csf[i][1]
        f = csf[i][2]
        ans = max(s,math.ceil(ans/f)*f)+c
        i+=1
    print(ans)

Submission status: Accepted

Solution code:
# 2019/08/12

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

ans=[]
for i in range(n):
    res=c[i]+s[i]
    for j in range(i+1,n):
        if res<s[j]:
            res=s[j]+c[j]
        else:
            if res%f[j]:
                res+=f[j]-res%f[j]+c[j]
            else:
                res+=c[j]
    ans.append(res)
print(*ans,sep='\n')
print(0)

Submission status: Accepted

Solution code:
import math
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
    if i == N - 1:
        print(0)
        exit()
    
    # j → j + 1区間の最短時間を求めていく
    for j in range(i, N-1):
        # 駅j+1を出発する時刻は S[j] + F[j] * k となる
        # これがt以上になる最小のkを求める
        k_tmp = math.ceil((t - S[j])/F[j])
        k = max(0,k_tmp)

        t = S[j] + F[j] * k + C[j]
    
    print(t)

Submission status: Accepted

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

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



print(0)

Submission status: Accepted

Solution code:
N = int(input())

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


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

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

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

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


def solve(from_i):
    t = 0
    for c, s, f in CSF[from_i:]:
        t = max(s, math.ceil(t / f) * f) + c
    return t


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

Submission status: Accepted

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

Submission status: Accepted

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

# simple solution
# 0: C
# 1: S
# 2: F
# print(status_lst)

rev_res = []
for ix, st_i in enumerate(status_lst):
    elapsed = st_i[1] + st_i[0]
    for next_st in range(ix+1, N-1):
        st_n = status_lst[next_st]
        if elapsed < st_n[1]:
            elapsed = st_n[1] + st_n[0]
        else:
            wait_time = elapsed % st_n[2]
            if wait_time == 0:
                elapsed = elapsed + st_n[0]
                # else:
                # elapsed = elapsed + st_n[2] - (elapsed % st_n[2]) + st_n[0]
            elif wait_time == elapsed:
                # elaplsed < F
                # ?
                elapsed = st_n[2] + st_n[0]
            else:
                elapsed = elapsed + st_n[2] - wait_time + st_n[0]

    rev_res.append(elapsed)

rev_res.append(0)

for ans in rev_res:
    print(ans)

Submission status: Accepted

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

# simple solution
# 0: C
# 1: S
# 2: F
# print(status_lst)

rev_res = []
for ix, st_i in enumerate(status_lst):
    elapsed = st_i[1] + st_i[0]
    for next_st in range(ix+1, N-1):
        st_n = status_lst[next_st]
        if elapsed < st_n[1]:
            elapsed = st_n[1] + st_n[0]
        else:
            wait_time = elapsed % st_n[2]
            if wait_time == 0:
                elapsed = elapsed + st_n[0]
            else:
                elapsed = elapsed + st_n[2] - (elapsed % st_n[2]) + st_n[0]
            # elif wait_time == elapsed:
            #     # elaplsed < F
            #     # ?
            #     elapsed = st_n[2] + st_n[0]
            # else:
            #     elapsed = elapsed + wait_time + st_n[0]

    rev_res.append(elapsed)

rev_res.append(0)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*l=map(int,open(0).read().split())
c=l[::3]+[0];s=l[1::3]+[0];f=l[2::3]
for i in range(n):
	t=c[i]+s[i]
	for j in range(i+1,n-1):t=max(-(-t//f[j])*f[j],s[j])+c[j]
	print(t)

Submission status: Accepted

Solution code:
from itertools import accumulate
n,*l=map(int,open(0).read().split())
c=l[::3];s=l[1::3];f=l[2::3]
def func(m):
	t=c[m]+s[m]
	for i in range(m+1,n-1):
		fi=f[i]
		t=max((t//fi+(t%fi!=0))*fi,s[i])+c[i]
	return t
for i in range(n-2):
	print(func(i))
print(c[-1]+s[-1],0,sep="\n")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    def step(t, i):
        """i -> i+1 at t"""
        s = S[i] if t < S[i] else math.ceil(t / F[i]) * F[i]
        d = s + C[i]
        return d
    for i in range(N):
        t = 0
        for j in range(i, N-1):
            t = step(t, j)
        print(t)
    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())
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]
        if ans <= s:
            ans = s
        else:
            while ans % f:
                ans += 1
        ans += c
    print(ans)
print(0)

Submission status: Accepted

Solution code:
n=int(input())
s=[list(map(int, input().split())) for i in range(n-1)]
#sum=移動時間  x=乗り換え時間

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from math import ceil

N = int(input())

ans = [0] * N
for i in range(1, N):
    c, s, f = [int(zz) for zz in input().split()]
    ans[i] = s + c
    for j in range(1, i):
        p = ceil(ans[j] / f) * f
        if p < s:
            ans[j] = s + c
        else:
            ans[j] = c + p

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

print(0)

Submission status: Accepted

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

for n in range(N):
    ans = 0
    for c, s, f in csf[n:]:
        if ans > s:
            tmp = math.ceil((ans - s) / f)
            ans = s + tmp * f + c
        else:
            ans = s + c
    print(ans)

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

Submission status: Accepted

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

for idx, station in enumerate(stations):
  time = station[1] + station[0]
  for next in range(idx+1, N-1):
    if time < stations[next][1]:
      time = stations[next][1] + stations[next][0]
    elif (time-stations[next][1])%stations[next][2] == 0:
      time += stations[next][0]
    else:
      time += stations[next][2] - (time-stations[next][1])%stations[next][2] + stations[next][0]
  print(time)
print(0)

Submission status: Accepted

Solution code:
from math import ceil
from collections import defaultdict
N=int(input())
Time=defaultdict(int)
for i in range(N-1):
    c,s,f=map(int,input().split())
    for j in range(N):
        if j<i:Time[j]=max(s,(ceil(Time[j]/f))*f)+c
        elif j==i:Time[j]=s+c
        else:pass
for k in range(N):print(Time[k])

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
CSF = [list(map(int, stdin.readline().rstrip().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)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    m = II()
    print(48-m)
    return

#B
def B():
    a, b = LI()
    s = S()
    ans = list(map(str, range(10)))
    for num, si in enumerate(s):
        if num != a:
            if si in ans:
                continue
            print("No")
            return
        else:
            if si == "-":
                continue
            print("No")
            return
    print("Yes")
    return

#C
def C():
    n = II()
    csf = LIR(n - 1)
    for i in range(n - 1):
        b = 0
        for k in range(i, n - 1):
            c, s, f = csf[k]
            if b <= s:
                b = s + c
            else:
                b += c + (-b % f)
        print(b)
    print(0)
    return

#D
def D():
    a = II()
    ans = inf
    b = 0
    for k in range(1, 10 ** 5):
        b += a
        ans = min(ans, sum(list(map(int, list(str(b))))))
    print(ans)
    return

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

Submission status: Accepted

Solution code:
import copy
import sys
import math

def main():
	n = int(input())
	c, s, f = [], [], []
	for _ in range(n-1):
		tmp = list(map(int,input().split()))
		c.append(tmp[0])
		s.append(tmp[1])
		f.append(tmp[2])
	#print(c)
	#print(s)
	#print(f)
	for i in range(n-1):
		currenttime = s[i] + c[i]
		#print('from st.' + str(i))
		for j in range(i+1,n-1):
			#print('current st.'  + str(j))
			#print('reach time: ' + str(currenttime))
			if(currenttime <= s[j]):
				currenttime = c[j] + s[j]
				#print('tokudeparture time: ' + str(c[j] +  s[j]))
			else:
				#print('departure time: ' + str(math.ceil((currenttime - s[j]) / f[j] - 1) * f[j] +  s[j]))
				currenttime = math.ceil((currenttime - s[j]) / f[j]) * f[j] +  s[j] + c[j]
		print(currenttime)
	print(0)

def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

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):
    if i == N-1:
        print(0)
        break
    t = C[i] + S[i]
    for j in range(i+1, N-1):
        k = t % F[j]
        arrive = t + F[j] - k if k != 0 else t
        t = max(S[j], arrive) + C[j]
    print(t)

Submission status: Accepted

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

#time秒にi駅に到着した場合の時間(引数2)
#を出す関数を再帰で求めればいい

def tt(time,i):
	if(i==n):
		return time
	if(time<=s[i]):
		return tt(s[i]+c[i],i+1)
	return tt((((time-s[i]-1)//f[i])+1)*f[i]+s[i]+c[i],i+1)

n = int(input())
c=[]
s=[]
f=[]
t=[]

c.append(0)
s.append(0)
f.append(0)
t.append(0)
for i in range(1,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	c.append(hoge[0])
	s.append(hoge[1])
	f.append(hoge[2])
	t.append(0)
c.append(0)
s.append(0)
f.append(1)
t.append(0)

#for i in range(0,n-1):
#	t[n-1-i]=s[n-1-i]+c[n-1-i]
#	print("{} {}".format(t[n-1-i],s[n-i]))
#	if(t[n-1-i]<=s[n-i]):
#		t[n-1-i]=t[n-i]
#	else:
#		t[n-1-i]-=s[n-i]
#		t[n-1-i]=((t[n-1-i]-1)//f[n-i]+1)*f[n-i]+t[n-i]

for i in range(1,n+1):
	print(tt(0,i))

#print(c)
#print(s)
#print(f)
#print(t)

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    csf = []
    for i in range(N-1):
        c,s,f = map(int, input().split())
        csf.append((c,s,f))
        
    for i, val in enumerate(csf):
        ans = 0
        c,s,f = val
        ans += s + c
        for j, vol in enumerate(csf):
            if i >= j:
                continue
                
            cc,ss,ff = vol
            if ans <= ss:
                ans = ss + cc
            else:
                tmp = ans - ss
                if tmp == 0:
                    ans += cc
                    continue
                    
                tmp2 = (tmp // ff)
                if tmp % ff != 0:
                    tmp2 += 1
                tmp2 = (tmp2 * ff) + ss
                ans = ans + (tmp2 - ans) + cc
        print(ans)
                
    print(0)
    
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC84 C

n = int(input())

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

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

Submission status: Accepted

Solution code:
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int c[] = new int[n];
		int s[] = new int[n];
		int f[] = new int[n];
		for (int i = 1; i < n; i++) {
			c[i] = Integer.parseInt(sc.next());
			s[i] = Integer.parseInt(sc.next());
			f[i] = Integer.parseInt(sc.next());
		}
		for (int i = 1; i <= n; i++) {
			int t = 0;
			for (int j = i; j < n; j++) {
				if (t < s[j])
					t = s[j];
				else if ( t % f[j] != 0)
					t += f[j] - t % f[j];
				t += c[j];
			}
			out.println(t);
		}
		out.flush();
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Submission status: Accepted

Solution code:
import numpy as np
# 駅の数を入力する
N = int(input())
# 乗車時間C、始発の発車時間S、発車間隔Fを入力する
C = np.empty(N - 1, dtype = int)
S = np.empty(N - 1, dtype = int)
F = np.empty(N - 1, dtype = int)
for i in range(N - 1):
    C[i], S[i], F[i] = map(int, input().split())

# 0〜N-2までの各駅iから駅N-１までの所要時間tを求める
for i in range(N - 1):
    # 駅iでの待機時間を加える
    t = S[i]
    # 駅iから駅i+1までの所要時間を加える
    t += C[i]
    # i+1〜N-2までの各駅jについて繰り返す
    for j in range(i + 1, N - 1):
        # tがS[j]より大きい場合
        if t > S[j]:
            # (t - S[j])をF[j]で割ったときの商aと余りbを求める
            a = (t - S[j]) // F[j]
            b = (t - S[j]) % F[j]
            # S[j]をF[j]だけ増やしていき、最初にt以上となる時間を新たなtとする
            t = S[j] + (a + min(b, 1)) * F[j]
        # tがS[j]よりも小さい場合
        elif t < S[j]:
            # S[j]を新たなtとする
            t = S[j]
        # 駅jから駅j+1までの所要時間を加える
        t += C[j]
    # tを出力する
    print(t)
# 駅N-1から駅N-1までの所要時間（0）を出力する
print(0)

Submission status: Accepted

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

n = int(input())
tl = [0]*n
for i in range(n-1):
  c,s,f = map(int,input().split())  
  for j in range(i+1):
    if tl[j] < s:
      tl[j] = s + c
    elif tl[j] % f == 0:
      tl[j] += c
    else:
      tl[j] += c + f - tl[j] % f
for k in tl:
  print(k)

Submission status: Accepted

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

n = int(input())
csfn = [() for i in range(n-1)]
tl = [0]*n
for i in range(n-1):
  c,s,f = map(int,input().split())
  csfn[i] += (c,s,f)
  
  for j in range(i+1):
    if tl[j] < csfn[i][1]:
      tl[j] = csfn[i][1] + csfn[i][0]
    elif tl[j] % csfn[i][2] == 0:
      tl[j] += csfn[i][0]
    else:
      tl[j] += csfn[i][0] + csfn[i][2] - tl[j] % csfn[i][2]
for k in tl:
  print(k)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

n = int(input())
train_list = []
for i in range(n-1):
    train_list.append([ int(v) for v in input().split() ])

def ride(a,t):
    global train_list
    if a == n - 1:
        return t
    else:
        duration, first, interval = train_list[a]
        if t <= first:
            time = first + duration
        else:
            b = (t - first + interval - 1) // interval
            time = first + duration + interval * b
        return ride(a+1,time)

for i in range(n):
    print(ride(i,0))

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
N = int(input())
lc=[]
ls=[]
lf=[]
for _ in range(N-1):
    C,S,F = map(int,input().split())
    lc.append(C)
    ls.append(S)
    lf.append(F)

for i in range(N-1):
    j = i
    ct = 0
    while j < N-1:
        if ct <= ls[j]:ct = ls[j] + lc[j]
        else:
            os = ct - ls[j]
            rm = os - lf[j] * (os//lf[j])
            if rm == 0:ct += lc[j]
            else:ct += (lf[j]-rm) + lc[j]
        if j == N-2:print(ct)
        j += 1
else:print(0)

Submission status: Accepted

Solution code:
N = int(input())
CSF = []
for n in range(N-1):
  CSF.append([int(csf) for csf in input().split()])

for i in range(N-1):
  total_time = 0
  for j in range(i, N-1):
    c12, s1, f1 = CSF[j]
    if s1 >= total_time:
      total_time = s1 + c12
    else:
      how_many_arrival_train = (total_time - s1) // f1
      how_long_waiting_time = (total_time - s1) % f1
      if how_long_waiting_time == 0:
        total_time = s1 + f1 * how_many_arrival_train + c12
      else:
        total_time = s1 + f1 * (how_many_arrival_train + 1) + c12
  print(total_time)
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 n in range(N):
    time = 0
    for i in range(n, N - 1):
        dep = S[i]
        time = max(time, dep)
        while time > dep:
            dep += F[i]
        time = dep + C[i]
    print(time)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
if n==1:
    print("0")
    exit()
l=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n):
    t=0
    k=i
    while k<n-1:
        if l[k][1]>t:
            t=l[k][0]+l[k][1]
            k+=1
            continue
        elif t%l[k][2]==0:
            t+=l[k][0]
            k+=1
            continue
        else:t+=l[k][2]-t%l[k][2]
    print(t)

Submission status: Accepted

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

ans = [0]*N
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        time = max(time,CSF[j][1]) # 開通待ち
        time += (CSF[j][1]-time)%CSF[j][2] # 待ち時間
        time += CSF[j][0] # 移動時間
    ans[i] = time
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import math
N =int(input() )
trains = [list(map(int,input().split(" "))) for _ in range(N-1)]
for s in range(N):
    ans = 0
    spent = 0
    arrived_time = 0
    for train in trains[s:]:
        c,s,f = train
        n = max(0,math.ceil((ans-s) /f))
        wait = n * f + s - ans
        #待機時間

        ans += c + wait

    print(ans)