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 = []
for _ in range(n-1):
	INPUT = list(map(int, input().split()))
	c.append(INPUT[0])
	s.append(INPUT[1])
	f.append(INPUT[2])

for i in range(n):
	if i == n-1:
		print(0)
	else:
		cc = c[i:]
		ss = s[i:]
		ff = f[i:]
		ans = cc[0] + ss[0]
		for j in range(n-2-i):
			if ans <= ss[j+1]:
				ans = cc[j+1] + ss[j+1]
			else:
				start = (((ans - ss[j+1] + ff[j+1] - 1) // ff[j+1]) * ff[j+1]) + ss[j+1]
				ans = start + cc[j+1]

		print(ans)

Submission status: Accepted

Solution code:
from itertools import accumulate

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

def make_func(c, s, f):
    def func(t):
        t = max(t, s)
        a, b = divmod(t, f)
        return f * (a + (b != 0)) + c
    return func

funcs = [make_func(*csf) for csf in csfs]
funcs2 = accumulate(funcs[::-1], func=lambda f1, f2: lambda x: f1(f2(x)))

res = [0] + [f(0) for f in funcs2]
for time in reversed(res):
    print(time)

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):
        t = max(S[j], (t+F[j]-1)//F[j]*F[j]) + C[j]
    print(t)

Submission status: Accepted

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

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

Submission status: Accepted

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

N = int(input())

C_list = [0] * (N-1)
S_list = [0] * (N-1)
F_list = [0] * (N-1)
for i in range(N-1):
    C_list[i], S_list[i], F_list[i] = map(int, input().split())

# 出発駅の数でループ
for i in range(N-1):
    # 次の行の出力のために初期化
    ans = 0
    # ある出発駅から最終駅までのループ
    for j in range(i, N-1):
        # 開始時の待ち時間
        if ans < S_list[j]:
            ans = S_list[j]
        # 次の駅への移動時間
        ans += C_list[j]
        # 次の出発前の待ち時間(最終駅に着いた時以外)
        if j != N-2:
            if ans % F_list[j+1] != 0:
                ans += F_list[j+1] - ans % F_list[j+1]
    print(ans)
# 出発駅 = 最終駅の出力
print(0)

Submission status: Accepted

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

N = int(input())

C_list = [0] * (N-1)
S_list = [0] * (N-1)
F_list = [0] * (N-1)
for i in range(N-1):
    C_list[i], S_list[i], F_list[i] = map(int, input().split())

# 出発駅の数でループ
for i in range(N-1):
    # 次の行の出力のために初期化
    ans = 0
    # ある出発駅から最終駅までのループ
    for j in range(i, N-1):
        # 開始時の待ち時間
        if j == i:
            ans += S_list[j]
        # 次の駅に着いた時、その駅の開始時待ちがまだある場合
        elif ans < S_list[j]:
            ans = S_list[j]
        # 次の駅への移動時間
        ans += C_list[j]
        # 次の出発前の待ち時間(最終駅に着いた時以外)
        if j != N-2:
            if ans % F_list[j+1] != 0:
                ans += F_list[j+1] - ans % F_list[j+1]
    print(ans)
# 出発駅 = 最終駅の出力
print(0)

Submission status: Accepted

Solution code:
def main():
    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())

    for i in range(N-1):
        t = 0
        now = i
        while now < N-1:
            if t < S[now]:
                t = S[now]
            for dt in range(101):
                if (t+dt)%F[now]==0:
                    t += dt + C[now]
                    now += 1
                    break
        print(t)
    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    print(t)

Submission status: Accepted

Solution code:
import math
numOfStation = int(input())
array = [0] * (numOfStation - 1)

for i in range(numOfStation - 1):
    array[i] = input().split()

for i in range(numOfStation - 1):
    time = 0
    for j in range(i, numOfStation - 1):
        nextTrain = int(array[j][1])
        # check the next train
        if time > nextTrain:
            # Additional time to catch the next one
            nextTrain += math.ceil((time - nextTrain)/int(array[j][2]))*int(array[j][2])

        time += (nextTrain - time) + int(array[j][0])  # Time arrived at the next station

    print(time)

print(0)

Submission status: Accepted

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


def departure_t(t, j):
    if t < S[j]:
        return S[j]
    elif t % F[j] == 0:
        return t
    else:
        return t - t % F[j] + F[j]


for i in range(N):
    t = 0
    for j in range(i, N - 1):
        t = departure_t(t, j)
        t += C[j]
    print(t)

Submission status: Accepted

Solution code:
N = int(input())
Nminus1 = N - 1
# lines = []

CSF = []
# S = [0 for _ in range(Nminus1)]
# F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()
    CSF.append((int(c), int(s), int(f)))
    # C[i] = int(c)
    # S[i] = int(s)
    # F[i] = int(f)

# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))

ans = []

for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a < S:
            a = S
        elif a % F == 0:
        	pass
        else:
            a += F - a % F
        a += C
    ans.append(a)

ans.append(0)
print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())
Nminus1 = N - 1
# lines = []

