Problem:


Score : 300 points

Problem Statement

A railroad running from west to east in Atcoder Kingdom is now complete.

There are N stations on the railroad, numbered 1 through N from west to east.

Tomorrow, the opening ceremony of the railroad will take place.

On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.

The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.

Here, it is guaranteed that F_i divides S_i.

That is, for each Time t satisfying S_i≤t and t％F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A％B denotes A modulo B, and there will be no other trains.

For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.

Constraints

1≤N≤500

1≤C_i≤100

1≤S_i≤10^5

1≤F_i≤10

S_i％F_i=0

All input values are integers.

Input

Input is given from Standard Input in the following format:

N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}

Output

Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x.

Sample Input 1

3
6 5 1
1 10 1

Sample Output 1

12
11
0

We will travel from Station 1 as follows:

5 seconds after the beginning: take the train to Station 2.

11 seconds: arrive at Station 2.

11 seconds: take the train to Station 3.

12 seconds: arrive at Station 3.

We will travel from Station 2 as follows:

10 seconds: take the train to Station 3.

11 seconds: arrive at Station 3.

Note that we should print 0 for Station 3.

Sample Input 2

4
12 24 6
52 16 4
99 2 2

Sample Output 2

187
167
101
0

Sample Input 3

4
12 13 1
44 17 17
66 4096 64

Sample Output 3

4162
4162
4162
0



Sample input:
3
6 5 1
1 10 1


Sample output:
12
11
0

Submission status: Accepted

Solution code:
import math

N = int(input())
stations = []
for _ in range(N-1):
    tmp = tuple(map(int, input().split()))
    stations.append(tmp)

ans_list = []
for i in range(len(stations)):
    C, S, F = stations[i]
    time = S + C
    index = i+1
    while index < N-1:
        next_C, next_S, next_F = stations[index]
        if next_S > time:
            time = next_S + next_C
        else:
            n = math.ceil(time / next_F)
            time = next_F * n + next_C
        index += 1
    ans_list.append(time)

ans_list.append(0)

for ans in ans_list:
    print(ans)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    n = int(input())
    csf = list()
    for i in range(n-1):
        csf.append(list(map(int, input().split())))

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n=int(input())
ans=0
if n>1:
    data=[]
    for _ in range(n-1):
        data_=list(map(int,input().split()))
        data.append(data_)
    if n>2:
        for i in range(0,n-2):
            time=data[i][1]
            for j in range(i,n-2):
                arrive=time+data[j][0]
                s=data[j+1][1]
                if arrive<=s:
                    time=s
                else:
                    f=data[j+1][2]
                    time=s+f*(math.ceil((arrive-s)/f))
            time+=data[n-2][0]
            print(time)
    time=data[n-2][0]+data[n-2][1]
    print(time)
print(ans)

Submission status: Accepted

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

for i in range(n):
    ans = 0
    for j in range(i, n-1):
        if csf[j][1] >= ans:
            ans = csf[j][0] + csf[j][1]
        else:
            ans = csf[j][0] + -(-ans //csf[j][2]) * csf[j][2]
    print(ans)

Submission status: Accepted

Solution code:
from math import ceil


def get_required_time(trains, station_num, station):
    arrival = [0] * station_num
    for i in range(station, station_num):
        if arrival[i - 1] < trains[i - 1][1]:
            arrival[i] = trains[i - 1][0] + trains[i - 1][1]
        else:
            arrival[i] = trains[i - 1][0] + trains[i - 1][2] * ceil(arrival[i - 1] / trains[i - 1][2])
    return arrival


def main():
    station_num = int(input())
    trains = [list(map(int, input().split())) for _ in range(station_num - 1)]
    for i in range(1, station_num):
        print(get_required_time(trains, station_num, i)[-1])
    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
c = []
s = []
f = []
for _ 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):
    now = i
    time = s[i]
    while now < n-1:
        time += c[now]
        now += 1
        if now == n-1:
            break
        x = time % f[now]
        if time < s[now]:
            time = s[now]
        elif x == 0:
            pass
        else:
            time += f[now] - x
    print(time)
print(0)

Submission status: Accepted

Solution code:
from math import ceil

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

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

Submission status: Accepted

Solution code:
N = int(input())
C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)
for i in range(N-1):
    ca,sa,fa = list(map(int,input().split()))
    C[i] = ca
    S[i] = sa
    F[i] = fa
time = [0] * N
for i in range(N-1):
    t = C[i]+S[i]
    for j in range(i+1,N-1):
        if t<= S[j]:
            t = S[j]
        else:
            d = t - S[j]
            k = d // F[j]
            m = d % F[j]
            if m != 0:
                t = S[j] + (k+1) * F[j]
        t += C[j]
    time[i] = t
