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

lst2=[]
for ii in range(len(lst)):
    tmp_time = lst[ii][1]+lst[ii][0]#ii個目からii+1個目に到達する時間
    for i in range(ii+1,len(lst)):
        n = 0
        while True:
            if tmp_time <= lst[i][1] + n*lst[i][2]:
                tmp_time = lst[i][1] + n*lst[i][2]
                break
            else:
                n=n+1
        tmp_time = tmp_time + lst[i][0]
    #print(tmp_time)    
    lst2.append(tmp_time)
lst2.append(0)
for i in lst2:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
#i番目駅からのスタート
for i in range(n):
  #時間
  t = 0
  for j in range(i,n-1):
    c,s,f = l[j]
    while not (t>=s and t%f==0):
      t += 1
    t += c
  print(t)

Submission status: Time Limit Exceeded

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

def tr(s,n):
    time = c[s-1][1] + c[s-1][0]
    for j in range(s,n-1):
        for i in range (0,100000):
            if (time <= c[j][1]+c[j][2]*i):
                time = c[j][1]+c[j][2]*i+c[j][0]
                break
    return time

ans = []
for k in range(1,n):
    ans.append(tr(k,n))
ans.append(0)
print(*ans, sep='\n')

Submission status: Time Limit Exceeded

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

for i in range(N-1):
    ARR.append([int(s)for s in input().split(" ")])

def aaa(currentIndex, m, arr):
    currentStartTime = arr[currentIndex][1]
    currentCost = arr[currentIndex][0]
    currentFrequency = arr[currentIndex][2]

    i = 0
    cm = currentStartTime + currentFrequency * i
    while cm < m:
        i = i + 1
        cm = currentStartTime + currentFrequency * i

    if currentIndex == len(arr) - 1:
        return cm + currentCost
    else:
        return aaa(currentIndex + 1, cm+currentCost, arr)




def calculate(n, arr):
    for index in range(n):
        if index == n - 1:
            print(0)
            continue

        start = arr[index][1]

        result = aaa(index,start,arr)
        print(result)