CSF = []
# S = [0 for _ in range(Nminus1)]
# F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()
    CSF.append((int(c), int(s), int(f)))
    # C[i] = int(c)
    # S[i] = int(s)
    # F[i] = int(f)

# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))

ans = []

for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a <= S:
            n = S - a
        else:
            mod = a % F 
            n = F - mod if mod != 0 else 0
        a = a + C + n
    ans.append(a)

ans.append(0)
print('\n'.join(map(str, ans)))

Submission status: Accepted

Solution code:
N = int(input())
Nminus1 = N - 1
# lines = []

CSF = []
# S = [0 for _ in range(Nminus1)]
# F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()
    CSF.append((int(c), int(s), int(f)))
    # C[i] = int(c)
    # S[i] = int(s)
    # F[i] = int(f)

# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))

for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a <= S:
            n = S - a
        else:
            mod = a % F 
            n = F - mod if mod != 0 else 0
        a = a + C + n
    print(a)

print(0)

Submission status: Accepted

Solution code:
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  # 駅iからNまでにかかる時間
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  # まだ運行していないので、運行するまで待つ必要がある
            elif t % f == 0:
                # tがfで割り切れるなら、すぐに鉄道に乗ればよい
                # sはfで割り切れることが保証されているので、この条件式でよい
                pass
            else:
                t += f - (t % f)  # この分だけ駅で待つ必要がある
            t += c  # 次の駅までかかる時間
        ans.append(t)
    return '\n'.join(map(str, ans))
 
N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))

Submission status: Accepted

Solution code:
# test
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  # 駅iからNまでにかかる時間
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  # まだ運行していないので、運行するまで待つ必要がある
            elif t % f == 0:
                # tがfで割り切れるなら、すぐに鉄道に乗ればよい
                # sはfで割り切れることが保証されているので、この条件式でよい
                pass
            else:
                t += f - (t % f)  # この分だけ駅で待つ必要がある
            t += c  # 次の駅までかかる時間
        ans.append(t)
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))

Submission status: Accepted

Solution code:
N = int(input())
Nminus1 = N - 1
# lines = []

CSF = [0 for _ in range(Nminus1)]
# S = [0 for _ in range(Nminus1)]
# F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()
    CSF[i] = (int(c), int(s), int(f))
    # C[i] = int(c)
    # S[i] = int(s)
    # F[i] = int(f)

# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))

for i in range(Nminus1):
    a = 0
    for j in range(i, Nminus1):
        C, S, F = CSF[j]
        if a <= S:
            n = S - a
        else:
            mod = a % F 
            n = F - mod if mod != 0 else 0
        a = a + C + n
    print(a)

print(0)

Submission status: Accepted

Solution code:
N = int(input())
Nminus1 = N - 1
# lines = []

C = [0 for _ in range(Nminus1)]
S = [0 for _ in range(Nminus1)]
F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()

    C[i] = int(c)
    S[i] = int(s)
    F[i] = int(f)

# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))

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

print(0)

Submission status: Accepted

