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: Time Limit Exceeded

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

for i in range(N-1):
    result = 0
    for j in range(i, N-1):
        if result <= CSF[j][1]:
            result = CSF[j][0] + CSF[j][1]
        else:
            flag = True
            num = CSF[j][1] + CSF[j][2]
            while flag:
                if num >= result:
                    result = num + CSF[j][0]
                    flag = False
                num += CSF[j][2]

    print(result)

print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

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

for i in range(N):
  if i == N-1:
    print(0)
  else:
    T = S[i]+C[i]
    for k in range(i+1,N-1):
      a = 0
      while T > S[k]+a*F[k]:
        a+=1
      T = S[k]+a*F[k]+C[k]
    print(int(T))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[]
for i in range(n-1):
    a.append(list(map(int,input().split())))
for i in range(n-2):
    ans=a[i][0]+a[i][1]
    m=0
    while True:
        if ans < a[i + 1][1] + (m+1) * a[i + 1][2]:
            ans=a[i + 1][1] + m * a[i + 1][2]+a[i+1][0]
            break
        else:
            m +=1
    for j in range(i+2,n-1):
        m=0
        while True:
            if ans<a[j][1]+(m+1)*a[j][2]:
                ans=a[j][1]+m*a[j][2]+a[j][0]
                break
            else:
                m+=1
    print(ans)
print(a[n-2][0]+a[n-2][1])
print(0)

Submission status: Time Limit Exceeded

Solution code:
def cal_t():
    for i in range(N-1):
        for j in range(N-1-i): # jは区間
            if j == 0:
                t[i][0] = S[i] + C[i]
            else:
                for n in range(100000):
                    wait_t = S[i+j] + F[i+j] * n - t[i][j-1]
                    if wait_t >= 0:
                        t[i][j] = t[i][j-1] + wait_t + C[i+j]
                        break

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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):
            C_j, S_j, F_j = train_info[j - 1]
            while True:
                if (t >= S_j) & (t % F_j == 0):
                    t += C_j
                    break
                else:
                    t += 1

        print(t)

Submission status: Time Limit Exceeded

Solution code:
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:
            while res>s:
                s += f
            res = s + c
        #print(i,res)
    print(res)

Submission status: Time Limit Exceeded

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(10000000):
                if t <= S[i] + j * F[i]:
                    t = S[i] + j * F[i]
                    # print("notta zikan =", t)
                    t += C[i]
                    # print("tuita zikan =", t)
                    break
    print(t)

Submission status: Time Limit Exceeded

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)
            for j in range(10000000):
                if t <= S[i] + j * F[i]:
                    t = S[i] + j * F[i]
                    # print("notta zikan =", t)
                    t += C[i]
                    # print("tuita zikan =", t)
                    break
    print(t)

Submission status: Time Limit Exceeded

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


def get_t(x, i):
    t = S[i]
    while x > t:
        t += F[i]
    return t


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

Submission status: Time Limit Exceeded

Solution code:
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
        while time > nextTrain:
            #Additional time to catch the next one
            nextTrain += int(array[j][2])

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

    print(time)

print(0)

Submission status: Time Limit Exceeded

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

            s += f

        num += 1

    print(time)


print(0)

Submission status: Time Limit Exceeded

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:
            train = S[i]
            while time >= train:
                train += F[i]
            time = train
        time += C[i]
        i += 1        
    print(time)

print(0)

Submission status: Time Limit Exceeded

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]
        else:
            train = S[i]
            while time > train:
                train += F[i]
            time = train
        time += C[i]
        i += 1        
    print(time)

print(0)

Submission status: Time Limit Exceeded

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 = l[i][1] + l[i][2]
            while m[j] > k:
                k += l[i][2]
            m[j] = k +  l[i][0]
m.append(0)
for i in m:
    print i

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
train_data=[(input().split())for i in range (N-1)] 
answer=0
#for i in range (N-1):
for i in range (N-1):
    answer=0
    answer+=int(train_data[i][0])+int(train_data[i][1])
    for j in range (i+1,N-1):
        count=0
        if answer<int(train_data[j][1]):
            answer=int(train_data[j][1])
        while answer>count:
            count+=int(train_data[j][2])
        answer=count+int(train_data[j][0])
    print (answer)
