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):
n=int(input())
a=[list(map(int,input().split())) for _ in range(n-1)]
ans=[]
for i in range(n):
    now=0
    for j in range(i,n-1):
        c,s,f=a[j]
        if s==now:
            k=0
        elif s>now:
            k=s-now
        else:
            if now%f!=0:
                k=f-now%f
            else:
                k=0
        now+=c+k
    print(now)

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

csf = []

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

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

print(*ans, sep="\n")

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

def time(m):
    c, s, f = csf[m-1]
    depart_next = s
    arrive_next = s+c
    while m < n-1:
        nc, ns, nf = csf[m]
        i = 0
        while ns + nf*i < arrive_next:
            i += 1
        depart_next = ns + nf*i
        arrive_next = depart_next + nc
        m += 1
    return arrive_next


for i in range(1, n):
    print(time(i))
print(0)

Solution (Python):
n=int(input())
csf=[list(map(int,input().split())) for _ in range(n-1)]
ans=[float("inf") for _ in range(n)]
ans[n-1]=0
for i in range(n-1):
  cnt=csf[i][1]+csf[i][0]
  for j in range(i+1,n-1):
    if csf[j][2]<cnt:
      if cnt%csf[j][2]==0:
        cnt+=csf[j][0]
      else:
        cnt+=csf[j][0]+csf[j][2]-cnt%csf[j][2]
    else:
      cnt+=cnt-csf[j][2]
  ans[i]=cnt
ans=ans[::-1]
for i in range(n-1):
  if ans[i]>ans[i+1]:
    ans[i+1]=ans[i]
for i in ans[::-1]:
  print(i)

Solution (Python):
n=int(input())
csf=[list(map(int,input().split())) for _ in range(n-1)]
ans=[float("inf") for _ in range(n)]
ans[n-1]=0
for i in range(n-1):
  cnt=csf[i][1]+csf[i][0]
  for j in range(i+1,n-1):
    if csf[j][2]<cnt:
      if cnt%csf[j][2]==0:
        cnt+=csf[j][0]
      else:
        cnt+=csf[j][0]+csf[j][2]-cnt%csf[j][2]
    else:
      cnt+=cnt-csf[j][2]
  ans[i]=cnt
ans=ans[::-1]
ans.append(float("inf"))
for i in range(n):
  if ans[i]>ans[i+1]:
    ans[i+1]=ans[i]
ans.pop(-1)
for i in ans[::-1]:
  print(i)

Solution (Python):
import math
N = int(input())
list_time = []
for i in range(N- 1):
  list_time.append(tuple(map(int, input().split())))
  
"""
駅iを時刻tに発ったとき，駅i+1に到着するのはt+ list_time[i- 1][0]
駅i+1を発つのはt+ list_time[i- 1][0]<= list_time[i][1]+ k* list_time[i][2] となる最小の
k，すなわち
k = max(0, math.ceil((t+ list_time[i- 1][0]- list_time[i][1])/ list_time[i][2]))
について時刻list_time[i][1]+ k* list_time[i][2]
"""

def lastdeparturetime(i, t):
  if(i == N- 1):
    return t
  else:
    k = max(0, math.ceil((t+ list_time[i- 1][0]- list_time[i][1])/ list_time[i][2]))
    T = list_time[i][1]+ k* list_time[i][2]
    return lastdeparturetime(i+ 1, T)
  
for i in range(1, N):
  arrivaltime = lastdeparturetime(i, list_time[i- 1][1])+ list_time[N- 2][0]
  print(arrivaltime)
  
print(0)

Solution (Python):
N = int(input())
A = list()
for i in range(N-1):
  A.append(list(map(int, input().split())))
