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
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
csf = [tuple(li()) for _ in range(n-1)]

for start in range(n-1):
    time = csf[start][1]
    for station in range(start,n-1):
        if time >= csf[station][1]:
            time = (-(-time//csf[station][2]))*csf[station][2]
            time += csf[station][0]
            
        else:
            time = csf[station][1]
            time += csf[station][0]
            
    print(time)
    
print(0)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

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

def main():
    n = int(input())
    station_list = list(tuple(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 = station_list[j]
            if ans <= s:
                ans = s
            elif ans % f != 0:
                ans += f - (ans % f)
            ans += c
        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):
    tmp = [int(v) for v in input().split()]
    c.append(tmp[0])
    s.append(tmp[1])
    f.append(tmp[2])

ans = []
for i in range(n-1):
    t = s[i] + c[i]
    j = i + 1
    while j <= n - 2:
        if t <= s[j]:
            t = s[j] + c[j]
        else:
            if t % f[j] == 0:
                t += c[j]
            else:
                t += f[j] - (t % f[j]) + c[j]
        j += 1
    ans.append(t)

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

Submission status: Accepted

Solution code:
n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)] # csf[N-1][csf]
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 # tのまんま
        else:
            t = t + csf[j][2] - t % csf[j][2]
        t += csf[j][0]
    print(t)

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
li = lambda: list(map(int,input().split()))

n = int(input())
A = [li() for _ in range(n-1)]
c,s,f = [i for i in zip(*A)]
for k in range(n-1):
    t = s[k]+c[k]
    for i in range(k+1, n-1):
        if t < s[i]:
            t = s[i]
        else:
            t = -(-t//f[i]) * f[i]
        t += c[i]
    print(t)
print(0)

Submission status: Accepted

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

if __name__ == "__main__":
    N = int(input())
    Cs = []
    Ss = []
    Fs = []
    for i in range(N-1):
        C, S, F = list(map(int, input().split()))
        Cs.append(C)
        Ss.append(S)
        Fs.append(F)

    for i in range(N-1):
        ans = 0
        for j in range(i, N-1):
            if ans <= Ss[j]:
                # 駅の最初の出発時間になっていないなら待つ
                ans = Ss[j] + Cs[j]
            else:
                # 最初の出発時間はすでに過ぎているならば
                if (ans - Ss[j]) % Fs[j] == 0:
                    # すぐに出発できる
                    ans += Cs[j]
                else:
                    # 出発時間まで待つ
                    ans += Cs[j] + Fs[j] - (ans - Ss[j]) % Fs[j]
        print(ans)
    print(0)

Submission status: Accepted

Solution code:
n = int(input())

if n == 1:
    print('0')
    exit()

c = [tuple(int(x) for x in input().split()) for _ in range(n - 1)]

c.append((0,0,1))

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

ans[n - 1] = 0

for i in range(n - 2, -1, -1):
    temp = c[i][0] + c[i][1]
    if temp <= c[i + 1][1]:
        ans[i] = 0 + ans[i + 1]
    else:
        for j in range(i + 1, n - 1):
            if c[j][1] >= temp:
                temp = c[j][1] + c[j][0]
            else:
                d = (temp - c[j][1]) // c[j][2]
                if ((temp - c[j][1]) % c[j][2]) != 0:
                    d += 1
                temp = c[j][1] + c[j][2] * d + c[j][0]
        ans[i] = temp

for x in ans:
    print(x)

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

Submission status: Accepted

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

for i in range(N - 1):
    sec = 0
    for j in range(i, N - 1):
        if sec < S[j][1]:
            sec = S[j][1]
        elif (sec - S[j][1]) % S[j][2]:
            sec += S[j][2] - sec % S[j][2]
        sec += S[j][0]
    print(sec)
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()))
T = [0] * N
Time = 0
for i in range(N-1):#situation that some passengers are in the station i+1
    for j in range(0, i+1):#passenger moves from the station j to j+1
        tmp = 0
        if T[j] < S[i]:
            T[j] = S[i] + C[i]
        else:
            tmp = -(-(T[j] - S[i]) // F[i])
            T[j] = S[i] + F[i] * tmp + C[i]
for i in range(N):
    print(T[i])

Submission status: Accepted

Solution code:
n = int(input())

arr = [map(int,raw_input().split()) for i in range(n-1)]

def ceil(n,d):
	if n%d==0:
		return n/d

	else:
		return n/d+1

for i in range(n):
	t = 0

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


	print t

Submission status: Accepted

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

# print(train_info)

for i in range(1, n + 1):
    # print("i = {}".format(i))
    t = 0

    if i == n:
        print(0)
    else:
        for j in range(i, n):
            # print("t = {}".format(t))
            C_j, S_j, F_j = train_info[j - 1]
            if t <= S_j:
                t = S_j + C_j
            elif t % F_j == 0:
                t += C_j
            else:
                t += F_j - t % F_j
                t += C_j

        print(t)

Submission status: Accepted

Solution code:
N = int(input())

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

for i in range(1, N+1):
    if i == N:
        print(0)
        continue
    result_time = 0
    for j, train in enumerate(trains):
        if j + 1 < i:
            continue
        c, s, f = train
        if result_time < s:
            result_time = s
        else:
            while result_time % f != 0:
                result_time += 1
        result_time += c

    print(result_time)

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())

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

    for i in range(len(L)):
        x = 0
        for c, s, f in L[i:]:
            if x <= s:
                x = s + c
            else:
                x = s + f * ceil(x - s, f) + c
        print(x)
    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def f(i):
	s = 0
	while i < N-1:
		# find the fastest train at time s from i stattion.
		if s <= S[i]:
			s = S[i]+C[i]
		else:
			m = (s-S[i]) % F[i]
			if m == 0:
				s = s + C[i]
			else:
				s = s + (F[i]-m) + C[i]
			# we use the fact that F[i] | S[i]
		i += 1
	return s

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