calculate(N, ARR)

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())
arr=[0]*n
for i in range(n-1):
  for j in range(i,n-1):
    l=s[j]
    if arr[i]>l:
      while arr[i]>l:
        l+=f[j]
    arr[i]=l
    arr[i]+=c[j]
  print(arr[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):
    time = S[i] + C[i]
    for j in range(i+1, N-1):
        cnt = 0
        while time > S[j] + F[j] * cnt:
            cnt += 1

        time = S[j] + F[j] * cnt + C[j]
    
    print(time)

print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t < s[m][1]:
                t = s[m][1]
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [list(map(int, input().split())) for _ in range(n - 1)]
for i in range(0, n):
    t = 0
    m = i
    if i != n - 1:
        t = s[i][0] + s[i][1]
        m += 1
    while True:
        if m == n - 1:
            break
        while True:
            if (t - s[m][1]) % s[m][2] == 0 and t >= s[m][1]:
                break
            t += 1
        t += s[m][0]
        m += 1
    print(t)

Submission status: Time Limit Exceeded

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

for i in range(N-1):
    total_time = 0
    for j, (c, s, f) in enumerate(zip(C[i:], S[i:], F[i:])):
        if j == 0:
            total_time += (c + s)
        else:
            while total_time < s:
                total_time += 1
            while total_time % f != 0:
                total_time += 1
            total_time += c
    print(total_time)
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
CSF = []
for i in range(N-1):
    CSF.append(list(map(int,input().split())))
def time(t,i):
    if CSF[i][1] >= t:
        return CSF[i][1]+CSF[i][0]
    else:
        x = 1
        while t > CSF[i][1]+ x*CSF[i][2]:
            x += 1
        return CSF[i][1]+ x*CSF[i][2] + CSF[i][0]

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

print(0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

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 start in range(n-1):
    i=start
    time=S[start]
    while i < n-1:
        while time % F[i] != 0 or time<S[i]:
            time += 1
        time += C[i]
        i+=1
    print(time)
print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n-1):
    time = 0
    for j in range(i, n-1):
        if i == j:
            time += (train_list[i][0] + train_list[i][1])
        else:
            flag = False
            p = 0
            while flag is False:
                t = train_list[j][1] + train_list[j][2] * p
                if t // time >= 1:
                    flag = True
                    time = t
                    time += train_list[j][0]
                p += ((time - t)//train_list[j][2])

    print(time)

print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

for i in range(n-1):
    time = 0
    for j in range(i, n-1):
        if i == j:
            time += (train_list[i][0] + train_list[i][1])
        else:
            flag = False
            p = 0
            while flag is False:
                t = train_list[j][1] + train_list[j][2] * p
                if t // time >= 1:
                    flag = True
                    time = t
                    time += train_list[j][0]
                p += 1

    print(time)

print(0)

Submission status: Time Limit Exceeded

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

for _ in range(n-1):
	c,s,f = map(int,input().split())
	C.append(c)
	S.append(s)
	F.append(f)
	
T = [0]*n
track = [x for x in range(n)]
not_done = [False]+[True]*(n-1)
travel = [False]*(n)
currTime = 0

timeBefore = [0]*(n)


while(any(not_done)):
	for i in range(1,n):
		if not_done[i]:
			if not travel[i]:
				if T[i] < S[track[i]]:
					T[i] += 1
				elif T[i] == S[track[i]]:
					travel[i] = True
					timeBefore[i] = T[i]
				else:
					if T[i]%F[track[i]] != 0:
						T[i] += 1
					else:
						travel[i] = True
						timeBefore[i] = T[i]
			
			if travel[i]:
				if T[i] - timeBefore[i] < C[track[i]]:
					T[i] += 1
				elif T[i] - timeBefore[i] == C[track[i]]:
					travel[i] = False
					track[i] += 1
		
			if track[i] == n:
				not_done[i] = False


T.append(0)

for i in range(1,len(T)):
	print(T[i])

Submission status: Time Limit Exceeded

Solution code:
H=int(input())-1
K = [list(map(int, input().split())) for i in range(H)]
total_total=[]
for j in range(H):
    total=K[j][0]+K[j][1]
    for i in range(j,H-1):
        c1=K[i][0]
        s1=K[i][1]
        f1=K[i][2]
        c2=K[i+1][0]
        s2=K[i+1][1]
        f2=K[i+1][2]
        if total>s2:
            count=s2
            while total>count:
                count=count+f2
            total=count+c2
        else:
            total=s2+c2
    print(total)
print(0)

Submission status: Time Limit Exceeded

Solution code:
H=int(input())-1
K = [list(map(int, input().split())) for i in range(H)]
total_total=[]
for j in range(H):
    total=K[j][0]+K[j][1]
    total_list=[total]
    for i in range(j,H-1):
        c1=K[i][0]
        s1=K[i][1]
        f1=K[i][2]
        c2=K[i+1][0]
        s2=K[i+1][1]
        f2=K[i+1][2]
        if total>s2:
            count=s2
            while total>count:
                count=count+f2
            total=count+c2
        else:
            total=s2+c2
        total_list.append(total)
    total_total.append(total_list)
for i in total_total:
    print(i[-1])
print(0)

Submission status: Time Limit Exceeded

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

for i in range(n-1):
  syoki=hyou[i][0]+hyou[i][1]
  for j in range(i+1,n-1):
    temp=hyou[j][1]
    while temp<syoki:
      temp+=hyou[j][2]
    syoki=temp+hyou[j][0]
  print(syoki)
print(0)

Submission status: Time Limit Exceeded

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

for i in range(n):
    if i == n-1:
        print(0)
    else:
        ela = 0

        for j in range(i, n-1):
            if j == i:
                # noru
                ela += cond[j][1]
            elif j != i:
                # noru
                if ela <= cond[j][1]:
                    ela = cond[j][1]
                elif ela > cond[j][1]:
                    k = 0
                    while True:
                        k += 1
                        product = k*cond[j][2]   
                        if product >= ela:
                            break
                    ela = product                     
            # susumu
            ela += cond[j][0]
        print(ela)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

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

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

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

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    time = li[i][0] + li[i][1]
    for j in range(i+1, n-1):
        now = li[j][1]
        while time > now:
            now += li[j][2]
        time = now
        time += li[j][0]
    print(time)
print(0)

Submission status: Time Limit Exceeded

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

def main(N,C,S,F):
    ans = [0]*N
    for i in range(N-2):
        tmp = S[i]+C[i]
        for j in range(i+1,N-1):
            if tmp<S[j]:
                tmp = S[j]
            elif tmp>S[j] and (tmp-S[j])%F[j]!=0:
                part = F[j]
                while(1):
                    part += F[j]
                    if part>=tmp:
                        tmp = part
                        break
            
            tmp += C[j]
        ans[i] = tmp
    ans[-2] = C[-1]+S[-1]
    
    for i in ans:
        print(i)

if __name__ == '__main__':
    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)
    main(N,C,S,F)

Submission status: Time Limit Exceeded

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

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
c = [list(map(int, input().split())) for _ in range(N - 1)]
anslst = [0] * N
for i in range(N - 1):
    ans = c[i][1] + c[i][0]
    for j in range(i + 1, N - 1):
        if ans <= c[j][1]:
            ans = c[j][1] + c[j][0]
        else:
            index = 1
            tmp = c[j][1] + c[j][2]
            while ans > tmp:
                tmp = c[j][1] + index * c[j][2]
                index += 1
            ans += (tmp - ans) + c[j][0]

    anslst[i] = ans

for i in anslst:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lists=[]
for _ in range(n-1):
    s=list(map(int,input().split()))
    lists.append(s)   
for x in range(n):
    nums=x+1
    if nums==n:
        print(0)
    else:
        times=0
        while nums<n:
            if times>=lists[nums-1][1]:
                while (times-lists[nums-1][1])%lists[nums-1][2]!=0:
                    times+=1
                times+=lists[nums-1][0]
                nums+=1
                    
            else:
                times=lists[nums-1][1]
                times+=lists[nums-1][0]   
                nums+=1 
        print(times)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
lists=[]
if n==1:
    print(0)
else:
    for _ in range(n-1):
        s=list(map(int,input().split()))
        lists.append(s)
        
    for x in range(n):
        nums=x+1
        #numsはどの駅から出発するかの駅の番号(1<=nums<=n)
        if nums==n:
            print(0)
        else:
            times=0
            while nums<n:
                if times>=lists[nums-1][1]:
                    while (times-lists[nums-1][1])%lists[nums-1][2]!=0:
                        times+=1
                    times+=lists[nums-1][0]
                    nums+=1
                    
                elif times<lists[nums-1][1]:
                    times=lists[nums-1][1]
                    times+=lists[nums-1][0]   
                    nums+=1
                    
            print(times)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
s = [tuple(map(int, input().split())) for _ in range(n-1)]
s.append((0, 0, 0))

for i in range(n):
    sec = s[i][0] + s[i][1]
    for j in range(i+1, n-1):
        c = s[j][1]
        while True:
            if c >= sec:
                sec = c
                break
            c += s[j][2]
        sec += s[j][0]
    print(sec)

Submission status: Time Limit Exceeded

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

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

def func(i, t):
	if i == N - 1:
		return t
	else:
		T = S[i]
		while T < t:
			T += F[i]
		return func(i + 1, T + C[i])

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

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    t = 0
    for j in range(i,n-1):
        start = s[j] #the time you should leave station_i
        while True:
            if t <= start:
                break
            else:
                start += f[j]
        #print(start)
        t = start + c[j] #the time you reach station_i+1
        #print(t)
    print(t)
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

lst = [list(map(int, input().split())) for i in range(N-1)]
ans = []
for i in range(N-1):
  t = lst[i][0] + lst[i][1]
  for j in range(i+1, N-1):
    if (t >= lst[j][1]):
      if (t % lst[j][2] == 0):
        t += lst[j][0]
      else:
        i = 1
        while (t >= lst[j][1] + (i * lst[j][2])):
          i += 1
        t = lst[j][1] + (i * lst[j][2]) + lst[j][0]
    else:
      t = lst[j][1] + lst[j][0]
  ans.append(t)
ans.append(0)

for i in ans:
  print(i)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

def leave(a,b,c):
	while a>b:
		b += c
	return b

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# ABC084C - Special Trains
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().split())) for _ in range(n - 1))
    for i in range(n - 1):
        cur = 0
        for j in range(i, n - 1):
            m, f, s = arr[j]  # move, first train, space (interval)
            if cur <= f:
                cur = f + m
            else:
                t = f  # next train to ride
                while t < cur:
                    t += s
                cur = t + m
        print(cur)
    print(0)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

