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: Wrong Answer

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

Submission status: Wrong Answer

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

val = [0, 0, 0]
num0 = 0
for i, j in enumerate(route[::-1]):
    num = j[0]+j[1]-num0
    if num >= 0:
        if i == 0:
            ans.append(ans[-1]+j[0]+j[1])
        else:
            ans.append(ans[-1]-val[1]+j[0]+j[1]+num%val[2])
    else:
        ans.append(ans[-1])
    num0 = max(num0, j[1])
    val = j
for i in range(n-1, -1, -1):
    print(ans[i])

Submission status: Wrong Answer

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

res = [0]*(N+1)

for i in range(N-2, -1, -1):
    t = S[i]+C[i]
    for j in range(i+1, N-1):
        t += t%F[j]+C[j] 
    res[i] = max(t, res[i+1])

for r in res[:-1]:
    print(r)

Submission status: Wrong Answer

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

def shortest_path(start,end,times):
    if start == end:
        return times
    elif times<=graph[start][2]:
        times = (graph[start][2]+graph[start][1])
        return shortest_path(start+1,end,times)
    elif times%graph[start][3]==0:
        times += (graph[start][1])
        return shortest_path(start+1,end,times)
    else:
        times = times+graph[start][3]-times%graph[start][3]
        return shortest_path(start+1,end,times)


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

Submission status: Wrong Answer

Solution code:
from math import floor
n=int(input())
csf=[tuple(map(int,input().split())) for _ in range(n-1)]

arrtime=lambda i,cs: max(csf[i][2]*floor(cs/csf[i][2]),csf[i][1])+csf[i][0]
for i in range(n-1):
  arrivN=csf[i][1]
  for j in range(i,n-1):
    arrivN=arrtime(j,arrivN)
  print(arrivN)