Submission status: Accepted

Solution code:
# vim: set fileencoding=utf-8:


def main():
    N = input()
    C = [0] * (N - 1)
    S = [0] * (N - 1)
    F = [0] * (N - 1)

    for i in xrange(N - 1):
        C[i], S[i], F[i] = map(int, raw_input().split())

    t = 0
    for j in xrange(N - 1):
        for i in xrange(N - 1):
            if i + j == N - 1:
                break
            t = spend_waited_time(t, S[i + j], F[i + j])
            t += C[i + j]

        print(t)
        t = 0

    print(0)


def spend_waited_time(t, S, F):
    if t <= S:  # 始発がまだなら
        t = S
    elif S < t:  # 始発済みなら、次の電車まで何秒待つ？
        a = (t - S) % F
        if a == 0:
            pass
        else:
            t += F - abs(a)

    return t


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import sys

input = sys.stdin.readline

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

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

Submission status: Accepted

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

Submission status: Accepted

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

from math import ceil
def f(t, i):
    for j in range(i, N - 1):
        c, s, f = csf[j]
        d, m = divmod(t, f)
        t = max(s, ceil(t / f) * f) + c
    return t

for i in range(N):
    print(f(0, i))

Submission status: Accepted

Solution code:
from math import ceil
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):
  t = 0
  for j in range(i,N-1):
    if S[j] >= t:
      t = S[j] + C[j]
    else:
      t = ceil(t / F[j]) * F[j] + C[j]

  print(t)

print(0)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 02:27:58 2018

