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

def Time_spent(i,t):
	global C,S,F

	res = C[i]
	if t < S[i]:
		res += S[i]
	else: # if t >= S[i]
		for tt in range(t,t + F[i] + 1):
			if tt % F[i] == 0:
				res += tt
				break
	return res

ans = [[0 for i in range(N)] for _ in range(N)]
time = 0
for i in range(N-1):
	for j in range(i,N-1):
		if j == 0:
			ans[i][j] = Time_spent(j, 0)
		else:
			ans[i][j] = Time_spent(j, ans[i][j-1])

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

Submission status: Accepted

Solution code:

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

def arrive(time, i):
    times = -(-(time - S[i]) // F[i])
    ans = 0 if times < 0 else times
    return S[i] + F[i] * ans


def solve():
    N = int(input())
    for i in range(N-1):
        c,s,v = map(int, input().split())
        C.append(c)
        S.append(s)
        F.append(v)

    for start_sta in range(N):
        now = 0
        for station in range(start_sta,N-1):
            arr = arrive(now, station)
            now = arr + C[station]
        print(int(now))

solve()

Submission status: Accepted

Solution code:
N = int(input())
inputList = []
for count in range(1,N):
    C,S,F = map(int, input().split())
    tempList = [C,S,F]
    inputList.append(tempList)

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

Submission status: Accepted

Solution code:
#!/usr/bin/python

# AtCoder Beginner Contest 084
# C: Special Trains

import sys

# the time when a person at station i arrive the station N,
# with the current time t
def solve(data, i, t):
  if i == N: return t
  (c, s, f) = data[i - 1]
  # we can start here at s, s+f, s+2f, ...
  # we have to find k >= 0 such that s+(k-1)f < t <= s+kf.
  # k-1 < (t-s)/f <= k
  k = 0 if t <= s else (t - s + f - 1) // f
  return solve(data, i + 1, s + k * f + c)

N = int(sys.stdin.readline())
data = []
for i in range(N - 1):
  c, s, f = [int(w) for w in sys.stdin.readline().split()]
  data.append((c, s, f))

for i in range(N):
  print(solve(data, i + 1, 0))

Submission status: Accepted

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

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

print(0)

Submission status: Accepted

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

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(1,n):
    c[i], s[i], f[i] = list(map(int,input().split()))

for i in range(1,n):
    t = 0
    for j in range(i,n):
        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)
print(0)

Submission status: Accepted

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

for i in range(N-1):
    #print('i={0}'.format(i))
    TIME = C_S_F[i][0] + C_S_F[i][1]
    for j in range(i,N-2):
       # print('j={0}'.format(j))
        if TIME < C_S_F[j+1][1]:
            TIME = C_S_F[j+1][1]+C_S_F[j+1][0]
        else:
            if TIME%C_S_F[j+1][2] != 0:
                TIME += C_S_F[j+1][2]-TIME%C_S_F[j+1][2]+C_S_F[j+1][0]; 
            else:
                    TIME += C_S_F[j+1][0]
    print(TIME)
print(0)

Submission status: Accepted

Solution code:
n = int(input())
data = []
for i in range(n-1):
    station_data = [int(x) for x in input().split()]
    data.append(station_data)

time_list = []

for i in range(n):
    total_time = 0

    for j in range(i, n-1):
        if total_time <= data[j][1]:
            total_time = data[j][1] + data[j][0]

        elif total_time % data[j][2] == 0:
            total_time += data[j][0]

        else:
            total_time += data[j][2] - total_time % data[j][2] + data[j][0]

    time_list.append(total_time)

answer = map(str, time_list)
print("\n".join(answer))

Submission status: Accepted

Solution code:
n = int(input())