print(0)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lst=[]
for i in range(n-1):
    lst.append(list(map(int,input().split())))
def neccesary_time(m):
    t=0
    for i in range(m,n-1):
        s=lst[i][1]
        if t<=s:
            t=s+lst[i][0]
        else:
            while s<t:
                s+=lst[i][2]
            t=s+lst[i][0]
    return t
for i in range(n-1):
    print(neccesary_time(i))
print(0)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

    time = [[] for _ in [0] * N]
    end = CSF[0][1] + 1
    for i, (c, s, f) in enumerate(CSF):
        end = max(end, s + 1)
        time[i] = [j for j in range(s, end, f)]
        end += c + s

    for i in range(N - 1):
        sec = 0
        for j in range(i, N - 1):
            n = bisect.bisect_left(time[j], sec)
            sec = time[j][n] + CSF[j][0]
        print(sec)
    print(0)

main()

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

def main():
    N = int(input())
    infos = []
    for i in range(1,N):
        infos.append(tuple(map(int, input().split())))

    for i in range(1,N):
        current_time = 0
        for station_number in range(i,N):
            current_time = next_arrival_time(current_time, infos[station_number -1])
        print(current_time)
    print(0)

@lru_cache(maxsize = 2**26)
def next_arrival_time(current_time, info):
    if current_time <= info[1]:
        return info[1] + info[0]

    next_time = info[1]
    while next_time < current_time:
        next_time += info[2]

    return next_time + info[0]

main()

Submission status: Time Limit Exceeded

Solution code:
from functools import lru_cache

def main():
    N = int(input())
    infos = []
    for i in range(1,N):
        infos.append(tuple(map(int, input().split())))

    for i in range(1,N):
        current_time = 0
        for station_number in range(i,N):
            current_time = next_arrival_time(current_time, infos[station_number -1])
        print(current_time)
    print(0)

@lru_cache(maxsize = 10**6)
def next_arrival_time(current_time, info):
    if current_time <= info[1]:
        return info[1] + info[0]

    next_time = info[1]
    while next_time < current_time:
        next_time += info[2]

    return next_time + info[0]

main()

Submission status: Time Limit Exceeded

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

    for i in range(1,N):
        current_time = 0
        for station_number in range(i,N):
            current_time = next_arrival_time(current_time, infos[station_number -1])
        print(current_time)
    print(0)

def next_arrival_time(current_time, info):
    if current_time <= info[1]:
        return info[1] + info[0]

    next_time = info[1]
    while next_time < current_time:
        next_time += info[2]

    return next_time + info[0]

main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
x = [[int(i) for i in input().split()] for  i in range(n-1)]
for j in range(n-1):
	answer = x[j][0]+x[j][1]
	for k in range(j+1,n-1):
		num = x[k][1]
		while num<answer: num+=x[k][2]
		answer = num+x[k][0]
	print(answer)
print(0)

Submission status: Time Limit Exceeded

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):
    sumTime = 0
    stationNumber = i
    #print("(●・▽・●)",stationNumber)
    while stationNumber < N - 1:
        #print("(●・▽・●)(●・▽・●)", stationNumber, sumTime)
        if sumTime <= s[stationNumber]:
            sumTime = s[stationNumber]

        if (sumTime - s[stationNumber]) % f[stationNumber] == 0:
            sumTime += c[stationNumber]
            stationNumber += 1
        else:
            sumTime += 1

    print(sumTime)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc084/tasks/abc084_c

