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:
from math import ceil

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    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):
        if i == N-1:
            print(0)
            break
        count = S[i]
        count += C[i]
        for j in range(i+1, N-1):
            if count < S[j]:
                count = S[j]
            elif count%F[j] != 0:
                count += F[j] - count%F[j]
            count += C[j]
        print(count)

Submission status: Accepted

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

def cul(s,start,add):
  if s <= start:
    return start
  else:
    if s%add==0:
      return s
    else:  
      A = s+(add-s%add)
      return A 
  
for i in range(n-1):
  ans = csf[i][0]+csf[i][1]
  for j in range(i+1,n-1):
    ans = cul(ans,csf[j][1],csf[j][2])+csf[j][0]
  print(ans)  
print(0)

Submission status: Accepted

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

time=[]
for i in range(n-1):
    arrive=csf[i][0]+csf[i][1]
    for j in range(i+1,n-1):
        if csf[j][1]>=arrive:
            arrive=csf[j][1]+csf[j][0]
        else:
            if (arrive-csf[j][1])%csf[j][2]==0:
                arrive=((arrive-csf[j][1])//csf[j][2])*csf[j][2]+csf[j][0]+csf[j][1]
            else:
                arrive=((arrive-csf[j][1])//csf[j][2])*csf[j][2]+csf[j][2]+csf[j][0]+csf[j][1]
    time.append(arrive)
    
for i in time:
    print(i)
print(0)

Submission status: Accepted

Solution code:
from math import ceil

N = int(input())

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

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        c, s, f = station[j]
        if t <= s:
            # 始発前に着いたら始発に乗る
            t = s + c
        else:
            # 始発後に着いたら次の便に乗る
            x = ceil((t - s) / f)
            t = s + c + f * x
    print(t)
print(0)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
l=[]


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

for n in range(N):
    sum=0
    for i in range(n,N-1):
        if sum>l[i][1]:
            sum=l[i][1]-(-(sum-l[i][1])//l[i][2]*l[i][2])+l[i][0]
        else:
            sum=l[i][0]+l[i][1]
    print(sum)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
C = [0] * N
S = [0] * N
F = [0] * (N - 1)
F.append(1)

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

for i in range(N):
    time = S[i]
    for j in range(i, N):
        time = max((F[j] - (time - S[j])) % F[j] + time, S[j]) + C[j]
    print(time)

Submission status: Accepted

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

for j in range(N):
    t = 0
    for i in range(j,N-1):
        C,S,F = CSF[i]
        if t >= S:
            if t%F == 0:
                t += C
            else:
                t = (1+t//F)*F + C
        else:
            t = S+C
    T.append(t)
print(*T, sep="\n")

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

ans=[]
for s in range(N-1):
  time=0
  for i in range(s,N-1):
    if i==s:
      time=S[i]+C[i]
    else:
      time=S[i]+C[i] if time<=S[i] else time+(F[i]-time%F[i])%F[i]+C[i]
  ans.append(time)

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

Submission status: Accepted

Solution code:
import math
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())

times = [0]*N
for j in range(N-1):
    time = 0
    for i in range(j, N-1):
        if time <= S[i]:
            time = S[i]
        else:
            time = math.ceil(time / F[i]) * F[i]
        time += C[i]

    times[j] = time
for i in range(N):
    print(times[i])

Submission status: Accepted

Solution code:
import math

N = int(input())
plan = [tuple(map(int, input().split())) for _ in range(N-1)] + \
    [(0, 0, 0)]

ans = []
for i in range(N):
    time = 0
    for j in range(i+1, N):
        c, s, f = plan[j-1]
        next_c, next_s, next_f = plan[j]
        if time <= s:
            time = c + s
        else:
            if (time - s) % f == 0:
                time += c
            else:
                time += c + (f - (time - s) % f)
    ans.append(time)


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

Submission status: Accepted

Solution code:
"""
シミュレーション問題
- 数式にこだわりすぎた
- WAになって何が間違っているかはわからなかった
- Nの範囲を確認すればO(N^2)でも十分問題なかったことが分かったので素直に実装すればよかった
"""
n = int(input())
setting = []
for _ in range(n-1):
    setting.append(tuple(map(int, input().split())))

results = []
for i in range(n-1):
    cur = 0
    for c, s, f in setting[i:]:
        if cur < s:
            cur = c + s
        elif 0 == cur % f:
            cur += c
        else:
            cur += c + f - cur % f
    results.append(cur)
results.append(0)
for result in results:
    print(result)

Submission status: Accepted

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

results = []
for i in range(n-1):
    cur = 0
    for j in range(i, n-1):
        if cur < setting[j][1]:
            cur = setting[j][0] + setting[j][1]
        elif 0 == cur % setting[j][2]:
            cur += setting[j][0]
        else:
            cur += setting[j][0] + setting[j][2] - cur % setting[j][2]
    results.append(cur)
results.append(0)
for result in results:
    print(result)

Submission status: Accepted

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

from math import ceil

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

Submission status: Accepted

Solution code:
N = int(input())

CSF = [[int(i) for i in input().split()] for _ in range(N-1)]
for i in range(N-1) :
    x = 0
    for j in range(i, N-1) :
        C, S, F = CSF[j]
        if x < S :
            x = S + C
        else :
            x = S + F * ((x - S + F - 1) // F) + C
    print(x)
print(0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

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

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# 
N =  int(sys.stdin.readline())
L =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N - 1)]

for i in range(N - 1):
    start = L[i]
    cnt = start[0] + start[1]
    for j in range(i + 1, N - 1):
        next = L[j]
        # 開通しているか確認
        if cnt < next[1]:
            cnt = next[1]
        else:
            # 貪欲法で探す？
            x = next[1]
            while True:
                if x >= cnt:
                    # print(x, cnt, next[1])
                    break
                x += next[2]
            cnt += (x - cnt)
        cnt += next[0]
    print(cnt)

print(0)

Submission status: Accepted

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


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    ans = [0]*(N)
    for k in range(N-1):
        cst = S[k]+C[k]
        for i in range(k+1,N-1):
            if(cst < S[i]):
                cst = max(cst, S[i])
            elif(cst%F[i] == 0):
                cst = cst
            else:
                cst = cst + F[i] - (cst%F[i])
            cst += C[i]
        ans[k] = cst

    for i in ans:
        print(i)

    return

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    global N, C, S, F
    N = int(next(tokens))  # type: int
    C = [int()] * (N-1)  # type: "List[int]" 
    S = [int()] * (N-1)  # type: "List[int]" 
    F = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    csf = [list(map(int, input().split())) for i in range(N-1)]
    for start in range(N):
        now = 0
        for i in range(start, N-1):
            c, s, f = csf[i]
            if now <= s:
                now = s
            else:
                if now%f != 0:# 待ち時間が発生するパターン
                    now += f - now % f
            # print("出発{} time:{}".format(i, now))
            now += c
            # print("到着{} time:{}".format(i+1, now))
        print(now)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
C = []
S = []
F = []

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

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

Submission status: Accepted

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

res = [0]*N
for i in range(N-1):
    t = 0
    for j in range(i,N-1):
        c = CSF[j][0]
        s = CSF[j][1]
        f = CSF[j][2]
        if t <= s:
            t = s+c
        else:
            if t%f == 0:
                t += c
            else:
                m = t%f
                t += ((f-m)+c)
    res[i] = t
print("\n".join(map(str,res)))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    csfs = [[int(i) for i in input().split()] for j in range(N-1)] + [[-1,0,0]]

    for i in range(N):
        state = i
        time = csfs[state][1]
        while state < N-1:
            if time % csfs[state][2] == 0 and csfs[state][1] <= time:
                time += csfs[state][0]
                state += 1
            else:
                time += (csfs[state][2] - time%csfs[state][2])
                if csfs[state][1] > time:
                    time = csfs[state][1]
        print(time)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,*t=map(int,open(0).read().split())
for i in range(n):
 a=0
 for c,s,f in zip(t[3*i::3],t[3*i+1::3],t[3*i+2::3]):a=max(s,a//-f*-f)+c
 print(a)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

res = []
for i in range(n):
    t = 0
    for j in range(i, n - 1):
        s = ss[j]
        f = fs[j]
        if t < s:
            t = s
        elif t % f > 0:
            t += f - t % f
        t += cs[j]
    res.append(t)
for x in res:
    print(x)

Submission status: Accepted

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

res = []
for i in range(n):
    t = 0
    for j in range(i, n - 1):
        s = ss[j]
        f = fs[j]
        if t < s:
            t = s
        elif t % f > 0:
            t += f - t % f
        t += cs[j]
    res.append(t)
for x in res:
    print(x)

Submission status: Accepted

Solution code:
n = int(input())
cs, ss, fs = [], [], []
for _ in range(n - 1):
    c, s, f = map(int, input().split())
    cs.append(c)
    ss.append(s)
    fs.append(f)
cs.append(0)
ss.append(0)
fs.append(1)

res = []
for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        s = ss[j]
        f = fs[j]
        if t < s:
            t = s
        elif t % f > 0:
            t += f - t % f
        t += cs[j]
    res.append(t)
res.append(0)
for x in res:
    print(x)

Submission status: Accepted

Solution code:
n = int(input())
cs, ss, fs = [], [], []
for _ in range(n - 1):
    c, s, f = map(int, input().split())
    cs.append(c)
    ss.append(s)
    fs.append(f)
cs.append(0)
ss.append(0)
fs.append(1)

res = []
for i in range(n - 1):
    arrives = [0]
    lefts = [ss[i]]
    for j in range(i, n - 1):
        a = lefts[-1] + cs[j]
        arrives.append(a)
        ns = ss[j + 1]
        if a > ss[j + 1]:
            nf = fs[j + 1]
            w = (nf - (a - ns) % nf) % nf
            lefts.append(a + w)
        else:
            lefts.append(ns)
    res.append(arrives[-1])
res.append(0)
for x in res:
    print(x)

Submission status: Accepted

Solution code:
import math
n=int(input())
csf=[input() for _ in range(n-1)]
for i in range(n-1):
  c,s,f=map(int, csf[i].split())
  cost=s+c
  for j in range(i+1, n-1):
    c,s,f=map(int, csf[j].split())
    cost=math.ceil((cost-s)/f)*f+s+c if cost > s else s+c
  print(cost)
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

#x以上で最小のyの倍数
def min_mult(x,y):
    if x%y==0:
        return x
    else:
        return x + (y-x%y)

N = I()
C,S,F = Line(N-1)

ans = []

for i in range(N-1):
    temp = S[i]+C[i]
    for j in range(i+1,N-1):
        temp = min_mult(max(temp,S[j]),F[j]) + C[j]
    ans.append(temp)

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

Submission status: Accepted

Solution code:
import sys
from statistics import *
from collections import *
from operator import itemgetter

stdin = sys.stdin

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

n = ni()
li = [[0, 0, 0]]
for i in range(1, n):
    li.append(na())
for i in range(1, n):
    t = 0
    for j in range(i, n):
        c, s, f = li[j]
        if t < s:
            t = s
        else:
            for k in range(t, t+f+1):
                if k % f == 0:
                    t = k
                    break
        t += c
    print(t)
print(0)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc084/tasks/abc084_c
# C - Special Trains
import math

N = int(input().split()[0])
csf_list = []

for _ in range(N-1):
    c, f, s = list(map(int, input().split()))
    csf_list.append((c, f, s))

x_list = []
total_c_list = []

for start_i in range(N-1):  # N <= 500
    total_c = csf_list[start_i][0] + csf_list[start_i][1]

    for csf in csf_list[start_i+1:]:  # N <= 500
        c, s, f = csf
        total_c = s if total_c < s else total_c
        i = math.ceil((total_c - s) / f)
        total_c = s + f * i + c
    total_c_list.append(str(total_c))

ans = '\n'.join(total_c_list + ['0'])
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
CSF = []
for i in range(0, N-1):
    CSF.append(list(map(int, input().split())))
for i in range(0, N):
    ans = 0
    for j in range(i, N-1):
        ans = max(CSF[j][1], ans)
        if ans % CSF[j][2] != 0:
            ans += (CSF[j][2]-ans % CSF[j][2])
        ans += CSF[j][0]
    print(ans)

Submission status: Accepted

Solution code:
N = int(input())

CSF = []

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

CSF.append([0, 0, 1])

ans = [0] * N

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



for i in ans:
    print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# ABC084C - Special Trains
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(N - 1))
    for i in range(N):
        cur = 0
        for c, s, f in A[i:]:
            if cur <= s:
                cur = s + c
            else:
                cur = (cur + f - 1) // f * f + c  # ? (@maspy)
        print(cur)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

N = int(input())

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

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

Submission status: Accepted

Solution code:
N = int(input())
CSFs = []
for i in range(N-1):
  C, S, F = map(int, input().split())
  CSFs.append((C, S, F))
for i in range(N):
  r = 0
  L = CSFs[i:]
  for C, S, F in L:
    if r < S:
      r = S
    else:
      r = (r-S +F-1)//F*F+S
    r += C
  print(r)

Submission status: Accepted

Solution code:

N = int(input())

CSF = []

for i in range(N-1):

    C,S,F = map(int,input().split())

    CSF.append([C,S,F])


for i in range(N):


    time = 0

    for j in range(N-1-i):

        j += i

        c = CSF[j][0]
        s = CSF[j][1]
        f = CSF[j][2]

        if time < s:

            time = s + c

        elif time % f == 0:

            time += c

        else:

            time = (time // f + 1) * f + c

    print (time)

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]
        elif time % f[j] == 0:
            pass
        else:
            time += f[j] - (time % f[j])
        time += c[j]
    print(time)
print(0)

Submission status: Accepted

Solution code:
n = int(input())

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

for i in range(n-1):
    c_, s_, f_ = map(int, input().split())
    c.append(c_)
    s.append(s_)
    f.append(f_)

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

Submission status: Accepted

Solution code:
import math
def main():
    N = int(input())
    info = []
    for _ in range(N-1):
        C, S, F = map(int, input().split())
        info.append([C, S, F])
    for i in range(N-1):
        t = info[i][1] + info[i][0]
        j = i+1
        while j < N-1:
            if t <= info[j][1]:
                t = info[j][1] + info[j][0]
            else:
                k = math.ceil((t-info[j][1])/info[j][2])
                t = k * info[j][2] + info[j][1] + info[j][0]
            j += 1
        print(t)
    print(0)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
l = [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>l[j][1]:
            while 1:
                if t%l[j][2]==0:
                    break
                else:
                    t+=1
            t+=l[j][0]
        else:
            t=l[j][1]+l[j][0]
    print(t)

Submission status: Accepted

Solution code:
n=int(input())
a=[0]*n
x=[]
y=[]
z=[]
for i in range(n-1):
	p,pp,ppp=map(int,input().split())
	x.append(p)
	y.append(pp)
	z.append(ppp)
for i in range(n-2):
	ans=y[i]+x[i]
	for j in range(n-i-2):
		if ans<y[j+1+i]:
			ans=y[j+1+i]
		if (ans-y[j+1+i])%z[j+1+i]!=0:
			ans+=z[j+1+i]-((ans-y[j+1+i])%z[j+1+i])
		ans+=x[j+1+i]
	print(ans)
print(y[-1]+x[-1])
print(0)

Submission status: Accepted

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

for i in range(n-1):
    cnt = i
    now = 0
    tmp = 0
    while cnt <= n-2:
        if cnt == n-2:
            if now == 0:
                tmp += csf[cnt][0] + csf[cnt][1]
                print(tmp)
                cnt += 1
                now += 1
            else:
                tmp += max((tmp + csf[cnt][2] - 1) // csf[cnt][2] * csf[cnt][2],csf[cnt][1]) - tmp + csf[cnt][0]
                cnt += 1
                print(tmp)
        elif now == 0:
            tmp += csf[cnt][0] + csf[cnt][1]
            cnt += 1
            now += 1
        else:
            tmp += max((tmp + csf[cnt][2] - 1) // csf[cnt][2] * csf[cnt][2],csf[cnt][1]) - tmp + csf[cnt][0]
            cnt += 1
            
    
    
print(0)

Submission status: Accepted

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

  ans = []
  for i in range(n-1):
    time = 0
    for j in range(i,n-1):
      c,s,f = query[j]
      time = max(s,time)
      if not time%f == 0:
        time += f-time%f
      time += c
    ans.append(time)
  for i in ans:
    print(i)
  print(0)
solve()

Submission status: Accepted

Solution code:
import math
N = int(input())
lst = [list(map(int, input().split())) for i in range(N-1)]
ans = []
for i in range(N-1):
  t = lst[i][0] + lst[i][1]
  for j in range(i+1, N-1):
    if (t >= lst[j][1]):
      if (t % lst[j][2] == 0):
        t += lst[j][0]
      else:
        n = math.ceil((t - lst[j][1]) / lst[j][2])
        t = lst[j][1] + lst[j][2] * n + lst[j][0]
    else:
      t = lst[j][1] + lst[j][0]
  ans.append(t)
ans.append(0)

for i in ans:
  print(i)

Submission status: Accepted

Solution code:
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 + C
        elif t == S or t % F == 0:
            t += C
        else:
            t += F - t % F + C
    print(t)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())

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

ans = [0] * N

for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        if j == i:
            now = CSF[j][1] + CSF[j][0]
        else:
            if now <= CSF[j][1]:
                now = CSF[j][1] + CSF[j][0]
            else:
                if (now - CSF[j][1]) % CSF[j][2] == 0: #すぐ乗れる
                    now += CSF[j][0]
                else:
                    wait = CSF[j][2] - ((now - CSF[j][1]) % CSF[j][2])
                    now += wait + CSF[j][0]
                    
    ans[i] = now
    


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

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())

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

for n in range(N-1):
    c, s, f = [int(x) for x in stdin.readline().rstrip().split()]
    C[n] = c
    S[n] = s
    F[n] = f

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

        t += C[j]
    print(t)
    t = 0
print(0)

Submission status: Accepted

Solution code:
N = int(input())
CSF = []
for _ in range(N - 1):
    c, s, f = map(int, input().split())
    CSF.append((c, s, f))
for i in range(N):
    t = 0
    for c, s, f in CSF[i:]:
        t = max(t, s)
        t = ((t - 1) // f + 1) * f
        t += c
    print(t)

Submission status: Accepted

Solution code:
N = int(input())
CSF = []
for _ in range(N - 1):
    c, s, f = map(int, input().split())
    CSF.append((c, s, f))
for i in range(N):
    t = 0
    for c, s, f in CSF[i:]:
        t = max(t, s)
        t = ((t - 1) // f + 1) * f
        t += c
    print(t)

Submission status: Accepted

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

for i in range(N):
    total=0
    for k in range(i,N):
        if k==i:
            total+=A[k][0]+A[k][1]
        else:
            if A[k][1]>total:
                total=A[k][1]
            if total%A[k][2]!=0:
                total=total+A[k][2]-total%A[k][2] 
            total+=A[k][0]
    print(total)
print(0)