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 = 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, raw_input().split())

for i in range(N):
  t = 0
  for j in range(i, N-1):
    t = max(t, S[j])
    t = (t+F[j]-1)/F[j]*F[j]+C[j]
  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 i in range(N-1):
    now = S[i]
    for j in range(i,N-1):
        if now < S[j]:
            now = S[j]
        elif now % F[j] != 0:
            now += F[j] - (now % F[j])
        else:
            pass
        now += C[j]
    print(now)
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 = S[i] + C[i]
    for j in range(i + 1, N - 1):
        if S[j] >= T:
            T = S[j] + C[j]
        else:
            tmp = S[j]
            while tmp < T:
                tmp += F[j]
            T = tmp + C[j]
    print(T)
print(0)

Submission status: Accepted

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

result = []
for i in range(n-1):
    t = e[i][0] + e[i][1]
    for x in e[i+1:]:
        if t <= x[1]:
            t = x[0] + x[1]
            continue
        t = math.ceil((t-x[1])/x[2])*x[2] + x[1] + x[0]
    result .append(t)

result.append(0)
for x in result:
    print(x)

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = []
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]
        elif t % csf[j][2] == 0: pass
        else: t += csf[j][2] - (t%csf[j][2])
        t += csf[j][0]
    ans.append(t)
ans.append(0)
for a in ans: print(a)

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    A = [0 for _ in range(N)]
    for i in range(N-1):
        C, S, F = map(int, input().split())
        for j in range(i+1):
            a = A[j]
            if a <= S:
                A[j] += C + (S - a)
            elif a % F == 0:
                A[j] += C
            else:
                A[j] += C + F - (a % F)
    for a in A:
        print(a)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
N = int(input())
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-1):
    C[i], S[i], F[i] = map(int, input().split())
for i in range(N):
    x = S[i] + C[i]
    for j in range(i+1,N-1):
        if x < S[j]:
            x = S[j] + C[j]
        else:
            x = S[j] + F[j] * math.ceil((x - S[j]) / F[j]) + C[j]
    print(x)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def calc(start, C, S, F):
    time = 0
    pos = start
    while pos < N:
        #駅posから駅pos+1に移動
        #電車を待つところから到着するまでの経過を記述
        if time == 0: #初期位置
            time += S[start] + C[start]
        else:
            if time < S[pos]:
                time = S[pos] + C[pos]
            else:
                if (time - S[pos]) % F[pos] != 0:
                    time += F[pos] - ((time - S[pos]) % F[pos]) + C[pos]
                else:
                    time += C[pos] 
        pos += 1
    return time

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

for i in range(1, N+1):
    print(str(calc(i, C, S, F)))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    C, S, F = [0]*(N-1), [0]*(N-1), [0]*(N-1)
    for i in range(N-1):
        C[i], S[i], F[i] = map(int, input().split())
    for i in range(N-1):
        cur, t = i, 0
        while cur < N-1:
            t += (F[cur] - t) % F[cur]
            t = max(t, S[cur])
            t += C[cur]
            cur += 1
        print(t)
    print(0)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
L = []
for i in range(N-1):
    L.append(list(map(int,input().split())))
for j in range(N):
    if j == N-1:
        print(0)
    else:
        t = L[j][0]+L[j][1]
        for k in range(j+1,N-1):
            if t >= L[k][1] and t%L[k][2] == 0:
                t += L[k][0]
            else:
                if t < L[k][1]:
                    t = L[k][0]+L[k][1]
                else:
                    t = t+L[k][2]-(t%L[k][2])+L[k][0]
        print(t)

Submission status: Accepted

Solution code:
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
ans = []
for i in range(len(l)):
    m = l[i][1]
    for j in range(i,len(l)):
        if m<l[j][1]:
            m = l[j][1]+l[j][0]
        elif m==l[j][1] or (m-l[j][1])%l[j][2]==0:
            m += l[j][0]
        else:
            next = l[j][2]-m%l[j][2]
            m += next+l[j][0]
    ans.append(m)
ans.append(0)
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
import sys
n  = int(input())