print(0)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = lambda:sys.stdin.readline().strip()
    
    N = int(input())
    #C:所要時間,S:開始後,F:間隔
    CSF = [list(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
            else:
                t+=(t-s)%f+c
        print(t)

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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

for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        if now <= C[j][1]:
            now = C[j][1]
        else:
            d = C[i][2]
            for k in range(10**5):
                if now <= C[j][1] + d:
                    now = C[j][1] + d
                    break
                d += C[j][2]
        now += C[j][0]
    print(now)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N - 1):
    count = 0
    count += S[i]
    count += C[i]
    for j in range(N - 1):
        if (i >= j):
            continue
        if count < S[j]:
            count = S[j]
            count += C[j]
        elif count % F[j] == 0:
            count += C[j]
            continue
        else:
            k = count // F[j]
            count += F[i] * (k + 1) - count
            count += C[j]

    print(count)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
CSF = [list(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
        else:
            t = ((t - s) // f) * f + s
        # i -> i+1に移動
        t += c

    print(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
CSF = [list(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
        else:
            t += (t - s) % f
        # i -> i+1に移動
        t += c

    print(t)

Submission status: Wrong Answer

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


for i in range(N - 1):
    t = 0

    for c, s, f in CSF[i:]:
        # 待ち時間
        if t < s:
            t = s
        else:
            t += (t - s) % f
        # i -> i+1に移動
        t += c

    print(t)

Submission status: Wrong Answer

Solution code:
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-1):
  time = l[i][1] + l[i][0]
  for j in range(i+1, N-1):
    if time-l[j][1] >= 0:
      wait = time % l[j][2]
      time += wait + l[j][0]
    else:
      time = l[j][1] + l[j][0]
  print(time)
print(0)

Submission status: Wrong Answer

Solution code:
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-1):
  time = l[i][1] + l[i][0]
  for j in range(i+1, N-1):
    if time-l[j][1] >= 0:
      wait = (time-l[j][1]) % l[j][2]
      time += wait + l[j][0]
    else:
      time = l[j][1] + l[j][0]
  print(time)
print(0)

Submission status: Wrong Answer

Solution code:
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-1):
  time = l[i][1] + l[i][0]
  for j in range(i+1, N-1):
    if time-l[j][1] >= 0:
      wait = (time-l[j][1]) % l[j][2]
    else:
      wait = l[j][1]
      time = 0
    time += wait + l[j][0]
  print(time)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
trains = []
for _ in range(N - 1):
    cost, start, f = map(int, input().split())
    trains.append([cost, start, f])

# print(trains)
for station_index in range(N - 1):
    ans = 0
    for j in range(station_index, N - 1):
        cost, start, f = trains[j]
        if ans < start:
            ans = start + cost
        elif ans == start:
            ans += cost
        else:
            if (ans - start) % f == 0:
                ans += cost
            else:
                ans += ((ans - start) % f) + cost
    print(ans)
print(0)

Submission status: Wrong Answer

Solution code:
(n,),*csf = [list(map(int, s.split())) for s in open(0)]

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [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 = l[j][0]
        s = l[j][1]
        f = l[j][2]
        if t < s:
            t = s
        t += c
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# 整数の入力
N = int(input())
data = [list(map(int, input().split())) for _ in range(N-1)]
# print(N)
#print(data)


for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        #print(j)
        c = data[j][0]
        s = data[j][1]
        f = data[j][2]
        if t == 0 or t < s: 
            t = s
        elif (t % f) != 0:
            t = t //f * f
        t += c
    print(t)
        

print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[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=l[j][0],l[j][1],l[j][2]
        if t<s:
            t=s
        elif t%f==0:
            t+=c
        else:
            t+=f-t&f
    print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[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=l[j][0],l[j][1],l[j][2]
        if t<s:
            t=s
        elif t%f==0:
            pass
        else:
            t+=f-t&f
        t+=c
    print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[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=l[j][0],l[j][1],l[j][2]
        if t<s:
            t=s
        elif not t%f==0:
            t=t+f-t&f
        t+=c
    print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[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=l[j][0],l[j][1],l[j][2]
        if t<s:
            t=s
        elif not t%f==0:
            t+=f-t&f
        t+=c
    print(t)

Submission status: Wrong Answer

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    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


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
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)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
csf = [lr() for i in range(n-1)]
ans = []
for i in range(n):
    time = 0
    for j in range(i,n-1):
        c,s,f = csf[j]
        if time >= s:
            k = time%f
            if k != 0:
                time = (time//f)*f+(f-k)+c
            else:
                time = time+c
        else:
            time = s+c
    ans.append(time)
for num in ans:
    print(num)

Submission status: Wrong Answer

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

N = int(input())
CSF = [[0,0,0]]
for i in range(1,N):
    CSF.append(list(map(int,input().split())))
for i in range(1,N+1):
    nowtime = 0
    for j in range(i,N):
        if nowtime <=CSF[j][1]:
            depT =CSF[j][1]
        else:
            depT =CSF[j][1] + math.ceil((nowtime-CSF[j][1])/CSF[j][2])*CSF[j][2]

        nowtime = depT+CSF[j][0]
        print(nowtime,depT)
    print(nowtime)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)
for i in range(N-1):
    c, s, f = map(int, input().split())
    C[i] = c
    S[i] = s
    F[i] = f
for i in range(N-1):
    ttl = C[i] + S[i]
    if i == N-2:
        print(ttl)
        print(0)
        exit()
    for j in range(i+1, N-1):
        if ttl > S[j]:
            ttl += (ttl - S[j]) % F[j] + C[j]
        if ttl == S[j]:
            ttl += C[j]
        if ttl < S[j]:
            ttl += S[j] - ttl + C[j]
    print(ttl)

Submission status: Wrong Answer

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

# check
T = []
append = T.append
for c, s, f in CSF:
    for i in range(len(T)):
        if T[i] < s:
            T[i] = c + s
        else:
            T[i] += c
    append(c + s)

else:
    for t in T + [0]:
        print(t)

Submission status: Wrong Answer

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

# check
T = []
append = T.append
for c, s, f in CSF:
    append(c + s)

    if len(T) > 1:
        for i in range(len(T) - 1):
            if T[i] < s:
                T[i] = c + s
            else:
                T[i] += c

else:
    for t in T + [0]:
        print(t)

Submission status: Wrong Answer

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

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    CSF = []
    for _ in range(N-1):
        c, s, f = MII()
        CSF.append((c, s, f))

    for i in range(N-1):
        t = 0
        for j, (c, s, f) in enumerate(CSF[i:]):
            if j == 0:
                t += s + c
            else:
                if t < s:
                    t += s - t 
                else:
                    if (t - s) % f != 0: 
                        t += (t - s) // f + 1
                t += c
        print(t)
    print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    CSF = []
    for _ in range(N-1):
        c, s, f = MII()
        CSF.append((c, s, f))

    for i in range(N-1):
        t = 0
        for j, (c, s, f) in enumerate(CSF[i:]):
            if j == 0:
                t += s + c
            else:
                if t < s:
                    t += s - t 
                t += c
        print(t)
    print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
cost=[]
start=[]
fre=[]

from math import ceil

for _ in range(n-1):
    c,s,f=map(int,input().split())
    cost.append(c)
    start.append(s)
    fre.append(f)


for i in range(n):
    if i==n-1:
        print(0)
        break

    time=start[i]+cost[i]

    for j in range(i+1,n-1):
        if time>=start[j] and time%fre[j]==0:
            time+=cost[j]
        elif time>=start[j] and time%fre[j]!=0:
            time+=ceil(time/fre[j])+cost[j]
        else:
            time=start[j]+cost[j]

    print(time)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [[0]*3 for i in range(n)]

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

for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        t = max(l[j][1], t)
        t += abs(t - l[j][1])%l[j][2]
        t += l[j][0]
    print(t)

print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [[0]*3 for i in range(n)]

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

for i in range(n):
    t = 0
    if i == n - 1:
        print(t)
        exit()
    for j in range(i, n - 1):
        t = max(l[j][1], t)
        t += (t - l[j][1])%l[j][2]
        t += l[j][0]
    print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
c_s_f = []
for i in range(n-1):
  c_s_f.append(list(map(int,input().split())))
if n == 1:
  print(0)
if n == 2:
  print(c_s_f[0][0] + c_s_f[0][1])
  print(0)
else:
  for i in range(n-1):
    dp = [0 for i in range(n)]
    dp[i+1] = c_s_f[i][0] + c_s_f[i][1]
    for a in range(i+1,n-1):
      if dp[a] <= c_s_f[a][1]:
        dp[a+1] = c_s_f[a][0] + c_s_f[a][1]
      else:
        amari = (dp[a] - c_s_f[a][1]) % c_s_f[a][2]
        if amari == 0:
          dp[a+1] = dp[a] + c_s_f[a][0]
        else:
          dp[a+1] = dp[a] + c_s_f[a][2] - amari + c_s_f[a][2]
    print(dp[-1])
  print(0)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
CSF = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N - 1)]

for i in range(N - 1):
    res = 0
    for c, s, f in CSF[i:]:
        if res < s:
            res = s + c
        elif res % f == 0:
            res += c
        else:
            res += res % f + c
    print(res)
print(0)

Submission status: Wrong Answer

Solution code:
import sys

N = int(input())
CSF = [list(map(int, sys.stdin.readline().rsplit())) for _ in range(N - 1)]

for i in range(N - 1):
    res = 0
    for c, s, f in CSF[i:]:
        if res < s:
            res = s + c
        elif (res - s) % f == 0:
            res += c
        else:
            res += (res - s) % f + c
    print(res)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
CSF = [list(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 += t % f
        else:
            t = s
        t += c
    print(t)

Submission status: Wrong Answer

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

if n ==1:
    print(0)
    exit()

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            if temp <= ab[j+1][1]:
                temp = ab[j+1][1] + ab[j+1][0]
            else:
                if temp % ab[j+1][2] ==0:
                    temp += ab[j+1][0]
                else:
                    temp = (temp//ab[j+1][2])+1 * ab[j+1][2] +ab[j+1][0]
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])

Submission status: Wrong Answer

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

if n ==1:
    print(0)
    exit()

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            if temp % ab[j+1][2] ==0:
                temp += ab[j+1][0]
            else:
                temp = (temp//ab[j+1][2])+1 * ab[j+1][2] +ab[j+1][0]
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])

Submission status: Wrong Answer

Solution code:
from math import ceil
n = int(input())
s_list = [[int(x) for x in input().split()] for _ in range(n - 1)]
ans_list = [0] * n
gap_list = [0] * n
for i in range(n - 2, -1, -1):
    j = i + 1
    t = s_list[i][1] + s_list[i][0]
    if i == n - 2:
        ans_list[i] = t
        continue
    ans_list[i] = ans_list[j]
    temp = s_list[j][1] + gap_list[j] - t
    if temp >= 0:
        gap_list[i] = temp
    else:
        ans_list[i] += ceil((t - s_list[j][1]) / s_list[j][2]) * s_list[j][2]
for ans in ans_list:
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
s_list = [[int(x) for x in input().split()] for _ in range(n - 1)]
ans_list = [0] * n
for i in range(n - 2, -1, -1):
    t = s_list[i][1] + s_list[i][0]
    for j in range(i + 1, n - 1):
        if t <= s_list[j][1]:
            t = ans_list[j]
            break
        t += (t - s_list[j][1]) % s_list[j][2] + s_list[j][0]
    ans_list[i] = t
for ans in ans_list:
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

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

for i in range(n-1):
    cc,ss,ff=map(int,input().split())
    c.append(cc)
    s.append(ss)
    f.append(ff)
#print(f)
for i in range(n-1):
    x=s[i]
    x+=c[i]
    for j in range(i,n-2):
        if x%f[j+1]==0:
            x+=c[j+1]
            continue
        else:
            while x%f[j+1]!=0:
                x+=1
            x+=c[j+1]
    print(x)
print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n - 1)]

    for i in range(n):
        if i == n - 1:
            print(0)
        else:
            x = csf[i][1]
            for j in range(i + 1, n - 1):
                cj1, sj1, fj1 = csf[j - 1]
                cj, sj, fj = csf[j]
                # print(i, j, x, csf[j - 1], csf[j])
                if x + cj1 + (fj1 - x % fj1) % fj1 <= sj:
                    x = sj
                else:
                    x += cj1 + x % fj1
            x += csf[-1][0] + (csf[-1][2] - x % csf[-1][2]) % csf[-1][2]
            print(x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n - 1)]

    for i in range(n):
        if i == n - 1:
            print(0)
        else:
            x = csf[i][1]
            for j in range(i + 1, n - 1):
                cj1, sj1, fj1 = csf[j - 1]
                cj, sj, fj = csf[j]

                if x + cj1 + ((- x) % fj1) <= sj:
                    x = sj
                else:
                    x += cj1 + x % fj1
            x += csf[-1][0] + ((- x) % csf[-1][2])
            print(x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n - 1)]

    for i in range(n):
        if i == n - 1:
            print(0)
        else:
            x = csf[i][1]
            for j in range(i + 1, n - 1):
                cj1, sj1, fj1 = csf[j - 1]
                cj, sj, fj = csf[j]
                if x + cj1 + (fj1 - x % fj1) <= sj:
                    x = sj
                else:
                    x += cj1 + x % fj1
            x += csf[-1][0] + (csf[-1][2] - x % csf[-1][2])
            print(x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n - 1)]

    for i in range(n):
        if i == n - 1:
            print(0)
        else:
            x = csf[i][1]
            for j in range(i + 1, n - 1):
                cj1, sj1, fj1 = csf[j - 1]
                cj, sj, fj = csf[j]
                if x + cj1 + (x % fj1) <= sj:
                    x = sj
                else:
                    x += cj1 + x % fj1
            x += csf[-1][0] + x % csf[-1][2]
            print(x)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n - 1)]

    for i in range(n):
        if i == n - 1:
            print(0)
        else:
            x = csf[i][1]
            for j in range(i + 1, n - 1):
                cj1, sj1, fj1 = csf[j - 1]
                cj, sj, fj = csf[j]
                if x + cj1 <= sj:
                    x = sj
                else:
                    x += x % fj1
                    x += cj1
            print(x + csf[-1][0])


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    C, S, F = [], [], []
    for _ in range(n - 1):
        c, s, f = list(map(int, input().split()))
        C.append(c)
        S.append(s)
        F.append(f)
    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)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