def over(start, i):
    #return the time of the first train that leaves after the start time of the ith station.
    #when f * (n-1) < start <= f * n, return f * n
    f_ = f[i]
    if start % f_ == 0:
        return start
    else:
        return f_ * ((start // f_) + 1)


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

times = []

for _ in range(n-1):
    c_, s_, f_ = [int(x) for x in input().split()]
    _ = [x.append(y) for x,y in [(c,c_),(s,s_),(f,f_)]]

for i in range(n-1):
    start = 0
    for j in range(n-1-i):
        tmp = over(start,i+j)
        if tmp < s[i+j]:
            tmp = s[i+j]
        start = tmp + c[i+j]
    times.append(start)

for x in times:
    print(x)
print(0)

Submission status: Accepted

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

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

        else:
            ans[j] = X[i][1] + X[i][0]

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

Submission status: Accepted

Solution code:
from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  N = GI()
  CSF = [GIS() for _ in xrange(N-1)]

  for i in xrange(N):
    ct = 0  # Current Time
    for cs in xrange(i, N-1):
      #print '*' * 20, 'DEPART', cs, ct
      c, s, f = CSF[cs]
      if ct < s:
        ct = s
      elif ct % f:
        ct += f - ct % f
      ct += c
      #print '*' * 20, 'ARRIVE', cs, ct
    print(ct)

main()

Submission status: Accepted

Solution code:
def main():
    n = int(raw_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):
            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
 

 
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def hoge(t, i):
	global data
	C, S, F = int(data[i][0]), int(data[i][1]), int(data[i][2])
	if S > t:
		t = S
	if t % F != 0:
		t += F - t % F
	return t + C

if __name__ == '__main__':
	N = int(input())
	data = list()

	for i in range(N - 1):
		l = input().split()
		data.append(l)

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

Submission status: Accepted

Solution code:
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  # 駅iからNまでにかかる時間
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  # まだ運行していないので、運行するまで待つ必要がある
            elif t % f == 0:
                # tがfで割り切れるなら、すぐに鉄道に乗ればよい
                # sはfで割り切れることが保証されているので、この条件式でよい
                pass
            else:
                t += f - (t % f)  # この分だけ駅で待つ必要がある
            t += c  # 次の駅までかかる時間
        ans.append(t)
    return '\n'.join(map(str, ans))

N = int(input())
STATION = [[int(i) for i in input().split()] for j in range(N-1)]
print(c_SpecialTrains(N, STATION))

Submission status: 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)

def process(i, t):
  if i == N-1:
    return t
  if t <= S[i]:
    return process(i+1, S[i]+C[i])
  elif t % F[i] == 0:
    return process(i+1, t+C[i])
  else:
    t2 = ((t//F[i])+1)*F[i]
    return process(i+1, t2+C[i])

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

Submission status: Accepted

Solution code:
from math import ceil

N = int(input())

Cs = []
Ss = []
Fs = []
for j in range(N - 1):
    C, S, F = map(int, input().split())
    Cs += [C]
    Ss += [S]
    Fs += [F]

Ts = [0] * N

for iSt in range(N - 1):
    for j in range(iSt + 1):
        if Ts[j] <= Ss[iSt]:
            Ts[j] = Ss[iSt] + Cs[iSt]
        else:
            Ts[j] = Ss[iSt] + ceil((Ts[j] - Ss[iSt]) / Fs[iSt]) * Fs[iSt] + Cs[iSt]

for T in Ts:
    print(T)

Submission status: Accepted

Solution code:
# C - Special Trains
import math

N = int(raw_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, raw_input().split())
result = [0] * N

for station in range(N):
  now = station
  time = 0
  while now != N-1:
    time = S[now] + C[now] if time <= S[now] else int(math.ceil(float(time)/float(F[now])))*F[now] + C[now]
    now += 1
  result[station] = time

for i in result: print i

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(n):
    t = 0
    for j in range(i,n-1):
        c = c_list[j]
        s = s_list[j]
        f = f_list[j]
#         print(c,s,f)
        if t < s:
            t = s
        elif t%f == 0:
            pass
        else:
            t = f * (t//f+1)
        t += c
        
    print(t)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

N = int(input())
stations = []
for _ in range(N-1):
    stations.append(inpl())

P = []

for i in range(N-1):
    C, S, F = stations[i]
    P = [C + max(S, F*(p//F + int(p%F!=0))) for p in P]
    P.append(S+C)  

for p in P:
    print(p)
print(0)

Submission status: Accepted

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

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


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


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

    for i in range(N):
        now = 0
        for j in range(i, N - 1):
            if S[j] > now:
                now += S[j] - now

            t = ceil(now / F[j])
            now += (F[j] * t) - now
            now += C[j]
        print(now)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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)


def solve(n):
    tmp = 0
    for i in range(n, N - 1):
        if tmp <= S[i]:
            tmp = S[i]
            tmp += C[i]
        else:
            tmp = ((tmp - 1) // F[i] + 1) * F[i]
            tmp += C[i]
    return tmp


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

Submission status: Accepted

Solution code:
#WA 2018-01-01 15:35:55 => Fix
N=input()
a=[tuple( map(int,raw_input().split()) ) for i in range(N-1)]
#print a
 
for i in range(N-1):
	val=0
	for c,s,f in a[i::]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val+=c
			else:
				val=f*((val/f)+1)
				val+=c

	print val
print 0

Submission status: Accepted

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

for i in range(N-1):
	val=0
	for c,s,f in a[i:]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val=f*(val/f)
			else:
				val=f*((val/f)+1)
			val+=c

	print val
print 0

Submission status: Accepted

Solution code:
import math

N = int(input())
C = list()
S = list()
F = list()
A = list()

# C,S,FについてN-1の大きさのlistを作る
for i in range(N-1):
    a, b, c = map(int, input().split())
    C.append(a)
    S.append(b)
    F.append(c)
    A.append(0)
A.append(0)

# 駅番号は0からN-1
# 駅iから出発して駅kを最初に出発する時刻を更新していく
for i in range(N-2): # 駅0から駅N-2
    A[i] = S[i]
    for j in range(i+1,N-1): # 次の駅i+1から最後から2つ手前の駅まで
        if A[j-1] + C[j-1] > S[j]:
            A[j] = F[j] * math.ceil((A[j-1]+C[j-1])/F[j])
        else:
            A[j] = S[j]
    A[N-1] = A[N-2] + C[N-2]
    print(A[N-1])    
print(S[N-2] + C[N-2]) #駅N-2
print(0) #駅N-1

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+= [c]
  S+= [s]
  F+= [f]

for i in range(N-1): #i+1駅に最初にいる
  t=0
  for j in range(i,N-1):#j+1駅にいる
    if t<=S[j]: t = S[j]
    else: t = F[j]*(t//F[j] + (t%F[j]!=0))
    t+=C[j]
  print(t)
print(0)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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())

ans = [0] * (N - 1)
for i in range(N - 1):
    for j in range(i, N - 1):
        r = ans[i] % F[j]
        ans[i] += F[j] - r if (r != 0) else 0
        ans[i] = max(ans[i], S[j])
        ans[i] += C[j]
    print(ans[i])
print(0)

Submission status: Accepted

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

    AC(N, C, S, F)


def AC(N, C, S, F):
    for i in range(N):
        t = 0
        for j in range(i, N - 1):
            t = t_func(t, C[j], S[j], F[j])

        print(t)


def t_func(t, c, s, f):
    if t < s:
        # 開通式終了前、終了待ってから次の駅(今までのtに依存しない)
        return s + c
    elif t % f == 0:
        # 開通式終了済み、ちょうど列車が発車しているか
        return t + c
    else:
        # 終了済みだが、列車待ち
        return t + (f - t % f) + c
        # t + (f - t  % f)
        # => (t // f + 1) * f
        # => t // f: 余りを気にせず商を求める
        ((t - t % f) // f + 1) * f
        (t - t % f) + f


def WA(N, C, S, F):
    # 逆順に計算して、結果の再利用
    res = [0] * N
    for i in range(1, N):
        res[i] = res[i - 1] + C[-i]
    # 後続の列車より早くない
    for i in range(1, N):
        res[i] = max(res[i - 1], res[i] + S[-i])

    for r in reversed(res):
        print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 31 12:25:16 2017

@author: kanako_note
"""

N = int(input())

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

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

for 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:
N = int(input())
clis = [];slis =[];flis = []
for i in range(N-1):
    c,s,f = map(int,input().split())
    clis.append(c);slis.append(s);flis.append(f)
for i in range(N):
    count=0
    for i2 in range(N-i-1):
        c=clis[i+i2];s=slis[i+i2];f=flis[i+i2]
        if count <= s:
            count=s+c
        elif (count-s)%f ==0:
            count = count+c
        else:
            count = count + c+f-count%f
    print(count)

Submission status: Accepted

Solution code:
import math

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

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1, N-1):
        C, S, F = CSF[j][0], CSF[j][1], CSF[j][2]
        if S < ans:
            n = math.ceil((ans - S) / F)
            ans = C + S + F * n
        else:
            ans = C + S
 
    print int(ans)

print 0

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    C = []
    S = []
    F = []
    for _ in range(N - 1):
        tmp_c, tmp_s, tmp_f = list(map(int, input().split(" ")))
        C.append(tmp_c)
        S.append(tmp_s)
        F.append(tmp_f)

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


solve()

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

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 LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = [LI() for _ in range(n-1)]
    r = []
    for i in range(n-1):
        s = a[i][0] + a[i][1]
        for j in range(i+1,n-1):
            if s <= a[j][1]:
                s = a[j][1]
            else:
                if s % a[j][2] > 0:
                    s += a[j][2] - s % a[j][2]
            s += a[j][0]
        r.append(s)
    r.append(0)

    return '\n'.join(map(str,r))

print(main())

Submission status: Accepted

Solution code:
#coding:utf-8

#A, B = map(int,raw_input().split())
N = int(raw_input())

Time = [0 for i in range(N)]
C, S, F = map(int,raw_input().split())
Time[0] += S
for i in range(1,N-1):
    Cnew, S, F = map(int,raw_input().split())
    Time[i] += S
    #print Time[i]

    for j in range(i):
        #print j
        Time[j] = Time[j] + C
        if Time[j] > S:
            #Time[j] = Time[j] + C
            #print Time[j]
            if (Time[j] - S) % F == 0:
                pass
            else:
                Amari = F - ((Time[j] - S) % F)
                Time[j] = Time[j] + Amari
        else:
            #print "hello"
            Time[j] = S
    C = Cnew

for i in range(N-1):
    Time[i] += C
    print Time[i]
print Time[N-1]

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(0, 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]
    print(t)
print(0)

Submission status: Accepted

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

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

        t += c

    print(t)

Submission status: Accepted

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

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 = 0
    for j in range(i, N-1):
        if time < S[j]:
            time = S[j]
        else:
            if time % F[j] != 0:
                time += F[j] - (time % F[j])
        time += C[j]
    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):
    AnsSec = 0
    Now_Station = i
    while Now_Station < n - 1:
        if AnsSec > csf[Now_Station][1]:
            if AnsSec % csf[Now_Station][2] != 0:
                AnsSec += csf[Now_Station][2] - (AnsSec % csf[Now_Station][2])
        else:
            AnsSec += csf[Now_Station][1] - AnsSec
        AnsSec += csf[Now_Station][0]
        Now_Station += 1
    print(AnsSec)

Submission status: Accepted

Solution code:
N = int(input())						# 5

C=[0]
S=[0]
F=[0]
for i in range(N-1):
	c, s, f = map(int, input().split())		# 5 7 2
	C.append(c)
	S.append(s)
	F.append(f)

#print("C", C)
#print("S", S)
#print("F", F)

ans=[0]*(N+1)





# n駅からn+1駅へ移動した時の到着時刻
def nextArrive(n, iArrive, C,S,F):
	iAns = 0
	if iArrive < S[n]:
		#⇒まだ
		iAns = S[n] + C[n]
		#print("A", n, iAns, S[n], C[n])
	else:
		#⇒順次運行中
		iOver = iArrive % F[n]
		if iOver == 0:
			iAns = iArrive + C[n]
		else:
			iAns = iArrive + (F[n] - iOver) + C[n]
		#print("B", n, iArrive, iWait, C[n], iAns)
	
	return iAns

iArrive=0
for i in range(1, N):
	iArrive = S[i]
	for n in range(i, N):
		iArrive = nextArrive(n, iArrive, C,S,F)

	ans[i] = iArrive






#print(ans)

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

Submission status: Accepted

Solution code:
import numpy as np
import copy

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

t = np.zeros(n, dtype=np.int)
for i in range(n-1):
    t[i] = s[i] + c[i]
    for j in range((i+1), (n-1), 1):
        if(s[j] >= t[i]):
            t[i] = s[j]
        elif(t[i] % f[j] != 0):
            t[i] += f[j] - (t[i] % f[j])
        t[i] += c[j]

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

Submission status: Accepted

Solution code:
import re
import math
num = int(input())
a = []
b = []
c = []
for i in range(num-1):
    x,y,z = map(int,input().split(" "))
    a.append(x)
    b.append(y)
    c.append(z)
for i in range(num-1):
    time = 0
    for j in range(i,num-1):
        if(time < b[j]):
            time = b[j]
        for k in range(c[j]):
            temp = time + k
            if(temp % c[j] == 0):
                time = temp
        time += a[j]
        # print(time,j)
    print(time)
print(0)

Submission status: Accepted

Solution code:
N=int(input())
data=[]
for i in range(N-1):
  tmp=input().split(' ')
  data.append(tmp)
for i in range(N-1):
  time=0
  for j in range(N-1-i):
    k=j+i
    if time<=int(data[k][1]):
      time=int(data[k][1])+int(data[k][0])
    else:
      num=time%int(data[k][2])
      if num==0:
        time=time-num+int(data[k][0])
      else:
        time=time-num+int(data[k][2])+int(data[k][0])
  print(time)
print(0)

Submission status: Accepted

Solution code:
import math
N = int(input())
grid = []
for i in range(N-1):
    array = list(map(int, input().strip().split(' ')))
    grid.append(array)
for x in range(N): 
    time = 0
    for i in range(x, N-1):
        if time <= grid[i][1]:
            time = grid[i][0] + grid[i][1]
        else :
            time = (math.ceil((time - grid[i][1])/grid[i][2]))*grid[i][2] + grid[i][1] + grid[i][0]
    print(time)

Submission status: Accepted

Solution code:
n = int(input())
table = [[0 for i in range(3)] for k in range(n-1)]
for i in range(n-1):
	c,s,f = map(int,input().split())
	table[i][0] = c
	table[i][1] = s
	table[i][2] = f
for i in range(n-1):
	total = table[i][1]+table[i][0]
	for k in range(i+1,n-1):
		if total <= table[k][1]:
			total = table[k][1] + table[k][0]
		else:
			sur = total%table[k][2]
			if sur == 0:
				total = total + table[k][0]
			else:
				total = (total - sur) + table[k][2] + table[k][0]
	print(total)
print('0')

Submission status: Accepted

Solution code:
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-1):
    t = 0
    for j in range(i, n - 1):
        if t < ss[j]:
            t = ss[j]
        else:
            if t % fs[j] != 0:
                t += fs[j] - (t % fs[j])
        t += cs[j]
    print(t)
print(0)

Submission status: Accepted

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

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

Submission status: Accepted

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

N = int(input())
CSF = []
for n in range(N-1):
    s = input()
    CSF.append([int(x) for x in s.split()])

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

Submission status: Accepted

Solution code:
from math import ceil

n = int(input())

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

buf = []
for i, (c, s, f) in enumerate(trains):
    t = s + c
    for cj, sj, fj in trains[i + 1: n]:
        if t < sj:
            t = sj
        else:
            t = ceil(t / fj) * fj
        t += cj
    buf.append(t)
buf.append(0)

print('\n'.join(map(str, buf)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8
N = 0
C = []
S = []
F = []

# i駅での到着時間を指定すると、次の乗車時間が帰ってくる
def getNextTrain(i, time):
  # t = S[i]
  if time <= S[i]:
    return S[i]
  else:
    n = time / F[i]
    m = time % F[i]
    t = F[i] * n
    if m != 0:
      t += F[i]
    # while(1):
    #   if t >= time:
    #     break
    #   t += F[i]

    return t

# 入力部分
N = int(raw_input())
for i in range(N-1):
  c, s, f = map(int, raw_input().split())
  C.append(c)
  S.append(s)
  F.append(f)

# 処理部分
for k in range(N):
  arrive = 0
  for p in range(k, N-1): 
    # p駅から出発して
    arrive = getNextTrain(p, arrive)
    #print str(arrive) + '-> ' + str(p),
    arrive += C[p]
    #print '->' + str(arrive)
  print arrive

# 出力部分

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

Submission status: Accepted

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

import math
import sys

n = int(sys.stdin.readline().strip())
f_list = []
for _ in range(n - 1):
    c, s, f = sys.stdin.readline().strip().split(" ")
    c = int(c)
    s = int(s)
    f = int(f)
    f_list = [c + math.ceil((max(_f, s)) / f) * f for _f in f_list]
    f_list.append(c + s)
f_list.append(0)
for _f in f_list:
    print(_f)

Submission status: Accepted

Solution code:
c=[]
s=[]
f=[]

N = 506

for i in range(N) :
    c.append(0)
    s.append(0)
    f.append(0)
n=int(input())
for i in range(1,n) :
    c[i],s[i],f[i] = map(int,input().split())
    
for i in range(1,n) :
    now = s[i] + c[i]
    for j in range(i+1,n) :
        if now >= s[j] :
            now = ((now + f[j] - 1)//f[j] )*f[j]
            now += c[j]
        else :
            now = s[j]
            now += c[j]
    print(now)

print(0)