"""
import sys
from sys import stdin
from collections import namedtuple
from math import ceil
input = stdin.readline


def solve(trains, N):
    arrives = []

    for i in range(N-1):
        arrives.append(0)
        for j in range(len(arrives)):
            dt = trains[i].S
            while dt < arrives[j]:
                dt += trains[i].F
            arrives[j] = dt + trains[i].C

    arrives.append(0)
    return arrives


T = namedtuple('T', ['C', 'S', 'F'])
def main(args):
    trains = []
    N = int(input())
    for _ in range(N-1):
        c, s, f = map(int, input().split())
        trains.append(T(c, s, f))
    ans = solve(trains, N)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
def F(Arri,S,F,C):
    k=0
    while Arri > (S+F*k):
        k+=1
    return S+F*k+C

N=int(input())
n=0
L=[]
l = [0,0,0]
while n < N-1:
    l[0],l[1],l[2] = map(int,input().split(' '))
    L.append(l.copy())
    n+=1
T = []
j = 0
while j < N-1:
    t=0
    t += L[j][0]+L[j][1]
    q=j+1
    while q < N-1:
        t = F(t,L[q][1],L[q][2],L[q][0])
        q += 1
    T.append(t)
    j += 1
T.append(0)
for i in T:
    print(i)

Submission status: Time Limit Exceeded

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)

ans = []
for j in range(N-1):
    temp = S[j]+C[j]
    temp2 = 0
    k = j
    while k < (N-1-1):
        if temp < S[k+1]:
            temp = S[k+1]
        else:
            temp2 = S[k+1]
            while temp2 < temp:
                temp2 += F[k+1]
            temp = temp2
        temp += C[k+1]
        k += 1
    ans.append(temp)

for l in range(N-1):
    print(ans[l])
    
print("0")

Submission status: Time Limit Exceeded

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

for init_station in range(N-1):
    i = init_station
    arr_t = input_list[i][1]
    arr_t += input_list[i][0]
    i += 1
    while (i < N-1):
        # 次の駅で arr_t より一つ遅い電車を調べる
        next_train = input_list[i][1]
        while (arr_t > next_train):
            next_train += input_list[i][2]
        arr_t = next_train
        arr_t += input_list[i][0]
        i += 1
    print(arr_t)

print(0)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from time import sleep

N = input()
C = []
S = []
F = []
for i in range(N - 1):
    tmp = map(int,raw_input().split())
    C.append(tmp[0])
    S.append(tmp[1])
    F.append(tmp[2])
result = []
for i in range(N - 1): # スタート駅
    arrived_time = 0
    for j in range(i, N - 1):
       # print(arrived_time)
        if j == i:
            arrived_time += S[j]
            arrived_time += C[j]
        else:
            k = 0
            depart_time = 0
            while 1:
                if S[j] + F[j] * k >= arrived_time:
                    depart_time = S[j] + F[j] * k
                    break
                k += 1
            arrived_time = depart_time + C[j]
    result.append(arrived_time)
result.append(0)
for i in result:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from time import sleep

N = input()
C = []
S = []
F = []
for i in range(N - 1):
    tmp = map(int,raw_input().split())
    C.append(tmp[0])
    S.append(tmp[1])
    F.append(tmp[2])
result = []
for i in range(N - 1): # スタート駅
    arrived_time = 0
    for j in range(i, N - 1):
       # print(arrived_time)
        if j == i:
            arrived_time += S[j]
            arrived_time += C[j]
        else:
            k = 0
            depart_time = 0
            while 1:
                if S[j] > arrived_time:
                    depart_time = S[j]
                    break
                if S[j] + F[j] * k == arrived_time:
                    depart_time = S[j] + F[j] * k
                    break
                if(S[j] + F[j] * k < arrived_time and S[j] + F[j] * (k+1) > arrived_time):
                    depart_time = S[j] + F[j] * (k + 1)
                    break
                else:
                    k += 1
            arrived_time = depart_time + C[j]
    result.append(arrived_time)
result.append(0)
for i in result:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from time import sleep

N = input()
C = []
S = []
F = []
for i in range(N - 1):
    tmp = map(int,raw_input().split())
    C.append(tmp[0])
    S.append(tmp[1])
    F.append(tmp[2])
result = []
for i in range(N - 1): # スタート駅
    arrived_time = 0
    for j in range(i, N - 1):
       # print(arrived_time)
        if j == i:
            arrived_time += S[j]
            arrived_time += C[j]
        else:
            k = 0
            depart_time = 0
            while 1:
                if S[j] > arrived_time:
                    depart_time = S[j]
                    break
                sleep(1)
                if S[j] + F[j] * k == arrived_time:
                    depart_time = S[j] + F[j] * k
                    break
                if(S[j] + F[j] * k < arrived_time and S[j] + F[j] * (k+1) > arrived_time):
                    depart_time = S[j] + F[j] * (k + 1)
                    break
                else:
                    k += 1
            arrived_time = depart_time + C[j]
    result.append(arrived_time)
result.append(0)
for i in result:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
station_num = int(input())

if station_num == 1:
    print(0)
else:
    station_list = [[0, 0, 0] for i in range(station_num)]
    
    for i in range(station_num - 1):
        station_list[i] = input().split()
    # print(station_list)
    
    for i in range(station_num):
        count = int(station_list[i][0]) + int(station_list[i][1])
        now_position = i + 1
        while True:
            if now_position == station_num - 1 or now_position == station_num:
                print(count)
                break
            else:
                while True:
                    if count < int(station_list[now_position][1]):
                        count = int(station_list[now_position][1])
                    elif count % int(station_list[now_position][2]) == 0:
                        count += int(station_list[now_position][0])
                        now_position += 1
                        break
                    else:
                        count += 1

Submission status: Time Limit Exceeded

Solution code:
station_num = int(input())
station_list = [[0, 0, 0] for i in range(station_num)]

for i in range(station_num - 1):
    station_list[i] = input().split()
# print(station_list)

for i in range(station_num):
    count = int(station_list[i][0]) + int(station_list[i][1])
    now_position = i + 1
    while True:
        if now_position == station_num - 1 or now_position == station_num:
            print(count)
            break
        else:
            while True:
                if count < int(station_list[now_position][1]):
                    count = int(station_list[now_position][1])
                elif count % int(station_list[now_position][2]) == 0:
                    count += int(station_list[now_position][0])
                    now_position += 1
                    break
                else:
                    count += 1

Submission status: Time Limit Exceeded

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:
        #print(S[-i])
        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:
                n = 1
                while True:
                    dev = S[-(i-j)] + n * F[-(i-j)] - time
                    if(0 <= dev and dev <  F[-(i-j)]):
                          time = (time + dev + C[-(i-j)])
                          break
                    n+=1
    T[-(i+1)] = time

for t in T:
    print(t)

Submission status: Time Limit Exceeded

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

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

print(0)

Submission status: Time Limit Exceeded

Solution code:
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N - 1):
        time = 0
        c, s, f = STATION[i]
        time += s + c  # 最初の駅では、開通後時間sに発車し、c秒かけて次の駅へ行く
        for j in range(i + 1, N - 1):
            c_next, s_next, f_next = STATION[j]
            while time > s_next:
                s_next += f_next  # s_next-timeが、その駅で待機しなければならない時間
            time += s_next - time + c_next  # c_next秒かけて次の駅へ行く
        ans.append(time)
    ans.append(0)  # N番目の駅からN番目の駅に行く時間は0とする
    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: Time Limit Exceeded

Solution code:
n = int(input())
t = []
for i in range(n-1):
    t.append(list(map(int, input().split())))
ans = []
for i in range(n-1):
    tmp = t[i]
    ans.append(tmp[0]+tmp[1])
    for j in range(i):
        if ans[j] > tmp[1]:
            tmp_ans = tmp[1]
            while True:
                tmp_ans += tmp[2]
                if ans[j] <= tmp_ans:
                    ans[j] = tmp_ans
                    break
        else:
            ans[j] = tmp[1]
        ans[j] += tmp[0]
ans.append(0)
for a in ans:
    print(a)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    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):
        now = 0
        for j in range(i, N - 1):
            t = 0
            while S[j] + F[j] * t < now:
                t += 1
            now += (S[j] + F[j] * t) - now
            now += C[j]
        print(now)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
a = [] 
for i in range(N-1):
    a.append(list(map(int, input().split())))
min_time = []
for i in range(N-1):
    t_min = [0]
    for j in range(N-1-i):
        start_time = a[i+j][1]
        while start_time < t_min[j]:
            start_time = start_time + a[i+j][2]
        goal_time = start_time + a[i+j][0]
        t_min.append(goal_time)
    min_time.append(t_min[-1])
for i in range(N-1):
    print(min_time[i])
print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
cc = []
ss = []
ff = []
for i in range(n-1):
    c, s, f = list(map(int, input().split()))
    cc.append(c)
    ss.append(s)
    ff.append(f)
for l in range(n-1):
    ans = ss[l]+cc[l]
    for k in range(l+1, n-1):
        temp = ss[k]
        while temp < ans:
            temp += ff[k]
        ans = temp + cc[k]
    print(ans)
print(0)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 30 21:52:40 2017

@author: kanako_note
"""

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 start in range(N-2):
    next = start + 1
    reach = S[start] + C[start]
    while(next < N-1):
        temp = S[next]
        while(1):
            if temp >= reach:
                leave = temp
                break
            temp += F[next]
        reach = leave + C[next]
        next += 1
    print(reach)
    
