Problem:


Score : 300 points

Problem Statement

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

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

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

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

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

Here, it is guaranteed that F_i divides S_i.

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

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

Constraints

1≤N≤500

1≤C_i≤100

1≤S_i≤10^5

1≤F_i≤10

S_i％F_i=0

All input values are integers.

Input

Input is given from Standard Input in the following format:

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

Output

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

Sample Input 1

3
6 5 1
1 10 1

Sample Output 1

12
11
0

We will travel from Station 1 as follows:

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

11 seconds: arrive at Station 2.

11 seconds: take the train to Station 3.

12 seconds: arrive at Station 3.

We will travel from Station 2 as follows:

10 seconds: take the train to Station 3.

11 seconds: arrive at Station 3.

Note that we should print 0 for Station 3.

Sample Input 2

4
12 24 6
52 16 4
99 2 2

Sample Output 2

187
167
101
0

Sample Input 3

4
12 13 1
44 17 17
66 4096 64

Sample Output 3

4162
4162
4162
0



Sample input:
3
6 5 1
1 10 1


Sample output:
12
11
0

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n-1): #出発する駅のインデックス
    total_time = a[i][1] + a[i][0]
    current_time = total_time
    for j in range(i+1,n-1): #通過駅
        if current_time <= a[j][1]:
            total_time = a[j][1] 
            total_time += a[j][0]
            current_time = a[j][1] + a[j][0]
        else:
            for i in range(a[j][2]):
                if (current_time+i)%a[j][2] == 0:
                    current_time += i
                    current_time += a[j][0]
                    total_time += i + a[j][0]
                    break
    print(total_time)

print(0) #最後の駅にいるとき

Submission status: Accepted

Solution code:
def solve_impl(ini, T):
    t = 0
    for Ci, Si, Fi in T[ini:]:
        # wait until start
        if t < Si:
            t = Si
        elif t % Fi != 0:
            t = t + Fi - t % Fi
        t += Ci
    return t


def solve():
    N = int(input())
    T = [ [int(n) for n in input().split()] for _ in range(N-1) ]

    for i in range(N):
        print(solve_impl(i,T))

    return 0


def main():
    ans = solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())

ans = [0] * (N-1)
CSF = [[int(i) for i in input().split()] for i in range(N-1)]

for i in range(N-1):
    now = 0
    for tranit_time, start, interval in CSF[i:]:
        if now <= start:
            now = start
            now += tranit_time
        else:
            if (now - start) % interval == 0:
                now += tranit_time
            else:
                now += interval - ((now - start) % interval)
                now += tranit_time
    ans[i] = now

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

Submission status: Accepted

Solution code:
n = int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    tmp = list(int(i) for i in input().split())
    c.append(tmp[0])
    s.append(tmp[1])
    f.append(tmp[2])