CSFs = [list(map(int, input().split(' '))) for i in range(N - 1)]

for i in range(0, N - 1):
    initial_move_time = CSFs[i][0] + CSFs[i][1]

    for j in range(i + 1, N - 1):
        if initial_move_time <= CSFs[j][1]:
            initial_move_time = CSFs[j][1]

        elif initial_move_time % CSFs[j][2] == 0:
            initial_move_time = initial_move_time

        else:
            k = 1
            while True:
                tmp = CSFs[j][1] + CSFs[j][2] * k
                if initial_move_time <= tmp:
                    initial_move_time = tmp
                    break
                k += 1
        initial_move_time += CSFs[j][0]

    print(initial_move_time)
    
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
ST = [[int(i) for i in input().split()] for j in range(N-1)]
for i in range(N-1):
    t = ST[i][1] + ST[i][0]
    for j in range(i+1,N-1):
        t = max(t, ST[j][1])
        while (t-ST[j][1])%ST[j][2] != 0:
            t += 1
        else:
            t += ST[j][0]
    else:
        print(t)
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

min_time = [0 for _ in range(N)]
for i in range(N-1):
    speed, start, interval = map(int, input().split())
    min_time[i] += start + speed
    for j in range(i):
        if min_time[j] - start < 0:
            min_time[j] = start
        else:
            while (min_time[j] - start) % interval != 0:
                min_time[j] += 1
        min_time[j] += speed