a = [list(map(int,input().split())) for i in range(n-1)]
su = 0 
for i in range(n):
    if i == n-1:
        print(0)
    else:
        for j in range(i,n-1):
            if su < a[j][1]:
                su = a[j][1] + a[j][0]
            elif su % a[j][2] == 0:
                su += a[j][0]
            else:
                su += a[j][2] - (su - a[j][1]) % a[j][2] + a[j][0]
        print(su)
        su = 0

Submission status: Accepted

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


def dis(i):
    if i<n-2:
        cnt=X[i][1]+X[i][0]
        while i<n-2:
                if cnt<X[i+1][1]:
                    cnt=X[i+1][1]+X[i+1][0]
                else:
                    if cnt%X[i+1][2]!=0:
                        cnt+=X[i+1][2]-(cnt%X[i+1][2])+X[i+1][0]
                    else:
                        cnt+=X[i+1][0]
                i+=1
        return cnt
    elif i==n-2:
        return X[i][1]+X[i][0]
    elif i==n-1:
        return 0
    

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def next(t, f):
    if t % f: return t + f - (t%f)
    else: return t
def time(t, i):
    if i == n-1: return t
    else:
        c, s, f = info[i]
        if t <= s: return time(s+c, i+1)
        else: return time(next(t, f)+c, i+1)
n = int(input())
info = [tuple(map(int, input().split())) for _ in range(n-1)]
for i in range(n):
    print(time(0, i))

Submission status: Accepted

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

def arrivalTime( time, loc ):
    if loc == N-1: return time
    if time <= A[loc][1]:
        return arrivalTime( A[loc][1]+A[loc][0], loc+1 )
    else:
        n = (time - A[loc][1] + (A[loc][2] - 1) ) // A[loc][2]
        return arrivalTime( A[loc][1]+A[loc][0] + n*A[loc][2], loc+1 )

for i in range(N-1):
    print( arrivalTime( A[i][1], i ) )
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):
    res = 0
    for j in range(i, n-1):
        if res < csf[j][1]:
            res += abs(csf[j][1] - res)
            res += csf[j][0]
        else:
            if (res - csf[j][1]) % csf[j][2] != 0:
                res += csf[j][2] - ((res - csf[j][1]) % csf[j][2])
            res += csf[j][0]
    print(res)

Submission status: Accepted

Solution code:
n = int(input())
index=0
timeCounterL=[0]*n
while index < n-1:
    c, s, f = map(int, input().split())
    index2=0
    while index2 < n:
        if index2 == index:
            timeCounterL[index2]+=s+c
        else:
            if index2 > index:
                break
            else:
                if timeCounterL[index2] > s:
                    amari = timeCounterL[index2]-s
                    if amari%f == 0:
                        timeCounterL[index2]+=c
                    else:
                        extraT = amari%f
                        timeCounterL[index2]+=f-extraT+c
                else:
                    timeCounterL[index2] = s+c
        index2+=1
    index+=1

for time in timeCounterL:
    print(time)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
time = [0 for _ in range(n)]

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

for t in time:
  print(t)

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

Submission status: Accepted

Solution code:
#ABC084C
N=int(input())
csf=[]
for n in range(N-1):
	csf.append(list(map(int,input().split())))