for i in range(N):
    print(time[i])

Submission status: Accepted

Solution code:
N = int(input())
ans = []
for _ in range(N - 1):
    C, S, F = map(int, input().split())
    ans.append(S + C)
    for i in range(len(ans) - 1):
        if ans[i] <= S:
            ans[i] = S + C
        else:
            if (ans[i] - S) % F == 0:
                ans[i] += C
            else:
                ans[i] = S + F * ((ans[i] - S) // F + 1) + C

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n-1):
	c,s,f = map(int, input().split())
	a.append([c,s,f])
ans = 0
while len(a) > 0:
	ans = 0
	for i, j, k in a:
		ans = max(ans, j)
		if ans%k != 0:
			ans += k - (ans%k)
		ans += i
	print (ans)
	a.pop(0)
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):
    ans = 0
    for c,s,f in csf[i:]:
        if ans < s:
            ans = s+c
        else:
            ans = -(-ans // f) * f + c
    print(ans)

Submission status: Accepted

Solution code:
def main():
    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]
            elif t%F[j] != 0:
                t += F[j] - t%F[j]
            t += C[j]
        print(t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    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]
            elif t%F[j] == 0:
                tmp = 0
            else:
                t += F[j] - t%F[j]
            t += C[j]
        print(t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    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]
            elif t%F[j] == 0:
                tmp = 0
            else:
                t = t + F[j] - t%F[j]
            t += C[j]
        print(t)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = []
for i in range(n-1):
    tmp = list(map(int,input().split()))
    l.append(tmp)
import math
for i in range(n):
    time=0
    now=i
    while now < n-1:
        if time > l[now][1]:
            tmp = math.ceil((time - l[now][1]) / l[now][2])
            wait = tmp * l[now][2]  - (time - l[now][1])
            time+= wait + l[now][0]
        else:
            time+=l[now][1] - time + l[now][0]
        now+=1

    print(time)

Submission status: Accepted

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

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