for ans in min_time:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
csf = []
t = []

def st(s,f,time): # time以下の数値のうち最小のs+t*n
    for i in range(10**10):
        if s + f * (i-1) < time <= s + f * i:
            return s+f*i
            break

for i in range(n-1):
    csf.append(list(map(int,input().split())))

for j in range(n-1): 
    time = 0
    for i in range(j,n-1):
        c,s,f = csf[i][0],csf[i][1],csf[i][2]
        if time < s:
            time = s + c
        else:
            time = st(s,f,time) + c
    print(time)
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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



def next_start_time(arrive, C, S, F):
    for i in range(1000):
        if arrive > S:
            i = (arrive - S) // F
            if arrive <= S + i * F:
                break
            else:
                i = i + 1
        elif arrive <= S + i * F:
            break
    return S + (i * F) + C


for i in range(N - 1):
    ans = 0
    for j in range(i, N - 1):
        ans = next_start_time(ans, station[j][0], station[j][1], station[j][2])
    print(ans)

print(0)

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    C = []
    S = []
    F = []
    for i in range(N-1):
        s1, s2, s3 = (int(_) for _ in input().split())
        C.append(s1)
        S.append(s2)
        F.append(s3)
    ans = []
    for h in range(N-1):
        time = 0
        for i in range(h,N-1):
            if i ==h:
                time=S[i]+C[i]
                continue
            if time <= S[i]:
                time=S[i]+C[i]
            else:
                tmp_t = S[i]
                while time > tmp_t:
                    tmp_t += F[i]
                time = tmp_t +C[i]
        ans.append(time)
    print('\n'.join(str(_) for _ in ans))
    print(0)
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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