for nn in range(N):
	#print(nn)
	t=0
	for n in range(nn,N-1):
		#print(" ",n)
		if t>csf[n][1]:
			t=csf[n][1]+((t-csf[n][1]+csf[n][2]-1)//csf[n][2])*csf[n][2]+csf[n][0]
			#t=S+((t-S+F-1)//F)*F+C
		else:
			t=csf[n][1]+csf[n][0]
		#print(" ",t)
	print(t)

Submission status: Accepted

Solution code:
n=int(input());y=[list(map(int,input().split())) for i in range(n-1)]
for s in range(n):
  x=0
  for k,g in enumerate(y[s:]):
    a,b,c=g[0],g[1],g[2]
    if k==0:x=b+a
    elif x>b:
      if (x-b)%c==0:x=x+a
      else:x=(x//c+1)*c+a
    elif x<b:x=b+a
  print(x)

Submission status: Accepted

Solution code:
n=int(input())
y=[list(map(int,input().split())) for i in range(n-1)]
for s in range(n):
  x=0
  for k,g in enumerate(y[s:]):
    a,b,c=g[0],g[1],g[2]
    if k==0:
      x=b+a
    elif x>b:
      if (x-b)%c==0:
        x=x+a
      else:
        x=(x//c+1)*c+a
    elif x<b:
      x=b+a
  print(x)

Submission status: Accepted

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 = ans[j]//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)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(N):
  t = 0
  for j in range(i,N-1):
    if(t < CSF[j][1]):
      t = CSF[j][1]
    elif(t%CSF[j][2] == 0):
      pass
    else:
      t += CSF[j][2] - t%CSF[j][2]
    t += CSF[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)

# ci : i -> i+1
# fi : frequency of departure from i-th station
# si : first train time. sec from start.
res = []

for i in range(N-1):
    total = S[i] + C[i]
    for j in range(i+1, N-1):
        if total < S[j]:
            total = S[j] + C[j]
        elif (total - S[j]) % F[j] == 0:
            total += C[j]
        else:
            total += F[j] - (total % F[j])
            total += C[j]
    res.append(total)

res.append(0)

print("\n".join([str(e) for e in res]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://abc084.contest.atcoder.jp/tasks/abc084_c

def main():
    N = int(input())
    # C: 所要時間、S: 始発の時間、F: 発射間隔
    CSFs = [list(map(int, input().split())) for _ in range(N-1)]
    C = [CSF[0] for CSF in CSFs]
    S = [CSF[1] for CSF in CSFs]
    F = [CSF[2] for CSF in CSFs]

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


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):
    t = 0
    pos = i
    while True:
        if pos == N-1:
            print(t);break
        if t<s[pos]: t = s[pos]
        if t%f[pos]==0:
            t += c[pos]
            pos += 1
        else:
            t = (t//f[pos]+1)*f[pos]

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def calculate(i):
  time=ls[i][1]+ls[i][0]
  for j in range(i+1,len(ls)):
    if time<ls[j][1]:
      time=ls[j][1]+ls[j][0]
    elif time %ls[j][2]==0:
      time+=ls[j][0]
    else:
      time+=ls[j][0]+ls[j][2]-time%ls[j][2]
  return time

for i in range(len(ls)):
  ans.append(calculate(i))
ans.append(0)
for i in ans:
  print(i)

Submission status: Accepted

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

def calculate(i):
  time=ls[i][1]+ls[i][0]
  for j in range(i+1,len(ls)):
    if time<ls[j][1]:
      time=ls[j][1]+ls[j][0]
    else:
      additional_time=ls[j][2]
      while time %additional_time!=0:
        time+=1
      time+=ls[j][0]
  return time

for i in range(len(ls)):
  ans.append(calculate(i))
ans.append(0)
for i in ans:
  print(i)

Submission status: Accepted

Solution code:
import math
csf=[map(int,input().split()) for i in range(int(input())-1)]
ans=[0]
for c,s,f in csf:
    ans=[math.ceil(max(0,x-s)/f)*f+s+c for x in ans]+[0]
[print(x) for x in ans]

Submission status: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
trains = [ [int(j) for j in input().split()] for _ in range(N-1)] 


for i in range(0,N):
    ans_i = 0
    for j in range(i, N-1):
        c,s,f = trains[j]
        ans_i = max(ans_i, s)
        if not ans_i % f == 0:
            ans_i += f - ans_i%f
        ans_i += c

        # ans_i += c + (f - ans_i%f)%f 
    print(ans_i)

exit(0)

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
trains = [ [int(j) for j in input().split()] for _ in range(N-1)] + [(0,0,0)]


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

exit(0)


dp = [float("inf") for _ in range(N-1)] + [0] # N-1

t = trains[N-2]
dp[N-2] = t[0]+t[1]
limited_by = [0 for _ in range(N)]
limited_by[N-2] = t[1]

for i in range(N-3, -1, -1):
    c,s,f = trains[i]
    nc,ns,nf = trains[i+1]
    arrive_at = c+s # start with A : B # at next station

    if arrive_at < limited_by[i+1]:
        dp[i] = dp[i+1]
        limited_by[i] = limited_by[i+1] -c 

    else:
        dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - ns
        limited_by[i] = s

for i in range(N): print(dp[i])
# print(limited_by)



# print(dp)
# 
# 
# for i in range(N-3, -1, -1):
#     c,s,f = trains[i]
#     nc,ns,nf = trains[i+1]
#     arrive_at = c+s
#     # print("i: ", i, "c,s,f: ", c,s,f, end=" ")
#     # print("arrive_at: ", arrive_at, end=" ")
#     # print(" arrive_at<ns: ", arrive_at < ns)
# 
#     if arrive_at < ns:
#         dp[i] = dp[i+1]
#         limited_by[i] = ns - c
#     elif arrive_at < limited_by[i+1]:
#         dp[i] = dp[i+1]
#         limited_by[i] = limited_by[i+1] - c
#     else:
#         # print("arrive_at: ", arrive_at, "f: ", f, "dp[i+1] : ", dp[i+1], "ns: ", ns)
#         dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - ns
#

Submission status: Accepted

Solution code:
N=int(input())
C=[]
S=[]
F=[]
from math import ceil
for _ in range(N-1):
    c,s,f=map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
ans=[]
for i in range(0,N-1):
    t=S[i]+C[i]
    sta=i+1
    while sta<N-1:
        if t<=S[sta]:
            t=S[sta]+C[sta]
        else:
            k=ceil((t-S[sta])/F[sta])
            t=S[sta]+k*F[sta]+C[sta]
        sta+=1
    ans.append(t)
for a in ans:
    print(a)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
a = [list(map(int, input().split())) for _ in range(n-1)]
*a, = zip(*a)
c, s, f = a[0], a[1], a[2]

for l in range(n):
    t = 0
    for k in range(n-1-l):
        t = s[l+k]+(max(0, t-s[l+k])+f[l+k]-1)//f[l+k]*f[l+k]+c[l+k]
    print(t)

Submission status: Accepted

Solution code:
import math


def solve(N, CSFs):
    ans = []
    for k in range(0, len(CSFs)):
        t = 0
        for c, s, f in CSFs[k:]:
            if t < s:
                t = s
                t += c
            else:
                t = f * math.ceil(t / f)
                t += c
        ans.append(t)
    ans.append(0)
    return "\n".join([str(t) for t in ans])

if __name__ == "__main__":
    N = int(input())
    CSFs = [tuple(map(int, input().split(" "))) for _ in range(N - 1)]
    print(solve(N, CSFs))

Submission status: Accepted

Solution code:
# encoding:utf-8

import copy
import numpy as np
import random

N = int(input())
n = N
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)

answer = []
for i in range(n-1):
    to_goal = C[i] + S[i]
    for j in range(i+1,n-1):
        if to_goal >= S[j]:
            if to_goal % F[j] == 0:
                to_goal += C[j]
            else:
                to_goal = ((to_goal//F[j])+1)*F[j]+C[j]
        elif to_goal < S[j]:
            to_goal = S[j]+C[j]

    answer.append(to_goal)


answer.append(0)
for i in range(len(answer)):
    print(answer[i])

Submission status: Accepted

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

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

Submission status: Accepted

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

#d = {}
#d[0] = 0
#d[1] = t

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

   #d[i+1] = t

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n = int(input())
    cs = []
    ss = []
    fs = []
    for i in range(n - 1):
        c, s, f = map(int, input().split())
        cs.append(c)
        ss.append(s)
        fs.append(f)

    for i in range(n):
        t = 0
        for j in range(i, n - 1):
            t = cs[j] + next_depart(ss[j], fs[j], t)
        print(t)

def next_depart(s, f, now):
    mi = max(s, now)
    for t in range(mi, mi + f):
        if t % f == 0:
            return t
    raise Exception

main()

Submission status: Accepted

Solution code:
import math
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 j in range(N-1):
    t = 0
    for i in range(j, N-1):
        if S[i] >= t:
            t = S[i] + C[i]
        else:
            n = math.ceil((t-S[i])/F[i])
            t = S[i] + n*F[i] + C[i]
    print(t)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n-1)]

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

Submission status: Accepted

Solution code:
N = int(input())
info = [list(map(int,input().split())) for i in range(N-1)]
for i in range(N-1):
    t = 0
    for c,s,f in info[i:]:
        # 開通式の待ち時間
        if t <= s:
            wait = s - t
            t += wait
        else:
            pass_time = t - s
            if pass_time % f == 0:
                wait = 0
            else:
                pass_time %= f
                wait = f - pass_time
            t += wait
        # 通行時間
        t += c
    print(t)
print(0)

Submission status: Accepted

Solution code:
import math

n = int(input())
c, s, f = [], [], []
for _ 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 - 1):
    t = 0
    for j in range(i, n - 1):
        t = s[j] + f[j] * max(0, math.ceil((t - s[j]) / f[j])) + c[j]
    print(t)

print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Ans = []
for i in range(N):
    t = 0
    for j in range(i,N-1):
        (c,s,f) = CSF[j]
        if t <= s:
            t = s+c
        else:
            t = s+((t-s-1)//f+1)*f+c
    Ans.append(t)

for ans in Ans:
    print(ans)

Submission status: Accepted

Solution code:
# ABC 084
# 基本
import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def getIntFromRows(n): return [int(input()) for i in range(n)]
def getIntMat(n):
    mat = []
    for i in range(n): mat.append(getIntList())
    return mat

def zeros(n): return [0 for i in range(n)]
def zeros2(n, m): return [[0 for i in range(m)] for j in range(n)]
N1097 = 10**9 + 7 
debug = True
def db(x): 
    if debug: print(x)

debug = False
n = getInt()
c, s, f = zeros(n-1), zeros(n-1), zeros(n-1)
for i in range(n-1):
    c[i], s[i], f[i] = getIntList()
db((c,s,f))
for i in range(n-1):
    arriv = 0
    dept = s[i]
    for j in range(i+1, n-1):
        arriv = dept + c[j-1]
        dept = (max(arriv, s[j])+f[j]-1) // f[j] * f[j]
        db((arriv, dept))
    arriv = dept + c[n-2]
    print(arriv)
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):
        if ans >= CSF[j][1]:
            ans = -(-ans//CSF[j][2]*CSF[j][2]) + CSF[j][0]
        else:
            ans = CSF[j][1] + CSF[j][0]
    print(ans)

Submission status: Accepted

Solution code:
import math
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)
j = 0
for j in range(N-1):
    ans = C[j]+S[j]
    k = j+1
    l = 0
    for l in range(N-j-2):
        if ans <= S[k+l]:
            ans+=C[k+l]+(S[k+l]-ans)
        else:
            b=math.ceil((ans-S[k+l])/F[k+l])
            ans+=C[k+l]+(S[k+l]+F[k+l]*b-ans)
    print(ans)
print(0)

Submission status: Accepted

Solution code:
from sys import stderr, setrecursionlimit
from math import ceil
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getInt()
ans = []
for i in range(n-1):
    c, s, f = getInts()
    ans.append(c + s)
    for j in range(i):
        # ans[j]にはj駅からi駅にたどり着くまでの最短時間が入っている
        if ans[j] <= s:
            # 最初の出発時間より速く到達できれば律速はi駅の最初の出発時間になる
            ans[j] = ans[i]
        else:
            # 最初の電車に乗れなかった場合，(ans[j]より大きい最小のfの倍数)時間まで待つ必要がある(さらに電車に乗る時間cを加える)
            # min({x | x % f == 0, x > ans[j]})
            ans[j] = ceil(ans[j]/f) * f + c
    debug(ans)

print(*ans, sep='\n')
print(0)