def arrive(time,now):
  if time>a[now][1]:
    time=(time+a[now][2]-1)//a[now][2]*a[now][2]+a[now][0]
  else: time=a[now][1]
  if now==n-2:
    return time
  else:
    return arrive(time,now+1)

for i in range(n-1):
  print(arrive(a[i][1],i))
print(0)

Submission status: Wrong Answer

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

def arrive(time,now):
  time=(time+a[now][2]-1)//a[now][2]*a[now][2]+a[now][0]
  if now==n-2:
    return time
  else:
    return arrive(time,now+1)

for i in range(n-1):
  print(arrive(a[i][1],i))
print(0)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n - 1)]
    
    ans = [0] * n
    ans[-1] = 0
    for i in range(n - 1):
        c, s, f = csf[i]
        ans[i] += c + s
        for j in range(i+1, n - 1):
            c, s, f = csf[j]
            if ans[i] == s:
                ans[i] += c
            elif ans[i] < s:
                ans[i] = c + s
            else:
                ans[i] += c + ((ans[i] - s) % f)
    for i in ans:
        print(i)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    csf = [list(map(int, input().split())) for _ in range(n - 1)]
    
    ans = [0] * n
    ans[-1] = 0
    for i in range(n - 1):
        c, s, f = csf[i]
        ans[i] += c + s
        for j in range(i+1, n - 1):
            c, s, f = csf[j]
            if ans[i] == s:
                ans[i] += c
            elif ans[i] < s:
                ans[i] = c + s
            else:
                ans[i] += c + (ans[i] % f)
    for i in ans:
        print(i)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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