total_time = []

time = 0
c = 0

for i in range(n-1):
    time = 0
    
    for j in range(n-(i+1)):
        s = train[c+j][1]
        if time < s:
            time = s
        
        else:
            while time > s:
                s += train[c+j][2]
            
            time += s - time
            
        
        time += train[c+j][0]
        
    total_time.append(time)
    c += 1

total_time.append(0)

for i in total_time:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
#https://atcoder.jp/contests/abc084/tasks/abc084_c
N = int(input())
CSF = [list(map(int,input().split())) for _ in range(N-1)]
for i in range(1,N+1):
    if i == N:
        print(0)
        break
    time = 0
    for j in range(i,N):
        if time == 0:
            time += CSF[j-1][1]  #はじめはS[j]秒経過  
        else:
            if time < CSF[j-1][1]:
                time = CSF[j-1][1]
            lv = CSF[j-1][1]
            while time > lv:  #timeがS[j]+F[j]またはS[j]より小さいなら
                lv += CSF[j-1][2]   #F[j]経過
        time += CSF[j-1][0]  #その後C[j]秒経過
    print(time)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    csf = []
    for _ in range(N - 1):
        C, S, F = map(int, input().split())
        csf.append((C, S, F))
    
    ans = []
    for i in range(N - 1):
        c, s, _  = csf[i]
        t = c + s
        for ii in range(i + 1, N - 1):
            nc, ns, nf = csf[ii]
            while t > ns:
                ns += nf
            t += nc + ns - t
        ans.append(t)
    ans.append(0)
    
    for t in ans:
        print(t)
    

main()

Submission status: Time Limit Exceeded

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

for i in range(N-1):
    t = csf[i][1] + csf[i][0]

    for j in range(i+1, N-1):
        if t <= csf[j][1]:
            t = csf[j][1] + csf[j][0]
            continue
        num = 0
        while True:
            if csf[j][1]+num*csf[j][2] < t <= csf[j][1]+(num+1)*csf[j][2]:
                t = csf[j][1]+(num+1)*csf[j][2] + csf[j][0]
                break
            num += 1
    print(t)

print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = []
for _ in range(n-1):
    l.append([int(i) for i in input().split()])
for j in range(n):
    l_ = l[j:]
    c = 0
    for i in range(n-1-j):
        if c <= l_[i][1]:
            c = l_[i][1]
        else:
            a = l_[i][1]
            while (c > a):
                a += l_[i][2]
            c = a
        c += l_[i][0]
    print(c)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
train = [[] for _ in range(N)]
take_time = []
for cnt in range(N - 1):
    x, y , z = map(int,input().split())
    take_time.append(x)
    for _ in range(150001 ) :
        train[cnt].append(y)
        y += z

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        index = bisect_left(train[i],now)
        now = train[i][index]
        now += take_time[i]
    print(now)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
train = [[] for _ in range(N)]
take_time = []
for cnt in range(N - 1):
    x, y , z = map(int,input().split())
    take_time.append(x)
    for _ in range(10**6+1):
        train[cnt].append(y)
        y += z

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        index = bisect_left(train[i],now)
        now = train[i][index]
        now += take_time[i]
    print(now)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
train = [[] for _ in range(N)]
take_time = []
for cnt in range(N - 1):
    x, y , z = map(int,input().split())
    take_time.append(x)
    for _ in range(10**7+1):
        train[cnt].append(y)
        y += z

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        index = bisect_left(train[i],now)
        now = train[i][index]
        now += take_time[i]
    print(now)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import math
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
csf = [IL() for i in range(N-1)]

ans = [0]*N

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

for i in ans:
	print(i)