Solution code:
n = int(input())

_list = []
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    _list.append([a, b, c])


for i in range(n - 1):
    num = i
    time = 0

    while num < n - 1:
        c, s, f = _list[num]

        if num == i:
            time += s + c
            num += 1
            continue

        wait = s - time

        if wait >= 0:
            time += wait + c
            num += 1
            continue

        test = (wait * -1) // f
        s += int(f * test)

        wait = s - time

        if wait >= 0:
            time += wait + c

        else:
            time += wait + c + f

        num += 1

    print(time)


print(0)

Submission status: Accepted

Solution code:
n = int(input())

_list = []
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    _list.append([a, b, c])


for i in range(n - 1):
    num = i
    time = 0

    while num < n - 1:
        c, s, f = _list[num]

        if num == i:
            time += s + c
            num += 1
            continue

        while True:
            wait = s - time

            if wait >= 0:
                time += wait + c
                break

            test = (wait * -1) // f
            s += int(f * test)

            if s - time < 0:
                s += f

        num += 1

    print(time)


print(0)

Submission status: Accepted

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

for i in range(N-1):
    lines.append(input())

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

for line in lines:
	c, s, f = line.split()
	C.append(int(c))
	S.append(int(s))
	F.append(int(f))

A = []

for i in range(N-1):
	a = C[i] + S[i]
	for j in range(i + 1, N - 1):
		if a <= S[j]:
			n = S[j] - a
		else:
			mod = a % F[j] 
			n = F[j] - mod if mod != 0 else 0
		a = a + C[j] + n
	A.append(a)

for a in A:
	print(a)
print(0)

Submission status: Accepted

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

for i in range(N-1):
    lines.append(input())

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

for line in lines:
	c, s, f = line.split()
	C.append(int(c))
	S.append(int(s))
	F.append(int(f))

A = []

for i in range(N-1):
	a = C[i] + S[i]
	for j in range(i + 1, N - 1):
		n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
		n = F[j] - n if a > S[j] and n != 0 else n
		# n = S[j] - a if a <= S[j] else a % F[j]
		a = a + C[j] + n
	A.append(a)

for a in A:
	print(a)
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)

results = []
for i in range(N):
    x = 0
    for n in range(i, N-1):
        if x < S[n]:
            x = S[n]
        if not (x - S[n]) % F[n] == 0:
            x += F[n] - (x - S[n]) % F[n]
        x += C[n]
    results.append(x)

for result in results:
    print(result)

Submission status: Accepted

Solution code:
N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    C_temp,S_temp,F_temp = map(int,input().split())
    C.append(C_temp)
    S.append(S_temp)
    F.append(F_temp)
ans = S[0]
for i in range(N):
    t = 0
    for j in range(i,N-1):
        if t<S[j]:
            t = S[j]
        elif t%F[j] == 0:
            pass
        else:
            t = t+F[j] -t%F[j]
        t += C[j]
    print(t)

Submission status: Accepted