@author: Yuki
"""

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

def train_time(start_time=0, data_list=[12, 24, 6]):
    if data_list[1] <= start_time:
        return start_time + (data_list[2] - start_time%data_list[2])%data_list[2] + data_list[0]
    else:
        return data_list[1] + data_list[0]

#N = 4
#data = [[12, 24, 6], [52, 16, 4], [99, 2, 2]]

res = []
for i in range(N-1):
    need_time = 0
    for ii in range(i, N-1):
        need_time = train_time(need_time, data[ii])
    res.append(need_time)

for i in range(N-1):
    print(res[i])
print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
c = []
s = []
f = []

for _ in range(n-1):
    line = input().split(" ")
    c.append(int(line[0]))
    s.append(int(line[1]))
    f.append(int(line[2]))

def calc(idx, t):
    # print(idx,t)
    ret = 0
    if idx==n-1:
        return t

    if t<s[idx]:
        t = s[idx]

    if t%f[idx]==0:
        return calc(idx+1, t+c[idx])
    else:
        return calc(idx+1, (t//f[idx]+1)*f[idx]+c[idx])


for i in range(n):
    # print("--",i,"--")
    print(calc(i, 0))

Submission status: Accepted

Solution code:
import math
n = int(input())
x = []
for i in range(n-1):
    x1,y1,z1=[int(i) for i in input().split()]
    x.append([x1,y1,z1])
dp = [0 for i in range(n)]
for i in range(0,n):
  ans = 0
  j = i+0
  while j < n-1:
    a = x[j]
    b = math.ceil(ans/x[j][2]) * x[j][2]
    if b < x[j][1]:
      b = x[j][1]
    ans = b + x[j][0]
    j += 1
  dp[i] = ans
for i in dp:
  print(i)

Submission status: Accepted

Solution code:
N=int(input())
list1=[]
for i in range(N-1):
    A=input()
    A=A.rstrip().split(" ")
    list1.append([int(A[0]),int(A[1]),int(A[2])])
#print(list1)

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


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
paths = []

for i in range(N - 1) :
    paths.append(list(map(int, input().split())))
    
for i in range(N) :
    if i == N -  1:
        print("0")
    else :
        t = paths[i][1] + paths[i][0]
        
        for j in range(i + 1, N - 1) :
            wait = paths[j][1]
            
            if wait < t :
                wait += paths[j][2] * ((t - wait) // paths[j][2] - 1)
            
            while wait < t :
                wait += paths[j][2]
                
            # t = wait + paths[j][2] + paths[j][0]
            t = wait + paths[j][0]
        print(t)

Submission status: Accepted

Solution code:
N=int(input())
cnt=0
l=[tuple(map(int,input().split())) for _ in range(N-1)]
for s in range(N-1):
  cnt=0
  for t in range(s,N-1):
    if not cnt:
      cnt=l[t][0]+l[t][1]
    else:
      n=(cnt-l[t][1])//l[t][2]
      if n<0:
        cnt=l[t][1]+l[t][0]
      elif n*l[t][2]==cnt-l[t][1]:
        cnt=l[t][1]+l[t][2]*n+l[t][0]
      else:
        cnt=l[t][1]+l[t][2]*(n+1)+l[t][0]
  print(cnt)
print(0)

Submission status: Accepted

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

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

# 時刻xで駅iにいて,最短で向かった場合の駅Nへの到着時刻
def time(i,x):
  if i == N:
    return x
  else:
    # 直近の列車の出発時刻tを求める
    a = int(-(-x//F[i-1]))
    t = max(a*F[i-1],S[i-1])
    return time(i+1,t+C[i-1])

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

Submission status: Accepted

Solution code:
n = int(input())
csf = [tuple(map(int, input().split())) for _ in range(n - 1)]#csf
for i in range(n):
    #i:起点
    t = 0#駅jの出発時刻, 駅n（添え字n - 1）では、この時刻がprintされるので、初期値は0とする
    for j in range(i, n - 1):
        #j:乗車する区間
        c_j, s_j, f_j = csf[j]

        #駅jの出発時刻を求める
        if t < s_j:
            t = s_j
        elif t % f_j == 0:
            pass
            #t = t
        else:
            #始発より後に駅に到着し、駅で電車を待つ
            t += f_j - (t % f_j)
        t += c_j#乗車して次の駅に到着させる
    print(t)#駅n（添え字n - 1）の到着時刻

Submission status: Accepted

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

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

print("0")

Submission status: Accepted

Solution code:
# N:駅の数
# Ci:i駅から i+1 駅への移動にかかる時間(cost)
# Si:i駅の最初の発車時間(start)
# Fi:i駅の発車スパン(frequency)
# Si % Fi = 0

N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


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

for s in range(1, N+1):
    # print("start=", s)
    if s == N:
        t = 0
        pass
    else:
        t = 0
        for i in range(s, N):
            if t < S[i]:
                t = S[i]

            elif t % F[i] == 0:
                pass

            else:
                t = t + F[i] - (t % F[i])

            t += C[i]
    print(t)

Submission status: Accepted

Solution code:
# N:駅の数
# Ci:i駅から i+1 駅への移動にかかる時間(cost)
# Si:i駅の最初の発車時間(start)
# Fi:i駅の発車スパン(frequency)
# Si % Fi = 0

N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


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

for s in range(1, N+1):
    # print("start=", s)
    if s == N:
        t = 0
        pass
    else:
        t = 0
        for i in range(s, N):
            # print("i =", i)
            # print("S[", i, "] =", S[i])
            if t < S[i]:
                t = S[i]
                t += C[i]
            else:
                for j in range(F[i]):
                    if (t + j) % F[i] == 0:
                        t = t + j
                        # print("notta zikan =", t)
                        t += C[i]
                        # print("tuita zikan =", t)
                        break
    print(t)

Submission status: Accepted

Solution code:
# N:駅の数
# Ci:i駅から i+1 駅への移動にかかる時間(cost)
# Si:i駅の最初の発車時間(start)
# Fi:i駅の発車スパン(frequency)
# Si % Fi = 0

N = int(input())
C = [0 for i in range(N)]
S = [0 for i in range(N)]
F = [0 for i in range(N)]
C[0], S[0], F[0] = 0, 0, 0


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

for s in range(1, N+1):
    # print("start=", s)
    if s == N:
        t = 0
        pass
    else:
        t = 0
        for i in range(s, N):
            # print("i =", i)
            # print("S[", i, "] =", S[i])
            if t < S[i]:
                t = S[i]
            for j in range(F[i]):
                if (t + j) % F[i] == 0:
                    t = t + j
                    # print("notta zikan =", t)
                    t += C[i]
                    # print("tuita zikan =", t)
                    break
    print(t)

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-1):
    start = CSF[i][1]
    
    goal = 0
    for cur in range(i,N-1):
        start = max(CSF[cur][1], 
                    (goal//CSF[cur][2]+bool(goal%CSF[cur][2])) * CSF[cur][2])
        goal = start + CSF[cur][0]
        
    print(goal)
    
print(0)

Submission status: Accepted

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

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 = [0]*(N-1)
for i in range(N-1):
    C[i] = list( map( int, input().split()))
for i in range(N-1):
    k = i
    ans = 0
    while k < N-1:
        if ans <= C[k][1]:
            ans = C[k][1] + C[k][0]
        else:
            ans += (C[k][2] - ans)%C[k][2] + C[k][0]
        k += 1
    print(ans)
print(0)

Submission status: Accepted

Solution code:
n = int(input())

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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 csf[j][1]>t:
      t+=(csf[j][1]-t)
    if t%csf[j][2]!=0:
      t+=(csf[j][2]-t%csf[j][2])
    t+=csf[j][0]
  print(t)
print(0)

Submission status: Accepted

Solution code:
import math
def find(now,S, F):
    if now<S:
         ans = S
    else:
         ans = math.ceil(now/F)*F
    return(ans)

n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-2):
    ans = csf[i][1];
    for j in range(i,n-2):
        ans = find(ans+csf[j][0],csf[j+1][1],csf[j+1][2])
    print(ans+csf[n-2][0])
if n!=1: print(csf[n-2][0]+csf[n-2][1])
print(0)

Submission status: Accepted

Solution code:
def main():
    
    N = int(input())
    CSF = []
    for i in range(N-1):
        CSF.append(list(map(int, input().split())))
    CSF.append([0,0,1])
    
    # loop
    ans_list = []
    for st in range(N-1):
        ans = CSF[st][1]
        for i in range(st,N-1):
            nex = ans + CSF[i][0]
            if nex <= CSF[i+1][1]:
                ans = CSF[i+1][1]
            else:
                if nex%CSF[i+1][2] == 0:
                    ans = nex
                else:
                    ans = (nex//CSF[i+1][2] + 1) * CSF[i+1][2]

        ans_list.append(ans)
    
    ans_list.append(0)
    
    for ans in ans_list:
        print(ans)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

N=int(input())
C,S,F = [],[],[]

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

for i in range(N-1):
    ans = C[i]+S[i]
    for j in range(1,N-1)[i:]:
        ans = max(math.ceil(ans/F[j])*F[j],S[j])+C[j]
    print(ans)
    
print(0)

Submission status: Accepted

Solution code:
N=int(input())
C = []
S = []
F = []
for i in range(N-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
def calcTime(loc,time):
    while loc < N-1:
        deltaT = time - S[loc]
        if deltaT < 0:
            time = S[loc] + C[loc]
        elif deltaT % F[loc] == 0:
            time += C[loc]
        else:
            time += F[loc] - (deltaT % F[loc]) + C[loc]
        loc += 1

    return time
for i in range(N-1):
    print(calcTime(i,S[i]))
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):
    tmp = 0
    for j in range(i,N-1):
        tmp = max(tmp, CSF[j][1])

        if not (tmp % CSF[j][2] == 0):
            tmp = tmp + CSF[j][2] - tmp % CSF[j][2]
        tmp += CSF[j][0]
            
    print(tmp)

Submission status: Accepted

Solution code:
N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]
result = [0]*N
for i in range(N-1):
    now = CSF[i][1] + CSF[i][0]
    for j in range(i+1,N-1):
        c,s,f = CSF[j]
        if s >= now:
            now = c + s 
        else:
            now = c + (now if now % f == 0 else (now // f+1)*f)
    result[i] = now
print(*result,sep='\n')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 20 16:39:29 2018

@author: Yuya
"""


N = int(input())

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

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

time = 0
print(time)