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

Solution (Python):
station_num = int(input())

if station_num == 1:
    print(0)
else:
    station_list = [[0, 0, 0] for i in range(station_num)]
    
    for i in range(station_num - 1):
        station_list[i] = input().split()
    
    
    for i in range(station_num):
        count = int(station_list[i][0]) + int(station_list[i][1])
        now_position = i + 1
        while True:
            if now_position == station_num - 1 or now_position == station_num:
                print(count)
                break
            else:
                while True:
                    if count < int(station_list[now_position][1]):
                        count = int(station_list[now_position][1])
                    elif count % int(station_list[now_position][2]) == 0:
                        count += int(station_list[now_position][0])
                        now_position += 1
                        break
                    else:
                        count = count + int(station_list[now_position][2]) - (count % int(station_list[now_position][2]))

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

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

    print ans

Solution (Python):
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 func(n):
    t=0
    for i in range(n,N-1):
        if t < S[i]:
            t = S[i]
        else:
            if t%F[i]!=0:
                t += F[i] - (t % F[i])
        t += C[i]
    return t

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

Solution (Python):
N = int(raw_input())
CSF = [map(int, 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):
        s, t, u = CSF[j][0], CSF[j][1], CSF[j][2]
        if t < ans:
            n = (ans - t) / u if ((ans - t) % u) == 0 else (ans - t) / u + 1
            ans = s + t + u * n
        else:
            ans = s + t

    print ans

print 0

Solution (Python):
N = int(input())
C = []
S = []
F = []
T = [0 for i in range(N)]

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

for t in T:
    print(t)

Solution (Python):
N = int(input())
C = []
S = []
F = []
T = [0 for i in range(N)]

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

for t in T:
    print(t)

Solution (Python):
import numpy as np
import pdb

def main():
    N = int(raw_input())
    Cs = np.zeros(N-1).astype(int)
    Ss = np.zeros(N-1).astype(int)
    Fs = np.zeros(N-1).astype(int)

    for k in range(N-1):
        CSF = np.array(raw_input().split(' ')).astype(int)
        Cs[k] = CSF[0]
        Ss[k] = CSF[1]
        Fs[k] = CSF[2]

    schedule = train(Cs, Ss, Fs)
    for m in range(len(schedule)):
        print schedule[m]

def train(Cs, Ss, Fs):
    N = len(Cs)
    finaltimes = np.zeros(len(Cs) + 1).astype(int)
    arrivaltimes = 0
    destination = N - 1
    for k in range(N):
        currentloc = k
        arrivaltimes = Ss[k]
        for j in range(k, N):
            bestarrivaltimes = np.max([arrivaltimes, Ss[j]])
            arrivaltimes = np.ceil(bestarrivaltimes/ Fs[j]) * Fs[j] + Cs[j]
        finaltimes[k] = int(arrivaltimes)

    return finaltimes



if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())

c = []
s = []
f = []
for i in range(N-1):
    l = list(map(int, input().split()))
    c.append(l[0])
    s.append(l[1])
    f.append(l[2])

ans = []
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]
    ans.append(t)

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

Solution (Python):
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):
        c, s, f = csf[j]
        if t < s:
            t = s
        elif t % f == 0:
            t = t
        else:
            t = (t + f) - (t % f)
        t += c

    print(t)

Solution (Python):
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 calc_time(i,t):
	global C,S,F

	res = 0
	if t < S[i]:
		res = S[i]
	elif t % F[i] == 0:
		res = t
	else:
		res = (t + F[i]) - (t % F[i])
	res += C[i]

	return res

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

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

Solution (Python):
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: 
		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])

Solution (Python):

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

Solution (Python):
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)

Solution (Python):





import sys



def solve(data, i, t):
  if i == N: return t
  (c, s, f) = data[i - 1]
  
  
  
  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))

Solution (Python):
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)

Solution (Python):


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)

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


for i in range(N-1):
    
    TIME = C_S_F[i][0] + C_S_F[i][1]
    for j in range(i,N-2):
       
        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)

Solution (Python):
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))

Solution (Python):
n = int(input())

def over(start, i):
    
    
    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)

Solution (Python):
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])

Solution (Python):
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  
    for cs in xrange(i, N-1):
      
      c, s, f = CSF[cs]
      if ct < s:
        ct = s
      elif ct % f:
        ct += f - ct % f
      ct += c
      
    print(ct)

main()

Solution (Python):
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()

Solution (Python):
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)

Solution (Python):
def c_SpecialTrains(N, STATION):
    ans = []
    for i in range(N):
        t = 0  
        for j in range(i, N - 1):
            c, s, f = STATION[j]
            if t < s:
                t = s  
            elif t % f == 0:
                
                
                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))

Solution (Python):
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))

Solution (Python):
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)

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
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]

        if t < s:
            t = s
        elif t%f == 0:
            pass
        else:
            t = f * (t//f+1)
        t += c
        
    print(t)

Solution (Python):

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)

Solution (Python):
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)


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

Solution (Python):
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()

Solution (Python):
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))

Solution (Python):

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+=c
			else:
				val=f*((val/f)+1)
				val+=c

	print val
print 0

Solution (Python):
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

Solution (Python):
import math

N = int(input())
C = list()
S = list()
F = list()
A = 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)



for i in range(N-2): 
    A[i] = S[i]
    for j in range(i+1,N-1): 
        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]) 
print(0)

Solution (Python):
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): 
  t=0
  for j in range(i,N-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)

Solution (Python):

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)

Solution (Python):
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:
        
        return s + c
    elif t % f == 0:
        
        return t + c
    else:
        
        return t + (f - t % f) + c
        
        
        
        ((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()

Solution (Python):
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]

Solution (Python):

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

Solution (Python):
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)

Solution (Python):
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

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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())

Solution (Python):



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
    

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

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

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
n = int(input())
cc = []
ss = []
ff = []
for i in range(n-1):
    c, s, f = list(map(int, input().split()))
    cc.append(c)
    ss.append(s)
    ff.append(f)
for l in range(n-1):
    ans = ss[l]+cc[l]
    for k in range(l+1, n-1):
        temp = ss[k]
        while temp < ans:
            temp += ff[k]
        ans = temp + cc[k]
    print(ans)
print(0)

Solution (Python):
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): 
    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)

Solution (Python):

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)

Solution (Python):
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)

Solution (Python):
N = int(input())						

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





ans=[0]*(N+1)






def nextArrive(n, iArrive, C,S,F):
	iAns = 0
	if iArrive < S[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]
		
	
	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








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

Solution (Python):
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])

Solution (Python):
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)
print(0)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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')