print(S[-1]+ C[-1])
print(0)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

n = int(input())
c = np.zeros((n-1), dtype=np.int)
s = np.zeros((n-1), dtype=np.int)
f = np.zeros((n-1), dtype=np.int)
for i in range(n-1):
    c[i], s[i], f[i] = map(int, input().split(" "))

t = np.zeros(n, dtype=np.int)
for i in range(n-1):
    w = np.zeros((n-1), dtype=np.int)
    w = copy.deepcopy(s)
    t[i] = s[i] + c[i]
    for j in range((i+1), (n-1), 1):
        k = 0
        while(True):
            if(w[j] >= t[i]):
                t[i] = w[j]
                break
            while(w[j] < t[i]):
                w[j] += f[j]
        t[i] += c[j]

for i in range(n):
    print(t[i])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

n = int(input())
c = np.zeros((n-1), dtype=np.int)
s = np.zeros((n-1), dtype=np.int)
f = np.zeros((n-1), dtype=np.int)
for i in range(n-1):
    c[i], s[i], f[i] = map(int, input().split(" "))

t = np.zeros(n, dtype=np.int)
for i in range(n-1):
    w = np.zeros((n-1), dtype=np.int)
    w = copy.deepcopy(s)
    t[i] = s[i] + c[i]
    for j in range((i+1), (n-1), 1):
        k = 0
        while(True):
            if(w[j] >= t[i]):
                t[i] = w[j]
                break
            for l in range(j, (n-1), 1):
                if(t[i] > w[l]):
                    w[l] += f[l]
        t[i] += c[j]