for i in range(n-1):
    time_sum = 0
    for j in range(i,n-1):
        if time_sum < s[j]:
            time_sum = s[j]
        elif time_sum%f[j]!=0:
            time_sum += f[j]-time_sum%f[j]
        time_sum += c[j]
    print(time_sum)
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 j in range(i, n - 1):
        ans = -(-1 *max(ans, csf[j][1]) // csf[j][2]) * csf[j][2] + csf[j][0]
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
res = [0] * N
for i in range(N - 1):
    C, S, F = map(int, raw_input().split())
    for j in range(i + 1):
        res[j] = max(S, res[j] if res[j] % F == 0 else res[j] - res[j] % F + F)
        res[j] += C
for t in res:
    print t

Submission status: Accepted

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

Submission status: Accepted

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


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

print('0')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def main():
    N = int(input())
    C = []
    S = []
    F = []
    for i in range(N - 1):
        sa = input().split(' ')
        C.append(int(sa[0]))
        S.append(int(sa[1]))
        F.append(int(sa[2]))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def abc084_c():
    from math import ceil
    n = int(input())
    c = [0] * (n - 1)
    s = [0] * (n - 1)
    f = [0] * (n - 1)
    for i in range(n - 1):
        c[i], s[i], f[i] = map(int, input().split())

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


abc084_c()

Submission status: Accepted

Solution code:
N = int(input())

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

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

	print(x)

Submission status: Accepted

Solution code:
# import pdb
N = int(input())

CSF = [input() for i in range(N-1)]
ans_r = []
# pdb.set_trace()
for i in range(N-1)[::-1]:
    C, S, F = map(int, CSF[i].split(' '))
    cost = S + C
    for j in range(i+1, N-1):
        Cj, Sj, Fj = map(int, CSF[j].split(' '))
        if cost <= Sj:
            cost = ans_r[(N-1) - j - 1]
            break
        else:
            temp = (cost+Fj-1)//Fj * Fj
            cost = temp + Cj
    ans_r.append(cost)
for i in ans_r[::-1]:
    print(i)
print(0)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    table = [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):
            c, s, f = table[j]
            if t <= s:
                t = s + c
            else:
                if t % f != 0:
                    t += f - (t % f)
                t += c
        print(t)
    print(0)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
c=[]
s=[]
f=[]
t=0
for i in range(n-1):
    a1,a2,a3=(list)(map(int,input().split()))
    c.append(a1)
    s.append(a2)
    f.append(a3)
time=[]
time.append(t)
for j in range(0,n-1):
    t=0
    for i in range(j,n-1):
        if i==j:
            t=s[i]+c[i]
        elif s[i]>=t:
            t=s[i]+c[i]
        elif (t-s[i])%f[i]==0:
            t=c[i]+t
        else:
            t=f[i]-(t-s[i])%f[i]+c[i]+t
    time.append(t)
    

time.sort(reverse=True)
for i in range(n):
    print(time[i])

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

Submission status: Accepted

Solution code:
import sys
import math

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

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


def f(idx, t):
    depT = -1
    if t <= S[idx]:
        depT = S[idx]
    else:
        depT = S[idx] + F[idx] * math.ceil((t - S[idx]) / F[idx])
    return depT + C[idx]


for i in range(N - 1):
    t = 0
    for j in range(i, N - 1):
        t = f(j, t)
    print(t)

print(0)

Submission status: Accepted

Solution code:
n = (int)(input())  # num of station
cost = []  # list of costed timeto next
s = []  # list of init train time
freq = []  # list of freq of train departure
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):  # return time will cost to go from (num)station to end
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  # if init train has not departed
      time = s[j]
    elif time % freq[j]:  # if next train has not arrived
      time = wait_next(time, freq[j])
    time += cost[j]  # add time to next station
  return time


def wait_next(now, freq):  # calc time we will wait to get next train
  while(1 and False):
    if not now % freq:
      break
    now += 1
#  return now
  return (now//freq+1)*freq


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

Submission status: Accepted

Solution code:
n = (int)(input())  # num of station
cost = []  # list of costed timeto next
s = []  # list of init train time
freq = []  # list of freq of train departure
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):  # return time will cost to go from (num)station to end
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  # if init train has not departed
      time = s[j]
    elif time % freq[j]:  # if next train has not arrived
      time = wait_next(time, freq[j])
    time += cost[j]  # add time to next station
  return time


def wait_next(now, freq):  # calc time we will wait to get next train
  while(1):
    if not now % freq:
      break
    now += 1
  return now


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

Submission status: Accepted

Solution code:
n = (int)(input())
cost = []
s = []
freq = []
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):
  time = 0
  for j in range(num, n-1):
    if time < s[j]:
      #print("not staredt", time)
      time = s[j]
      #print("start", time)
    elif time % freq[j]:
      #print("wait", time)
      time = wait_next(time, freq[j])
      #print("stae", time)
    time += cost[j]
    #print("time", time)

  return time


def wait_next(now, freq):
  while(1):
    if not now % freq:
      break
    now += 1
  return now


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

Submission status: Accepted

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

for i in range(N-1):
	time = 0
	for j in range(i, N-1):
		c, s, f = C_S_F[j]
		time = max(s, time + abs(time%-f))
		time += c
	print(time)
print(0)

Submission status: Accepted

Solution code:
n=int(input())

c=[]
s=[]
f=[]

for i in range(n-1):
    p,q,r=map(int,input().split())
    c.append(p)
    s.append(q)
    f.append(r)
    
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]-ans%f[j])%f[j]+c[j]
    print(ans)
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

c = []
s = []
f = []