for i in range(N):
  ans = 0
  j = i
  while(j < N-1):
    C = A[j][0]
    S = A[j][1]
    F = A[j][2]
    
    if(S > ans):
      ans = S
    else:
      if(ans % F != 0):
        ans = ((ans//F)+1)*F
    ans += C
    j += 1
    
  print(ans)

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

def to_next(start_time, sta):
    
    time = 0
    if dia[sta][1] > start_time:
        time += dia[sta][1] - start_time
    elif start_time % dia[sta][2] != 0:
        time += dia[sta][2] * (start_time // dia[sta][2] + 1) - start_time
    time += dia[sta][0]
    return time

def to_end(sta):
    time = 0
    while sta != N-1:
        time += to_next(time, sta)
        sta += 1
    return time
for i in range(N - 1):
    print(to_end(i))
print(0)

Solution (Python):
import sys
input = sys.stdin.readline
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())

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

for i in ans:
    print(i)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    timeschedule = [na() for _ in range(n - 1)]

    for i in range(n):
        time = 0

        for j in range(i, n - 1):
            c, s, f = timeschedule[j]
            if time < s:
                time = s
            if (time - s) % f:
                time += f - ((time - s) % f)
            time += c

        print(time)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

from functools import lru_cache
@lru_cache(None)
def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    if t <= ss:
        return dfs(eki+1, ss+cc)
    else:
        m = -(-t//ff)
        return dfs(eki+1, ff*m+cc)

for i in range(n):
    print(dfs(i,0))

Solution (Python):
def calc_time_to_next_station(t, c, s, i):
  if t <= s:
    return s + c
  else:
    f = lambda x, y: (x + y - 1) // y
    return f(t-s, i) * i + s + c  


def calc_needed_time(i, cost, start, interval):
  """
  calculate the needed time to reach n-th station when we are at i-th station 
  Args:
    i (int): 0-indexed number
    cost (list)
    start (list)
    interval (list)
  """
  if i == n - 1:
    return 0
  m = len(start)
  t = 0
  for j in range(i, m):
    t = calc_time_to_next_station(t, cost[j], start[j], interval[j])
  return t
 



n = int(input())
cost, start, interval = [], [], []
for _ in range(n-1):
  c, s, i = map(int, input().split())
  cost.append(c)
  start.append(s)
  interval.append(i)


for i in range(n):
  print(calc_needed_time(i, cost, start, interval))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    if t <= ss:
        return dfs(eki+1, ss+cc)
    else:
        m = -(-t//ff)
        return dfs(eki+1, ff*m+cc)

for i in range(n):
    print(dfs(i,0))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    if t <= ss:
        return dfs(eki+1, ss+cc)
    else:
        return dfs(eki+1, -(-t//ff)*ff+cc)

for i in range(n):
    print(dfs(i,0))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    if t < ss:
        return dfs(eki+1, ss+cc)
    else:
        return dfs(eki+1, -(-t//ff)*ff+cc)

for i in range(n):
    print(dfs(i,0))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    m = max(0,-(-t+ss)//ff)
    if t < ss:
        return dfs(eki+1, ss+cc)
    else:
        return dfs(eki+1, -(-t//ff)*ff+cc)

for i in range(n):
    print(dfs(i,0))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    m = max(0,-(-t+ss)//ff)
    if t < ss:
        return dfs(eki+1, ss+cc)
    elif t%ff==0:
        return dfs(eki+1, t+cc)
    else:
        return dfs(eki+1, -(-t//ff)*ff+cc)

for i in range(n):
    print(dfs(i,0))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

def dfs(eki,t):
    if eki == n-1:
        return t

    cc = c[eki]
    ss = s[eki]
    ff = f[eki]

    m = max(0,-(-t+ss)//ff)
    if t < ss:
        return dfs(eki+1, ss+cc)
    elif t%ff==0:
        return dfs(eki+1, t+cc)
    else:
        return dfs(eki+1, t+ff-(t%ff)+cc)

for i in range(n):
    print(dfs(i,0))

Solution (Python):

import numpy as np

N = int(input())

Cs = []
Ss = []
Fs = []
ans = [0] * N
ans_fix = [False] * N
for i in range(N-1):
    C,S,F = list(map(int, input().split()))
    Cs.append(C)
    Ss.append(S)
    Fs.append(F)

ans_fix[-1] = True

for i in range(N):
    for j in range(i, N-1):
        if i == 0:
            ans[j] = Ss[j] + Cs[j]
        elif not ans_fix[j-i]:
            if ans[j-i] <= Ss[j]:
                ans[j-i] = Ss[j]
            wait_time = Fs[j] - (ans[j-i] % Fs[j]) if ans[j-i] % Fs[j] != 0 else 0
            ans[j-i] += wait_time + Cs[j]

    ans_fix[N-2-i] = True

for a in ans:
    print(a)

Solution (Python):
N = int(input())
CSF = [map(int, input().split()) for _ in range(N-1)]
C, S, F = [list(i) for i in zip(*CSF)]

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

Solution (Python):
(n,),*d=[list(map(int,c.split()))for c in open(0)]
for i in range(n-1):
 t=0
 for j in range(i,n-1):c,s,f=d[j];t=[t+(f-t%f)%f,s][t<s]+c
 print(t)
print(0)

Solution (Python):

(n,), *d = [list(map(int, c.split())) for c in open(0)]
n -= 1
for i in range(n):
    t = 0
    for j in range(i, n):
        c, s, f = d[j]
        t = (s if t < s else t if t % f == 0 else t + f - t%f) + c
    print(t)
print(0)

Solution (Python):

import sys
import math

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
"""
後ろから順番に漸化式でいけるかと思ったが、それぞれの駅での電車の間隔が一定でないので、むり
O(n**2)で順番に計算する。
"""


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())
ans = [0] * (n - 1)

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

Solution (Python):
n = int(input())
data = []
for i in range(n-1):
    c,s,f = map(int,input().split())
    s //= f
    data.append((c,s,f))
for i in range(n):
    if i == n-1:
        print(0)
        break
    for j in range(i,n-1):
        if j == i:
            ans = data[j][0]+data[j][1]*data[j][2]
            continue
        ans = (max((ans-1)//data[j][2]+1,data[j][1])*data[j][2]) + data[j][0]
    print(ans)

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)

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

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

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

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

ans = [0] * n

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

Solution (Python):
import sys
input = sys.stdin.readline

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 = 0
    for j in range(i, n-1):
        c = C[j]
        s = S[j]
        f = F[j]

        t = max(t, s)
        if t % f:
            t += f - (t % f)
        t += c
    print(t)
print(0)

Solution (Python):
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]
 
for i in range(n):
    current = 0
    for j in range(i, n-1):
        if current < csf[j][1]:
            current = csf[j][1]
        if current % csf[j][2] != 0:
            current += csf[j][2] - (current % csf[j][2])
        current += csf[j][0]
    print(current)

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

ans = []
for i, (ci, si, fi) in enumerate(CSF):
  now = si + ci
  for j in range(i+1, N-1):
    cj, sj, fj = CSF[j]
    now = max((-(-now//fj))*fj, sj) + cj
  ans.append(now)

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count





N = I()
data = ILL(N-1)


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

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

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

Solution (Python):
def solve(n, t_list):

    ans = [t[1] for t in t_list]
    ans.append(0)
    for i, t in enumerate(t_list):
        for j in range(i+1):
            if ans[j] < t[1]:
                ans[j] += t[0]+(t[1] - ans[j])
            else:
                if ans[j] % t[2] == 0:
                    ans[j] += t[0]
                else:
                    ans[j] += t[0] + (ans[j] // t[2] + 1)*t[2] - ans[j]

    for i in ans:
        print(i)

if __name__ == "__main__":
    n = int(input())
    t_list = [[int(j) for j in input().split()] for i in range(n-1)]
    solve(n, t_list)

Solution (Python):
import math
def main():
  N = int(input())
  ans = [0] * N
  for i in range(N-1):
    c, s, f = map(int, input().split())
    for j in range(i + 1):
      ans[j] = f*max(math.ceil(ans[j]/f), math.ceil(s/f))+c
  for i in range(N):
    print(ans[i])
if __name__ == "__main__":
  main()

Solution (Python):
DEBUG = False

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

if DEBUG:
    print("CSF: {}".format(CSF))

for i in range(N-1):
    ans = 0
    for j in range(i, N-1):
        if DEBUG:
            print("i: {}, j: {}, ans: {}".format(i, j, ans))
        c, s, f = CSF[j]
        if ans < s:
            ans = s
        elif ans  % f != 0:
            ans += f - ans % f
        else:
            pass
        ans += c
    if DEBUG:
        print("i: {}, j:{}, ans:{}".format(i, j, ans))
    print(ans)
print(0)

Solution (Python):
n = int(input())
inputs = [list(map(int,input().split())) for i in range(n-1)]
out = []
for station_st in range(n-1):
    spend_time = inputs[station_st][1]+inputs[station_st][0] 

    for st_num_cur in range(station_st+1,n-1):
        if spend_time < inputs[st_num_cur][1]:
            spend_time = inputs[st_num_cur][1]

        train_leave_time = inputs[st_num_cur][1] 
        train_i = 0
        wait_time = 0
        if (spend_time%inputs[st_num_cur][2])!=0:
            wait_time = inputs[st_num_cur][2] - (spend_time%inputs[st_num_cur][2])
        spend_time += wait_time + inputs[st_num_cur][0] 
        
    print(spend_time)
print(0)

Solution (Python):
def main():
    N = int(input())
    trains = [list(map(int, input().split(' '))) for _ in range(N - 1)]
    ans = [0 for _ in range(N)]
    for i in range(N - 1):
        t = 0
        for train in trains[i:]:
            c, s, f = train
            wait_time = s - t if t <= s else (f - t) % f
            t += wait_time + c
        ans[i] = t
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Solution (Python):
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 j == i:
            ans += CSF[i][1]
            ans += CSF[i][0]
        else:
            if ans < CSF[j][1]:
                ans += CSF[j][1] - ans
            else:
                mod = (ans - CSF[j][1]) % CSF[j][2]
                if mod != 0:
                    ans += CSF[j][2] - mod
            ans += CSF[j][0]
    print(ans)

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] = list(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] - t) + c[j]
        else:
            tmp = (t - s[j]) % f[j]
            if tmp == 0:
                t += c[j]
            else:
                t += (f[j] - tmp) + c[j]
    print(t)

Solution (Python):
N = int(input())
memo = [0]*N
C = [0]*N
S = [0]*N
F = [0]*N



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

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

    print(t)

Solution (Python):
import math

ceil = math.ceil

def main():
    N = int(input())
    ans = [0]*N
    for i in range(N-1):
        C, S, F = map(int, input().split())
        ans[i] = S + C
        for j in range(i):
            nxt = ceil((ans[j]-S)/F)
            ans[j] = max(0, nxt)*F + S + C
    
    for a in ans:
        print(a)

if __name__ == "__main__":
    main()

Solution (Python):



def main():
    N = int(input())
    C = [None] * (N-1)
    S = [None] * (N-1)
    F = [None] * (N-1)
    for i in range(N-1):
        C[i], S[i], F[i] = map(int, input().split())
    
    for i in range(N-1):
        ans = S[i]
        for j in range(i,N-1):
            if j > i:
                if ans <= S[j]:
                    ans = S[j]
                else:
                    if (ans - S[j]) % F[j] > 0:
                        ans += F[j] - (ans - S[j]) % F[j]
            ans += C[j]
        print(ans)
    print(0)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
csf=[]
for _ in range(n-1):
    c,s,f=map(int,input().split())
    csf.append((c,s,f))
ans=[0]*n
for i,(c,s,f) in enumerate(csf):
    for j in range(0,i+1):
        if ans[j]<=s:
            ans[j]=s+c
        else:
            ans[j]=(ans[j]+f-1)//f*f+c
for x in ans:
    print(x)

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

ans = []
for i in range(n-1):
    now = 0
    for c,s,f in csf[i:]:
        if now < s:
            now = s
        now += (s-now)%f+c
    ans.append(now)
ans.append(0)

for a in ans:
    print(a)

Solution (Python):
def mult(a,b):
    
    d = (a-1)//b
    return b*(d+1)

def mov(CSF,st):
    N = len(CSF)
    time = 0
    for i in range(st,N):
        c,s,f = CSF[i][0],CSF[i][1],CSF[i][2]
        time = max(time,s)
        time = mult(time,f) + c
    return time

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

    for i in range(N-1):
        print(mov(CSF,i))
    print(0)

if __name__ == "__main__":
    main()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
train = []

for i in range(N - 1):
    c, s, f = getNM()
    train.append([c, s, f])


def gotowest(sta):
    
    time = train[sta][0] + train[sta][1]
    
    for j in range(sta + 1, N - 1):
        if time <= train[j][1]:
            
            time = train[j][0] + train[j][1]
        else:
            
            wait = ((time - train[j][1]) + train[j][2] - 1) // train[j][2]
            time = train[j][1] + (train[j][2] * wait) + train[j][0]
    return time

ans = []
for i in range(N - 1):
    ans.append(gotowest(i))

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

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
train = []

for i in range(N - 1):
    c, s, f = getNM()
    train.append([c, s, f])


def gotowest(sta):
    
    time = train[sta][0] + train[sta][1]
    for j in range(sta + 1, N - 1):
        if time <= train[j][1]:
            time = train[j][0] + train[j][1]
                
        else:
            
            wait = ((time - train[j][1]) + train[j][2] - 1) // train[j][2]
            time = train[j][1] + (train[j][2] * wait) + train[j][0]
    return time
    
ans = []
for i in range(N - 1):
    ans.append(gotowest(i))

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

Solution (Python):
n = int(input())
csf = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    csf.append((c, s, f))
ans = [0]*n
for i, (c, s, f) in enumerate(csf):
    for j in range(0, i+1):
        if ans[j] <= s:
            ans[j] = c+s
        else:
            ans[j] = (ans[j]+f-1)//f*f+c
for i in ans:
    print(i)

Solution (Python):
import copy
n = int(input())
c = [list(map(int, input().split())) for i in range(n-1)]
for i in range(n):
    t = 0
    for j in range(i, n-1):
        if t < c[j][1]:
            t = c[j][1]
        elif t%c[j][2] == 0:
            pass
        else:
            t += c[j][2] - t%c[j][2]
        t += c[j][0]
    print(t)

Solution (Python):


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

for i in range(N - 1):
    c_i, s_i, f_i = data[i] 
    ans = c_i + s_i
    if i == N - 2:
        print(ans)
        continue
    for j in range(i + 1, N - 1):
        c_j, s_j, f_j = data[j]
        if ans >= s_j:
            tmp = (ans - s_j) % f_j
            ans += c_j if tmp == 0 else f_j - tmp + c_j
        else:
            ans += s_j - ans + c_j
    print(ans)

print(0)

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

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

print(0)

Solution (Python):
from math import ceil
n, *CSF = map(int, open(0).read().split())
A = []
for i in range(0, 3*(n-1), 3):
    t = 0
    for c, s, f in zip(CSF[i::3], CSF[i+1::3], CSF[i+2::3]):
        if t <= s:
            t = s + c
        else:
            t = ceil((t-s) / f) * f + s + c
    A.append(t)
A.append(0)
print(*A, sep='\n')

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:
            pass
        else:
            t += f - t % f

        t += c

    print(t)

Solution (Python):
N = int(input())
C, S, F = zip(*(tuple(map(int, input().split())) for _ in range(N - 1)))
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]
        else:
            div, rem = divmod(total, F[j])
            total = (div + bool(rem)) * F[j]
        total += C[j]
    print(total)
print(0)

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

ans = [0]*(n)
ans[n-2] = csf[n-2][0] + csf[n-2][1] 

for i in range(n-3, -1, -1):
    
    ans_cur = csf[i][0] + csf[i][1] 
    for j in range(i+1, n-1):
        
        if ans_cur < csf[j][1]: 
            ans[i] = ans[j]
            break
        while ans_cur%csf[j][2] != 0:
            ans_cur += 1 
        ans_cur += csf[j][0]
    else:
        ans[i] = ans_cur

for val in ans:
    print(val)

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

for i in range(N):
    if i==N-1:
        print(0)
    now=0
    for j in range(i,N-1):
        c,s,f=L[j]
        if now<s:
            now+=s-now
        if now%f!=0:
            now+=(f-now%f)
        now+=c
        if j==N-2:
            print(now)