for i in range(n):
    print(t[i])

Submission status: Time Limit Exceeded

Solution code:
import math
n = int(input())
cc = [0 for i in range(n-1)]
ss = [0 for i in range(n-1)]
ff = [0 for i in range(n-1)]
for i in range(n-1):
    c, s, f = list(map(int, input().split()))
    cc[i] = c
    ss[i] = s
    ff[i] = f
for l in range(n-1):
    ans = ss[l]+cc[l]
    for k in range(l+1, n-1):
        temp = ss[k]
        while temp < ans:
            temp += ff[k]
        ans = temp + cc[k]
    print(ans)
print(0)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
C,S,F=[0]*(N-1),[0]*(N-1),[0]*(N-1)
for i in range(N-1):
    C[i],S[i],F[i]=map(int,input().split())
for i in range(N-1): #一周につき一つの駅([0]..[N-3])から[N-1]までの計算
    arrivalTime=S[i]+C[i]#最初発車駅の次の駅に着く時間
    for j in range(i+1,N-1):
        leaveTime=S[j]#現在考慮中の駅から初めて発車する時間
        while arrivalTime > leaveTime:
            leaveTime+=F[j]
        arrivalTime=leaveTime+C[j]
    print(arrivalTime)
print(0)#[N-1]駅

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy

n = int(input())
c = np.zeros((n-1), dtype=np.int)
s = np.zeros((n-1), dtype=np.int)
f = np.zeros((n-1), dtype=np.int)
for i in range(n-1):
    c[i], s[i], f[i] = map(int, input().split(" "))

t = np.zeros(n, dtype=np.int)
for i in range(n-1):
    w = np.zeros((n-1), dtype=np.int)
    w = copy.deepcopy(s)
    t[i] = s[i] + c[i]
    for j in range((i+1), (n-1), 1):
        k = 0
        while(True):
            if(w[j] >= t[i]):
                t[i] = w[j]
                break
            for l in range(n-1):
                if(t[i] > w[l]):
                    w[l] += f[l]
        t[i] += c[j]

for i in range(n):
    print(t[i])