for i in range(n-1):
    p, q, r = map(int, input().split())
    c.append(p)
    s.append(q)
    f.append(r)

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

Submission status: Accepted

Solution code:
n = int(input())

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

for j in range(n-1):
    time = 0
    tmp = 0
    for k in range(j, n-1):
        if arr[k][1] >= time:
            time = arr[k][1] + arr[k][0]
        else:
            if time % arr[k][2] == 0:
                time = time + arr[k][0]
            else:
                time = (time // arr[k][2] + 1) * arr[k][2] + arr[k][0]   
    print(time)
print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec  2 18:15:53 2018
ABC084C
@author: maezawa
"""
import math
n = int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    ci, si, fi = list(map(int, input().split()))
    c.append(ci)
    s.append(si)
    f.append(fi)
for j in range(n-1):
    ti = s[j]+c[j]
    for i in range(j+1,n-1):
        #print(j, i, ti)
        if s[i] >= ti:
            m = 0
        else:
            m = math.ceil((ti-s[i])/f[i])
        ti = s[i]+m*f[i]+c[i]
    print(ti)
print(0)

Submission status: Accepted

Solution code:
N = int(input())
C ,S, F = ([],[],[])
for i in range(N-1):
    a, aa, aaa = (int(i) for i in input().split())
    C.append(a)
    S.append(aa)
    F.append(aaa)

def move_time(i, t):
    ride = 0
    if t > S[i]:
        if t % F[i] == 0:
            ride = t
        else:
            ride = (t//F[i] + 1) * F[i]
    else:
        ride = S[i]

    return ride + C[i]

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        t = move_time(j, t)
    print(t)

print(0)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
csf = []
for _ in range(n-1):
    c,s,f = map(int, input().split())
    csf.append((c,s,f))

for i in range(n-1):
    t = 0
    for j in range(i,n-1):
        t = max(t, csf[j][1])
        if t%csf[j][2]>0:
            t += (csf[j][2] - t%csf[j][2])
        t += csf[j][0]
    print(t)
print(0)

Submission status: Accepted

Solution code:
def nexttrain(x, c, s, f):
    return c + max(s, -(-x//f)*f)
def inpl(): return [int(i) for i in input().split()]

N = int(input())
st = 0
CSF = []
for _ in range(N-1):
    CSF.append(inpl())
for j in range(N-1):
    for i in range(N-1-j):
        c, s, f = CSF[i+j]
        st = nexttrain(st, c, s, f)
    print(st)
    st = 0
print(0)

Submission status: Accepted

Solution code:
n=int(input())
c=[]
for i in range(n-1):
    x,y,z=map(int,input().split())
    c.append((x,y,z))
for i in range(n-1):
    ans=0
    for j in range(i,n-1):
        ans=[c[j][1]+((ans-c[j][1]+c[j][2]-1)//c[j][2])*c[j][2],c[j][1]][ans<c[j][1]]
        ans+=c[j][0]
    print(ans)
ans=chk=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)


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

    print(t)

Submission status: Accepted

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

dp = [[0] * N for _ in range(N)]
for i in range(N):
    dp[i][i]=0
    for j in range(i,N-1):
        if dp[i][j] <= CSF[j][1]:
            dp[i][j+1] =CSF[j][0] + CSF[j][1]
        else:
            dp[i][j+1] = CSF[j][0] + CSF[j][2]*(1+(dp[i][j]-1)//CSF[j][2])

[print(dp[_][N-1]) for _ in range(N)]

Submission status: Accepted

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

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

Submission status: Accepted

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

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

    print(result)

print(0)

Submission status: Accepted

Solution code:
import math

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


def nextArriveTime(station, start):
    """
    print("start:{} depart:{} arrive:{}"
          .format(start,
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station],
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station] + c[i]))
    """
    # print("kf:{}".format(math.ceil((start - s[station]) / f[station]) * f[station]))
    return s[station] \
           + max(0, math.ceil((start - s[station]) / f[station])) * f[station] \
           + c[station]

for i in range(n):
    time = s[i]
    for j in range(i, n):
        time = nextArriveTime(j, time)
        # print("{}->{}:{}".format(j, j+1, nextArriveTime(j, time)))
    print(time)
print(0)

Submission status: Accepted

Solution code:
import math

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


def nextArriveTime(station, start):
    """
    print("start:{} depart:{} arrive:{}"
          .format(start,
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station],
                  s[station] + math.ceil((start - s[station]) / f[station]) * f[station] + c[i]))
    """
    # print("kf:{}".format(math.ceil((start - s[station]) / f[station]) * f[station]))
    if start >= s[station]:
        return s[station] \
               + math.ceil((start - s[station]) / f[station]) * f[station] \
               + c[station]
    else:
        return s[station] + c[station]

for i in range(n):
    time = s[i]
    for j in range(i, n):
        time = nextArriveTime(j, time)
        # print("{}->{}:{}".format(j, j+1, nextArriveTime(j, time)))
    print(time)
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

N=int(input())
C = []
S = []
F = []
for i in range(N-1):
    c,s,f = list(map(int,input().split()))
    C.append(c)
    S.append(s)
    F.append(f)
    
for i in range(N):
    time = 0
    for j in range(i,N-1):
        if time < S[j]:
            time = S[j]+C[j]
        else:
            itime=int(time/F[j])
            if itime*F[j]!=time:
                time=(itime+1)*F[j]+C[j]
            else:
                time+=C[j]
    print(time)

Submission status: Accepted

Solution code:
N = int(input())
s = []
for i in range(N-1):
    C,S,F = map(int,input().split(" "))
    s.append([C,S,F])
for i in range(N):
    if i == N-1:
        print(0)
    else:
        time = 0
        for j in range(i,N-1):
            C,S,F = s[j]
            if time < S:
                time = S + C
            else:
                if (time-S)%F == 0:
                    time += C
                else:
                    time += (F - (time-S)%F)
                    time += C
        print(time)

Submission status: Accepted

Solution code:
n=int(input())
s=[0]*n
l=[list(map(int,input().split())) for i in range(n-1)]
#print(l)
for i in range(n-1):
    s[i]=l[i][0]+l[i][1]
    #print(s)
    for j in range(i):
        if s[j]<=l[i][1]:
            s[j]=s[i]
        else:
            if s[j]%l[i][2]==0:
                s[j]=l[i][0]+l[i][2]*(s[j]//l[i][2])
            else:
                s[j]=l[i][0]+l[i][2]*(s[j]//l[i][2]+1)
for i in range(n):
    print(s[i])

Submission status: Accepted

Solution code:
def ans(station,start):
    global c
    global s
    global f
    global n

    if(station==n-1):
        return start
    if(start<=s[station]):
        return ans(station+1,s[station]+c[station])
    else:
        if(start%f[station]==0):
            return ans(station+1,start+c[station])
        else:
            return ans(station+1,start + (f[station] - start%f[station]) + c[station])





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):
    print(ans(i,0))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n - 1):#h:高さ
    a.append([int(m) for m in input().split()])

cp = 0
for i in range(n):
    if i == n - 1:
        print(0)
    else:
        for j in range(i, n - 1):
            if cp == 0:
                k = a[j][1] + a[j][0]
            else:
                if k < a[j][1]:
                    k = a[j][1]
                    k += a[j][0]
                else:
                    if (k - a[j][1]) % a[j][2] == 0:
                        r = 0
                    else:
                        r = a[j][2] - (k - a[j][1]) % a[j][2]
                    k += a[j][0]
                    k += r
            cp = 1
        print(k)
        cp = 0

Submission status: Accepted

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

t[N-1]=0
t[N-2]=s[N-2]+c[N-2]
for i in range(N-3,-1,-1):
#    print(N-i-1)
    t[i]=c[i]+s[i]
    for j in range(i,N-2):
        if t[i]<=s[j+1]:
            t[i]=t[i+1]
            break
        else:
            if t[i]%f[j+1]!=0:
                t[i]=t[i]+(f[j+1]-t[i]%f[j+1])+c[j+1]
            else:
                t[i]=t[i]+c[j+1]
for i in range(len(t)):
    print(t[i])

Submission status: Accepted

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

times = [0] * N
for i_start in range(N - 1):
    time = 0
    for Ci, Si, Fi in CSF[i_start:]:
        # wait opening celemony
        time = max(Si, time)
        # wait train arrival
        time += Fi - (time % Fi) if time % Fi > 0 else 0
        # on the train
        time += Ci
    # record
    times[i_start] = time

for time in times: print(time)

Submission status: Accepted

Solution code:
from math import ceil
import sys
def 解():
    iN = int(sys.stdin.readline())
    aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
    #def fCeil(a):
    #   return int(-1* ( int(-1*a)))

    for i in range(iN-1):
        Tjb = aData[i][0] + aData[i][1]
        for j in range(i+1,iN-1):
            Cj = aData[j][0]
            Sj = aData[j][1]
            Fj = aData[j][2]
        #   Tjb = max( fCeil(Tjb/Fj),Sj//Fj)*Fj+Cj
            Tjb = max( ceil(Tjb/Fj),Sj//Fj)*Fj+Cj
        print(Tjb)
    print(0)
解()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        t = max(t, csf[j][1])
        if t % csf[j][2] > 0:
            t += csf[j][2] - t % csf[j][2]
        t += csf[j][0]
    print(t)
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def head(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

N = int(input())
Info = [[int(i) for i in input().split()] for j in range(N-1)]

for i in range(N):
    if i == N-1:
        print(0)
    else:
        now = 0
        for j in range(i, N-1):
            start = (Info[j][1] if now <= Info[j][1] else Info[j][1] + head(now-Info[j][1], Info[j][2]) * Info[j][2])
            now = start + Info[j][0]
        print(now)

Submission status: Accepted

Solution code:
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
  ci, si, fi=map(int, input().split())
  c.append(ci)
  s.append(si)
  f.append(fi)
for i in range(n):
  ans=0
  for j in range(i, n-1):
    if ans<s[j]:
      ans=s[j]
    ans=(ans+f[j]-1)//f[j]*f[j]+c[j]
  print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

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


for i in range(N-1):
    estime = 0
    for (c,s,f) in CSF[i:]:
        if estime < s:
            estime = c + s
        else:
            if estime%f == 0:
                estime += c
            else:
                estime += c + f - estime%f

    print(estime)

print(0)

Submission status: Accepted

Solution code:
class Station:
    def __init__(self, c, s, f):
        self.c = c
        self.s = s
        self.f = f


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

for i in range(N):
    arrive_time = 0
    for j in range(i, N-1):
        current_station = stations[j]
        next_time = current_station.c + arrive_time
        if arrive_time > current_station.s:
            next_time += (current_station.f - (arrive_time -
                                               current_station.s
                                               )) % current_station.f
        else:
            next_time += (current_station.s - arrive_time)
        arrive_time = next_time
    print(arrive_time)

Submission status: Accepted

Solution code:
#ABC084C
N=int(input())
CSF = []
ans = [0]*N
ans[N-1]=0
t=0
for i in range(N-1):
    CSF.append(list(map(int, input().split())))

for i in range(N-1):
    t=0
    for j in range(N-1):
        if j<i:
            continue
        if t<=CSF[j][1]:
            t=CSF[j][1]+CSF[j][0]
        elif (t-CSF[j][1])%CSF[j][2]==0:
            t=CSF[j][0]+CSF[j][1]+((t-CSF[j][1])//CSF[j][2])*CSF[j][2]
        else:
            t = CSF[j][0] + CSF[j][1] + ((t - CSF[j][1]) // CSF[j][2]+1) * CSF[j][2]
    ans[i]=t

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

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 j in range(N) :
    if j != N-1 :
        answer = 0
        for k in range(j,N-1) :
            if answer < S[k] :
                answer = S[k]
            if answer % F[k] != 0 :
                answer = (answer // F[k] + 1) * F[k]
            answer += C[k]
        print(answer)
    else :
        print(0)

Submission status: Accepted

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

for i in range(N):
    time=0
    for j in range(i,N-1):

        if time<CSF[j][1]:
            time=CSF[j][1]
        x=-((-time)//CSF[j][2])
        time=x*CSF[j][2]
        time+=CSF[j][0]
        #print(x,time)

    print(time)

Submission status: Accepted

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

for i in range(N-1):
    t = 0
    for c,s,f in src[i:]:
        t = max(t,s)
        t = -(-t//f)*f
        t += c
    print(t)
print(0)