for i in range(n):
    cnt = 0
    for j in range(i, n-1):
        c, s, f = CSF[j][0], CSF[j][1], CSF[j][2]
        if cnt < s:
            cnt = s
        elif cnt % f != 0:
            cnt = (cnt//f + 1) * f
        cnt += c
    ans[i] += cnt

for a in ans:
    print(a)

Submission status: Accepted

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

for n in range(N):
  if n == N - 1:
    print(0)
    break
  
  ans = 0
  for index, i in enumerate(li):
    if index < n:
      continue

    if ans < i[1]:
      ans = i[1]
    else:
      if (ans - i[1]) % i[2] != 0:
        ans += i[2] - (ans % i[2])

    ans += i[0]
  print(ans)

Submission status: Accepted

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

print("\n".join(str(t) for t in time))

Submission status: Accepted

Solution code:
from math import ceil

def solve(n, CSF):
    times = [0] * n
    for i, (c, s, f) in enumerate(CSF):
        for j in range(i + 1):
            if times[j] <= s:
                times[j] = s
            else:
                times[j] = s + ceil((times[j] - s) / f) * f
            times[j] += c
    return times

_n = int(input())
_CSF = [map(int, input().split()) for _ in range(_n - 1)]
print(*solve(_n, _CSF), sep='\n')

Submission status: Accepted

Solution code:
n = int(input())

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

me = 0
for i in range(n-1):
  remain = n - i - 1
  time = 0
  for r in range(remain):
    c, s, f = stations[r+i]
    if time < s:
      time = s
    elif time % f == 0:
      pass
    else:
      time = time + f - (time % f)
    time += c
  print(time)
  
print(0)

Submission status: Accepted

Solution code:
import math

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

for i in range(n-1):
    t = 0
    for j in range(i, n-1):
        if a[j][1] >= t:
            t = a[j][1]
        else:
            t = math.ceil(t / a[j][2]) * a[j][2]
        t += a[j][0]
    print(t)
print(0)

Submission status: Accepted

Solution code:
n = int(input())

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

ans = []
for i in range(n - 1):
  temp = stat[i][1]
  for j in range(i, n - 1):
    c, s, f = map(int, stat[j])
    temp = max(s, temp)
    while temp % f != 0:
      temp += 1
    temp += c
  ans.append(temp)

for i in ans:
  print(i)
print(0)

Submission status: Accepted

Solution code:
N=int(input())
TTBL=[list(map(int,input().split())) for i in range(N-1)]
def GT(k,t):
  c,s,f=TTBL[k][0],TTBL[k][1],TTBL[k][2]
  return s+max(0,t-s+(f-1))//f*f+c
for i in range(N-1):
  ret = 0
  for j in range(i,N-1):
    ret=GT(j,ret)
  print(ret)
print(0)

Submission status: Accepted

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

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

print(0)

Submission status: Accepted

Solution code:
n  = int(input())

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

#print("sLIst",sList)

for i in range(len(sList)):
  timeCount = sList[i][1]+sList[i][0] 
  for j in range(i+1,len(sList)):
    if timeCount < sList[j][1]:
      timeCount = sList[j][1]
      
    timeTmp = timeCount % sList[j][2]
    if timeTmp == 0:
      timeCount += sList[j][0]
    else:
      timeCount += sList[j][2] - timeTmp + sList[j][0]
  print(timeCount)

print(0)

Submission status: Accepted

Solution code:
n = int(input())
l = [list(map(int,input().split())) for i in range(n-1)]
for i in range(n):
    ans = 0
    if i == n-1:
        print(0)
        exit()
    for j in range(i,n-1):
        ans = l[j][0]+l[j][1]+l[j][2]*(max(((ans-l[j][1]+l[j][2]-1)//l[j][2]),0))

    print(ans)

Submission status: Accepted

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

ans =[]
#O(N^2)
#スタート地点
for i in range(N-1):
    t = S[i]
    #乗り換え地点
    for j in range(i,N-1):
        if t >= S[j]:
            pass
        else:
            t = S[j]
        if t % F[j] == 0:
            t += C[j]
        else:

            b = t % F[j]
            t += F[j] - b
            t += C[j]
    ans.append(t)

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

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n):
    s=i
    ti=0
    while s!=n-1:
        if ti<t[s][1]:
            ti=t[s][1]+t[s][0]
        else:
            ti=t[s][2]*(math.ceil(ti/t[s][2]))+t[s][0]
        s+=1
    print(ti)

Submission status: Accepted

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

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

print(0)

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):
    ans = 0
    for j in range(i,n-1):
        if ans <=train[j][1]:
            ans = train[j][1]+ train[j][0]
        else:
            if ans%train[j][2]==0:
                ans += train[j][0]
            else:
                ans = train[j][0] + (ans//train[j][2]+1)*train[j][2]
    print(ans)

print(0)

Submission status: Accepted

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

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

def calc(x): #xからの客がNに到達するのにかかる時間
    tmp = 0
    for i in range(x, N - 1):
        tmp = max((tmp + CSF[i][2] - 1) // CSF[i][2] * CSF[i][2], CSF[i][1]) + CSF[i][0] 
    return tmp


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

Submission status: Accepted

Solution code:
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]
 
def F(n):
    time = 0
    for i in range(n, N-1):
        c, s, f = CSF[i]
        if time <= s:
            time = s + c
        else:
            remainder = time % f
            time += (f-remainder)%f+c
    print(time)
for i in range(N-1):
    F(i)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
c = []
s = []
f = []
for _ in range(n-1):
    p,q,r = map(int,input().split())
    c.append(p)
    s.append(q)
    f.append(r)
a = [0]*n
for i in range(n-1):
    t = 0
    for j in range(i, n-1):
        if t <= s[j]:
            t = s[j]
        elif t%f[j] != 0:
            t += f[j]-t%f[j]
        t += c[j]
    a[i] = t
print('\n'.join(map(str, a)))

Submission status: Accepted

Solution code:
N=int(input())
A=[list(map(int,input().split())) for i in range(N-1)]
for i in range(N):
  t=0
  for j in range(i,N-1):
    if t<A[j][1]:
      t=A[j][1]
    elif (t-A[j][1])%A[j][2]:
      t+=A[j][2]-t%A[j][2]
  
    t+=A[j][0]
  print(t)

Submission status: Accepted

Solution code:
n = int(input())
CSF = [list(map(int, input().split())) for _ in range(n-1)]
C, S, F = zip(*CSF)
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]:
      t += F[j]-t%F[j]
    t += C[j]
  print(t)

Submission status: Accepted

Solution code:
import sys
import math

class cin():
    def getInt():
        return int(sys.stdin.readline().rstrip())
    def getString():
        return sys.stdin.readline().rstrip()

N = cin.getInt()
A = [list(map(int,cin.getString().split())) for i in range(N - 1)]

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

Submission status: Accepted

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

for n in range(N):
    if n != N - 1:
        # start n-th station
        t = S[n]
        for i in range(n, N - 1):
            # time to take a train i -> i+1
            t += C[i]
            # goto next station
            if i != N - 2:
                if t <= S[i + 1]:
                    t = S[i + 1]
                else:
                    if t % F[i + 1] != 0:
                        t += F[i+1] - (t % F[i+1])
        print(t)
    else:
        # start at final destination
        print(0)

Submission status: Accepted

Solution code:
N = int(input())
CSFlist = [tuple(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
    now = 0
    for c, s, f in CSFlist[i:]:
        now = max(now, s)
        now += (f - now % f) if now % f != 0 else 0
        now += c
    print(now)

Submission status: Accepted

Solution code:
n = int(input())
lst1 = [list(map(int,input().split())) for i in range(n-1)]
ans = []
for i in range(n-1):
    res = 0
    for j in range(i,n-1):
        if res < lst1[j][1]:
            res = lst1[j][1]
        elif res%lst1[j][2]==0:
            pass
        else:
            res = res+ lst1[j][2] -res%lst1[j][2] #駅を経つまでの時間を加算
        res += lst1[j][0]
        
    ans.append(res)

ans.append(0)

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import math

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

for i in range(N - 1):
    t = CSF[i][0] + CSF[i][1]
    for ii in range(i + 1, N - 1):
        if t <= CSF[ii][1]:
            t = CSF[ii][1] + CSF[ii][0]
        else:
            t = CSF[ii][1] + CSF[ii][2] * math.ceil((t - CSF[ii][1]) / CSF[ii][2]) + CSF[ii][0]
    print(t)
print(0)

Submission status: Accepted

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

ans = [0]*n
for i in range(n):
    time = 0
    for j in range(i, n-1):
        if l[j][1] - time > 0:
            time += l[j][1] - time
        if time % l[j][2] != 0:
            time += l[j][2] - time % l[j][2]
        time += l[j][0]
    ans[i] += time

for i in ans:
    print(i)

Submission status: Accepted

Solution code:
n = int(input())
dat = []
for i in range(n-1):
    c, s, f = map(int, input().split())
    dat.append([c, s, f])
for i in range(n-1):
    #print("i={0}".format(i))
    t = 0
    for j in range(i, n-1):
        # 発車時刻前ならその時刻まで待たないといけない
        #print("reqch j={0}, t={1}".format(j, t))
        t = dat[j][1] if t <= dat[j][1] else t
        # w = (t - dat[j][1]) % dat[j][2]
        w = t % dat[j][2]
        #print("    t={0}, w={1}".format(t, w))
        if w != 0:
            t += (dat[j][2] - w)
        t += dat[j][0]
        #print("next t={0}".format(t, w))
    print(t)
print(0)

Submission status: Accepted

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

result=[]
for i in range(n-1):
  temp=CSF[i][1]+CSF[i][0]
  j=i+1
  while j<n-1:
    #at+b
    a,b=CSF[j][2],CSF[j][1]
    t=(temp-b)/a
    if t<=0:
      t=0
    else:
      t=-1*((b-temp)//a)
    temp=a*t+b+CSF[j][0]  
    j+=1
  result.append(temp)

for item in result:
  print(item)
print(0)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    csf = []
    for _ in range(N - 1):
        csf.append([int(x) for x in input().split()])

    for i in range(N - 1):
        total = 0
        total = csf[i][0] + csf[i][1]
        for j in range(i + 1, N - 1):
            if total <= csf[j][1]:
                total = csf[j][1] + csf[j][0]
                continue
            else:
                if (total - csf[j][1]) % csf[j][2] != 0:
                    total += csf[j][2] - (total - csf[j][1]) % csf[j][2]
                total += csf[j][0]
        print(total)
    print(0)



if __name__ == '__main__':
    main()

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(len(C)):
  cur=0
  for j in range(i,len(C)):
    # max(現在時刻 or S[j])より大きい最小のF[j]の倍数
    # F[j]で割ったものを切り上げてF[j]掛ければOK
    # 計算量O(N**2)->250,000
    if cur<S[j]:
      cur=S[j]
    cur=((cur+F[j]-1)//F[j])*F[j]+C[j]
  print(cur)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
c = []
s = []
f = []
for _ 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 (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:
from math import ceil
n = int(input())
cc = [0]*(n-1)
ss = [0]*(n-1)
ff = [0]*(n-1)
ans = [0]*n

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

for i in range(n-1):
    for j in range(i,n-1):
        x = max(0,ceil((ans[i]-ss[j])/ff[j]))
        ans[i] = ss[j] + x*ff[j] + cc[j]

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

Submission status: Accepted

Solution code:
a = int(input())
l = []

for i in range(a-1):
    ta,tb,tc  = map(int,input().split())
    l.append([ta,tb,tc])

for i in range(a-1):
    s = 0
    s += sum(l[i][:2])
    for j in range(i+1,a-1):
        # print(i,j,s)
        if s<= l[j][1]:s = sum(l[j][:2])
        elif s%l[j][2]==0 :s+=l[j][0]
        else : s+=l[j][2]- s%l[j][2] + l[j][0]
        # print(l[j][0])
    print(s)
print(0)

Submission status: Accepted

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

        else:
            if nowtime[h] % F[h] == 0:
                nowtime[h + 1] = nowtime[h] + C[h]
            else:
                nowtime[h+1] = nowtime[h]+F[h]-(nowtime[h] % F[h])+C[h]
    print(nowtime[N - 1])

print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left

N=int(input())
times = [list(map(int, input().split())) for i in range(N-1)]
for start in range(N-1):
    current = start + 1
    elapsed =  times[start][1] + times[start][0]
    while current < N-1:
        if elapsed < times[current][1]:
            elapsed = times[current][1]
        if elapsed % times[current][2] != 0:
            elapsed = times[current][2] * (elapsed // times[current][2] + 1)
        elapsed += times[current][0] 
        current += 1
    print(elapsed)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
C, S, F = zip(*[tuple(map(int, input().split())) for _ in range(N-1)])
S = list(s for s in S) + [0]
for i in range(N-1):
    for j in range(i, N-1):
        S[i] = max(S[i], S[j])
        while S[i] % F[j]:
            S[i] += 1
        S[i] += C[j]
print(*S, sep="\n")

Submission status: Accepted

Solution code:

n = int(input())
C = []
S = []
F = []

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

for i in range(n-1):
    time = S[i]
    time += C[i]
    for j in range(i+1, n-1):
        if time < S[j]:
            time = S[j]
        if time%F[j] != 0:
            time = F[j] * (time//F[j] + 1)
        time += C[j]
    print(time)
print(0)

Submission status: Accepted

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

Submission status: Accepted

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:
            if total_time < s:
                total_time = s
            if total_time % f != 0:
                total_time += f - total_time % f
            total_time += c
    print(total_time)
print(0)

Submission status: Accepted

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

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

    print(t)

print(0)

Submission status: Accepted

Solution code:
N = int(input())
C = []
S = []
F = []
for _ in range(N-1):
    c1, s1, f1 = map(int, input().split())
    C.append(c1)
    S.append(s1)
    F.append(f1)
    
for i in range(N-1):
    ans = 0
    for j in range(i,N-1):
        if ans <= S[j]:
            ans = S[j] + C[j]
        elif (ans - S[j]) % F[j] == 0:
            ans += C[j]
        else:
            ans += C[j] + F[j] - ((ans - S[j]) % F[j])
    print(ans)  
print(0)

Submission status: Accepted

Solution code:

N = int(input())

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

for i in range(N-1):
  count = T[i][1]
  for j in range(i, N-1):
    c, s, f = map(int, T[j])

    if count >= s and (count - s) % f == 0:
      count += c
    elif count >= s:
      count += c + f - (count - s) % f
    else:
      count = s + c
  print(count)

print(0)

Submission status: Accepted

Solution code:
N = int(input())
CSF = []
import math
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 = math.ceil((t-CSF[i][1])/CSF[i][2])
        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: 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, s, f = map(int, input().split())
    C[i] = c
    S[i] = s
    F[i] = f

ans_list = [0] * N
for i in range(N-1):
    time = 0
    time = C[i] + S[i]
    for k in range(i+1, N-1):
        if time < S[k]:
            time = S[k] + C[k]
        else:
            time += (S[k] - time) % F[k]
            time += C[k]
    ans_list[i] = time

for i in range(N):
    print(ans_list[i])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  l=[LI() for _ in range(n-1)]

  for i in range(n-1):
    t=0
    for x in l[i:]:
      c,s,f=x
      if t<=s:
        t=s
      else:
        _t=t-s
        if _t%f==0:
          pass
        else:
          t+=f-(_t%f)
      t+=c
    print(t)
  print(0)

main()
# print(main())

Submission status: Accepted

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

for s in range(N):
    time=0
    for e in range(s,N-1):
        C,S,F=CSF[e]
        if time>S:
            a=(time-S)%F
            if a:
                time+=F-a
            time+=C
        else:
            time=S+C
    print(time)