Solution code:
N = int(input())
train = [ list(map(int,input().split())) for i in range(N-1)]
for i in range(N-1):
    a = [ 0 for i in range(i+1)]
    a[i] = train[i][1] + train[i][0]
    for j in range(i):
        if train[i][1] >= b[j]:
            a[j] = a[i]
        else:
            a[j] = (((b[j] - train[i][1] - 1) // train[i][2]) + 1) * train[i][2] + a[i]
    b = a
for i in a:
    print(i)
print(0)

Submission status: Accepted

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

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

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
    while i != n-1:
        if i == 0:
            time += S[i]
        elif S[i] <= time and time%F[i] == 0:
            time += 0
        else:
            if time > S[i]:
                r = (time-S[i])//F[i]
                time = S[i] + F[i]*(r + 1)
            else:
                time = S[i]
        time += C[i]
        i += 1        
    print(time)

print(0)

Submission status: Accepted

Solution code:
N = int(input())

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

for i in range(N-1):
    C_i = CSF[i][0]
    S_i = CSF[i][1]
    t = S_i + C_i
    for j in range(i+1,N-1):
        C_j, S_j, F_j = CSF[j]
        if t > S_j:
            w = t%F_j
            if w == 0:
                t += C_j
            else:
                t += F_j - w + C_j
        else:
            t = S_j + C_j
    print(t)
print(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):
    T = 0
    for j in range(i, N-1):
        if S[j] > T:
            T = S[j]

        if T % F[j] != 0:
            T += F[j] - T%F[j]

        T += C[j]

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

Submission status: Accepted

Solution code:
n  = int(input())
a = []
for i in range(n-1):
    a.append([int(i) for i in input().split()])
a.append([0,0,1])
#print(a)

for i in range(n):
    time = a[i][0]+a[i][1]
    for j in range(i+1, n):
        if(time < a[j][1]):
            time = a[j][0]+a[j][1]
        else:
            while(True):
                if(time%a[j][2] == 0):
                    time += a[j][0]
                    break
                else:
                    time += 1
    print(time)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N=int(input().strip())
C=[0,]
S=[0,]
F=[0,]
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(1,N):
    dept=S[i]
    for j in range(i+1,N):
        arrive=dept+C[j-1]
        gap=arrive%F[j]
        dept=S[j] if arrive<=S[j] else arrive+((F[j]-gap)if gap>0 else 0)
    print(dept+C[N-1])
print(0)

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(raw_input())
l = [map(int, raw_input().split()) for _ in range(n-1)]
m = []
for i in range(n-1):
    m.append(l[i][1]+l[i][0])
    for j in range(i):
        if m[j] <= l[i][1]:
            m[j] = m[i]
        else:
            k = (m[j] + l[i][2] - 1) / l[i][2] * l[i][2]
            m[j] = k +  l[i][0]
m.append(0)
for i in m:
    print i

Submission status: Accepted

Solution code:
def f(vs):
    t = 0
    for i in range(len(vs)):
        c, s, f = vs[i]
        m = max(0, (t - s + f - 1) / f)
        t = s + m*f + c
    return t

def solve():
    n = input()
    vs = [map(int, raw_input().split()) for i in range(n-1)]
    return [f(vs[i:]) for i in range(n)]

print "\n".join(map(str, solve()))

Submission status: Accepted

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

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

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

print(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N = int(input())

stations = [inpl() for _ in range(N-1)]

for i in range(N):
    now = 0
    for C, S, F in stations[i:]:
        if now <= S:
            now = S
        now = S + -(-(now - S)//F)*F + C
        
    print(now)

Submission status: Accepted

Solution code:
N = int(input())
C = []
S = []
F = []
T = [0 for i in range(N)]

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

for t in T:
    print(t)

Submission status: Accepted

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

for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t<CSF[j][1]:
            t = CSF[j][1]
        elif t%CSF[j][2]==0:
            pass
        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):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(1,N):
    time = 0
    time += S[i]
    for j in range(i,N-1):
        time += C[j]
        if S[j+1]>=time:
            time=S[j+1]
        else:
            if (time-S[j+1])%F[j+1]!=0:
                time += F[j+1]-int((time-S[j+1])%F[j+1])
    time += C[N-1]
    print(time)

print(0)

Submission status: Accepted

Solution code:
import math
n = int(input())
params = [[int(param) for param in input().split()] for _ in range(n-1)]


while params:

    c, s, f = params.pop(0)
    total = s + c

    for index, param in enumerate(params):
        c, s, f = param

        if (s > total):
            total = s + c
        elif((total-s) % f == 0):
            total += c
        else:
            total = (total + f) - (total % f) + c
            # if ((total-s) % f == 0):
            #     total += c
            # else:
            #     total = math.ceil((total-s)/f)*f + c

    print(total)

print(0)

Submission status: Accepted

Solution code:
n = int(input())
cs = []
ss = []
fs = []
for i in range(n - 1):
    c, s, f = input().split()
    c = int(c)
    s = int(s)
    f = int(f)
    cs.append(c)
    ss.append(s)
    fs.append(f)
for i in range(n):
    t = 0
    for j in range(i, n - 1):
        c, s, f = cs[j], ss[j], fs[j]
        if t < s:
            t = s + c
        elif t % f == 0:
            t += c
        else:
            t += f - t % f + c
    print(t)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def min_times(stations, n):
    times = []
    for i in range(n - 1):
        ci, si, fi = stations[i]
        t = si + ci
        for j in range(i + 1, n - 1):
            cj, sj, fj = stations[j]
            if t < sj:
                t = sj + cj
            else:
                waiting = fj - (t - sj) % fj if (t - sj) % fj != 0 else 0
                t += waiting + cj
        times.append(t)
    times.append(0)
    return times


if __name__ == '__main__':
    n = int(input())
    stations = [list(map(int, input().split())) for _ in range(n - 1)]
    for i in min_times(stations, n):
        print(i)

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):
    t = 0
    for j in range(i, n-1):
        if t < s[j]:
            t += s[j] - t

        if t%f[j] == 0:
            t += c[j]
        else:
            t += f[j] - t % f[j] + c[j]

    print(t)

print(0)

Submission status: Accepted

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

for k in range(N):
	t = 0
	for i in range(k,N-1):
		if t < T[i][1]:
			t = T[i][0]+T[i][1]
		else:
			t += T[i][0]+ (T[i][2]-t%T[i][2])%T[i][2]
	print(t)

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-1):
    T = S[i]
    for j in range(i,N-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]) + C[j]
    print(T)
print(0)

Submission status: Accepted

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

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

print(0)

Submission status: Accepted

Solution code:
class station:
    def __init__(self, speed, first, interval):
        self.speed = speed
        self.first = first
        self.interval = interval


def onboard_duration(station, start_time, first=False):
    # return the arrival_time at the next_station
    if first or start_time < station.first: # starting station or the first train is not departed from the station
        return station.first + station.speed
    elif start_time % station.interval == 0:
        return start_time + station.speed
    else:
        return start_time + station.interval - (start_time % station.interval) + station.speed


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

for i in range(len(stations)):
    elapsed_time = 0
    for j in range(i, len(stations)):
        if elapsed_time == 0:
            elapsed_time = onboard_duration(stations[j], elapsed_time, first=True)
        else:
            elapsed_time = onboard_duration(stations[j], elapsed_time)
    print(elapsed_time)

print('0')

Submission status: Accepted

Solution code:
import math
N=int(input())-1
c,s,f=[],[],[]
for i in range(N):
    a=list(map(int,input().split()))
    c.append(a[0])
    s.append(a[1])
    f.append(a[2])
for j in range(N):
    t=c[j]+s[j]
    for k in range(1,N-j):
        if s[j+k]>=t:
            t=s[j+k]+c[j+k]
        else:
            t=math.ceil((t-s[j+k])/f[j+k])*f[j+k]+s[j+k]+c[j+k]
    print(t)
print("0")

Submission status: Accepted

Solution code:
def next_start(S, F):
    for i in range(S, S + F + 1):
        if i % F == 0:
            return i


N = int(input())
Cs, Ss, Fs = [], [], []

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


for nth in range(N - 1):
    t = 0
    for i in range(nth, N - 1):
        # print(i, nth, t)
        t = max(Ss[i], next_start(t, Fs[i]))
        # print('\t\t', i, nth, t)
        t += Cs[i]
        # print('\t', i, nth, t)
    print(t)
print(0)

Submission status: Accepted

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

def station(time, i):
    if i == N:
        print(time)
        return
    c, s, f = CSF[i]
    nextTime = s + c if time <= s else math.ceil(time / f) * f + c
    station(nextTime, i+1)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
t = [[0 for _ in range(3)] for j in range(N-1)]
for i in range(N-1):
    t[i][0], t[i][1], t[i][2] = map(int, input().split())

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

Submission status: Accepted

Solution code:
N = int(input())
t = [[0 for _ in range(3)] for j in range(N-1)]
for i in range(N-1):
    t[i][0], t[i][1], t[i][2] = map(int, input().split())

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