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:
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
#def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s + c
        elif (time - s) % f != 0:
            time += (f - (time - s) % f) + c#待ち時間を足す
    print(time)
    
def main2():    
    for i in range(n-1):
        main(i)
    print(0)
main2()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for i in range(j,n-1):
        c, s, f = mylist[i]
        if time < s:
            time = s + c
        if (time - s) % f != 0:
            time += (f - (time - s) % f) #待ち時間を足す
        time += c
    print(time)
    
def main2():    
    for i in range(n-1):
        main(i)
    print(0)
main2()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for c, s, f in mylist:
        if time < s:
            time = s
        if (time - s) % f != 0:
            time += (f - (time - s) % f) #待ち時間を足す
        time += c
    print(time)
    
    
for i in range(n-1):
    main(i)
print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for c, s, f in mylist:
        if time < s:
            time = s
        if (time - s) % f != 0:
            time += (f - (time - s) % f) #待ち時間を足す
        time += c
    print(time)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

def main(j):
    time = 0
    for c, s, f in mylist:
        if time < s:
            time = s + c
        if (time - s) % f != 0:
            time += (f - (time - s) % f) #待ち時間を足す
        time += c
    print(time)
    
    
for i in range(n-1):
    main(i)
print(0)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
import numpy as np

 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n = I()
mylist = tuple(tuple(MI()) for i in range(n-1))

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

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
c=[]
s=[]
f=[]
if n==1:
    print(0)
    sys.exit()
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):
    tmp=0
    while i<n-1:
        if tmp<=s[i]:
            a=s[i]
        elif tmp%f[i]==0:
            a=s[i]+f[i]
        elif tmp>s[i]:
            b=(tmp-s[i])%f[i]
            a=tmp+b
        tmp=a+c[i]
        i+=1
    print(tmp)
print(0)

Submission status: Wrong Answer

Solution code:
import sys
n=int(input())
c=[]
s=[]
f=[]
if n==1:
    print(0)
    sys.exit()
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):
    tmp=0
    while i<n-1:
        if tmp<=s[i]:
            a=s[i]
        elif tmp>s[i]:
            b=(tmp-s[i])%f[i]
            a=tmp+b
        tmp=a+c[i]
        i+=1
    print(tmp)
print(0)

Submission status: Wrong Answer

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):
    tmp=s[i]
    while i<n-1:
        if tmp<=s[i]:
            a=s[i]
        elif tmp>s[i]:
            a=tmp+(tmp-s[i])%f[i]
        tmp=a+c[i]
        i+=1
    print(tmp)
print(0)

Submission status: Wrong Answer

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

ans = 0
memo = {}
memoset = set()
def dfs(i, time):
    if i==N-1:
        return time
    c, s, f = CSF[i]
    if time<s:
        time = s
    elif time%f!=0:
        time = time//f+f
    if (time, i) in memoset:
        return memo[(time, i)]
    T = dfs(i+1, time+c)
    memo[(time, i)] = T
    memoset.add((time, i))
    return T

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

Submission status: Wrong Answer

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

for i in range(n-1):
  t=l[i][1]
  t+=l[i][0]
  for j in range(i+1,n-1):
    if t<l[j][1]:
      t=l[j][1]
    elif t%l[j][2]!=0:
      t+=t%l[j][2]
    t+=l[j][0]

  print(t)
print(0)

Submission status: Wrong Answer

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

for i in range(n-1):
  t=l[i][1]
  t+=l[i][0]
  for j in range(i+1,n-1):
    temp_t=t-l[j][1]
    if temp_t<0:
      t=l[j][1]
    elif temp_t%l[j][2]!=0:
      t+=temp_t%l[j][2]
    t+=l[j][0]

  print(t)
print(0)

Submission status: Wrong Answer

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

for i in range(n-1):
  j=i
  t=l[j][1]
  t+=l[j][0]
  while j<n-2:
    j+=1
    temp_t=t-l[j][1]
    if temp_t<0:
      t=l[j][1]
    elif temp_t%l[j][2]!=0:
      t+=temp_t%l[j][2]
    t+=l[j][0]

  print(t)
print(0)

Submission status: Wrong Answer

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

ans = 0
memo = {}
memoset = set()
def dfs(i, time):
    if i==N-1:
        return time
    c, s, f = CSF[i]
    if time<s:
        time = s
    elif time%f!=0:
        time = time//f+1
    if (time, i) in memoset:
        return memo[(time, i)]
    T = dfs(i+1, time+c)
    memo[(time, i)] = T
    memoset.add((time, i))
    return T

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

Submission status: Wrong Answer

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

ans = 0
memo = {}
memoset = set()
def dfs(i, time):
    if i==N-1:
        return time
    c, s, f = CSF[i]
    if time<s:
        time = s
    if (time, i) in memoset:
        return memo[(time, i)]
    T = dfs(i+1, time+c)
    memo[(time, i)] = T
    memoset.add((time, i))
    return T

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

Submission status: Wrong Answer

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

ans = 0
memo = {}
memoset = set()
def dfs(i, time):
    if i==N-1:
        return time
    c, s, f = CSF[i]
    if time<s:
        time = s
    if (time, i) in memoset:
        return memo[(time, i)]
    T = dfs(i+1, time+c)
    memo[(time, i)] = T
    return T

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

Submission status: Wrong Answer

Solution code:
n = int(input())
loss = []

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [list(map(int,input().split())) for _ in range(N-1)]
A.insert(0,0)
B = [0 for _ in range(N+1)]
for i in range(1,N):
    C1,S1,F1 = A[i]
    T = S1
    for j in range(i+1,N):
        C2,S2,F2 = A[j]
        dt = (T+C1)%F2
        T += dt+C1
        C1 = C2
        S1 = S2
        F1 = F2
    T += C1
    B[i] = T
for i in range(1,N+1):
    print(B[i])

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):
        if t <= L[j][1]:
            s = L[j][1]
        else:
            if t % L[j][1]:
                s = t + L[j][2] - (t % L[j][1])
            else:
                s = t
        t = s + L[j][0]
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

stations = [tuple(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 = stations[j]
        t = max(t, s)
        t += t % f
        t += c
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
CC = [0] * (N-1)
SS = [0] * (N-1)
FF = [0] * (N-1)

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

for i in range(N-1):
    T = 0
    Max = 0
    for k in range(i,N-1):
        Max = max(T, SS[k])
        U = Max % FF[k]
        T = Max - U + FF[k] + CC[k]
        #print(i,k,T)
    print(T)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
CC = [0] * (N-1)
SS = [0] * (N-1)
FF = [0] * (N-1)

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

for i in range(N-1):
    T = 0
    Max = 0
    for k in range(i,N-1):
        Max = max(T, SS[k])
        U = Max % FF[k]
        T = Max + U + CC[k]
        #print(i,k,T)
    print(T)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
CC = [0] * (N-1)
SS = [0] * (N-1)
FF = [0] * (N-1)

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

for i in range(N-1):
    T = 0
    Max = 0
    for k in range(i,N-1):
        Max = max(T, SS[k])
        T = (Max // FF[k]) * FF[k] + CC[k]
        #print(i,k,T)
    print(T)
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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][1]) // csf[j][2] + 1) * csf[j][2] + csf[j][0]
    ans.append(tmp)
ans.append(0)

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

Submission status: Wrong Answer

Solution code:
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][1] // csf[j][2] + 1) * csf[j][2] + csf[j][0]
    ans.append(tmp)
ans.append(0)

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split())) for _ in range(n-1)]
ans=[]
for i in range(n-1):
    now=0
    for j in range(i,n-1):
        c,s,f=a[j]
        if s==now:
            d=0
        elif s>now:
            d=s-now
        else:
            d=f*(now%f)-now%f
        now+=c+d
    ans+=[now]  
ans+=[0]    
print(*ans,sep="\n")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[list(map(int,input().split())) for _ in range(n-1)]
ans=[]
for i in range(n-1):
    now=a[i][0]+a[i][1]
    for j in range(i+1,n-1):
        c,s,f=a[j]
        if s==now:
            d=0
        elif s>now:
            d=s-now
        else:
            d=now%f
        now+=c+d
    ans+=[now]  
ans+=[0]    
print(*ans,sep="\n")

Submission status: Wrong Answer

Solution code:
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]
        print(i, j, time)
    ans[i] = time

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
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()))


# ===CODE===


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 += (time - s) % f
            time += c

        print(time)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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)
    return dfs(eki+1, ss+m*ff+cc)

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

Submission status: Wrong Answer

Solution code:
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 = max(0,-(-t+ss)//ff)
        return dfs(eki+1, ss+m*ff+cc)

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

Submission status: Wrong Answer

Solution code:
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]

    t = max(ss,t)

    return dfs(eki+1, -(-t)//ff*ff+cc)

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

Submission status: Wrong Answer

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

ans = [0]*n

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

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

Submission status: Wrong Answer

Solution code:
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]

    return dfs(eki+1, max(ss, -(-t)//ff*ff)+cc)

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

Submission status: Wrong Answer

Solution code:
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]

    return dfs(eki+1, max(ss, -(-t)//ff*ff)+cc)

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

Submission status: Wrong Answer

Solution code:

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]
            ans[j-i] += (ans[j-i] % Fs[j]) + Cs[j]

    ans_fix[N-2-i] = True

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:

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]
            ans[j-i] += ((ans[j-i] - Ss[j]) % Fs[j]) + Cs[j]

    ans_fix[N-2-i] = True

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:

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]:
            if ans[j-i] <= Ss[j]:
                ans[j-i] = Ss[j]
            ans[j-i] += ((ans[j-i] - Ss[j]) % Fs[j]) + Cs[j]

            if i == j:
                ans_fix[j] = True

for a in ans:
    print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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:
        # print(eki,t)
        return t

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


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

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

Submission status: Wrong Answer

Solution code:
for i in range(1,int(input())):
 c,s,f=map(int,input().split())
 l=0
 for j in range(i):l=max(-l//f*-f,s)+c
 print(l)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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
        else:
            t += t % f
        t += c
    print(t)

Submission status: Wrong Answer

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):
    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 += math.ceil(tmp / f[j]) + c[j]
    ans[i] = t
    print(t)
print(0)

Submission status: Wrong Answer

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):
    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 tmp % f[j] == 0:
                t += c[j]
            else:
                t += math.ceil(tmp / f[j]) + c[j]
    ans[i] = t
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
CSF = []
for i in range(N-1):
    csf = list(map(int, input().split()))
    CSF.append(csf)
# print("CSF: {}".format(CSF))

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

    print(ans)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
CSF = []
for i in range(N-1):
    csf = list(map(int, input().split()))
    CSF.append(csf)
# print("CSF: {}".format(CSF))

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

    print(ans)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
CSF = []
for i in range(N-1):
    csf = list(map(int, input().split()))
    CSF.append(csf)
# print("CSF: {}".format(CSF))

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
        ans += c
    print(ans)
print(0)

Submission status: Wrong Answer

Solution code:
n=int(input()) #　a1
csf= [list(map(int, input().split())) for i in range(n-1)] #a1 a2 a3 // b1 b2 b3

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

Submission status: Wrong Answer

Solution code:
n=int(input()) #　a1
csf= [list(map(int, input().split())) for i in range(n-1)] #a1 a2 a3 // b1 b2 b3

for i in range(n):
  t=0
  for j in range(i,n-1):
 #   print('1ka',t)
    if t<=csf[j][1]:
      t=csf[j][1]
    else:
      t=t+csf[j][2]-(t%csf[j][2])
  #  print('2ka',t)
    t+=csf[j][0]
  print(t)

Submission status: Wrong Answer

Solution code:
n=int(input()) #　a1
csf= [list(map(int, input().split())) for i in range(n-1)] #a1 a2 a3 // b1 b2 b3

for i in range(n):
  t=0
  for j in range(i,n-1):
 #   print('1ka',t)
    if t<=csf[j][1]:
      t=csf[j][1]
    else:
      t=t-(t%csf[j][2])
  #  print('2ka',t)
    t+=csf[j][0]
  print(t)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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[i][2] == 0:
            pass
        else:
            t += c[j][1] - t%c[j][2]
        t += c[j][0]
    print(t)

Submission status: Wrong Answer

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

import math
for i in range(n):
    t = 0
    for j in range(i,n-1):
        if t < csf[j][1]:
            t = csf[j][1]
        elif t % csf[j][2] == 0:
            pass
        else:
            t = math.ceil(t/csf[j][2])
        t = t + csf[j][0]
    print(t)

Submission status: Wrong Answer

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

ans = []
for i in range(n-1):
    c,s,f = pair[i]
    cnt = s + c
    for j in range(i+1,n-1):
        c,s,f = pair[j]
        s_ = ((cnt - 1)//f+1 )*f
        cnt = s_ + c
    print(cnt)
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
pair = []
ns = []

prev = 0
for i in range(n-1):
    c,s,f = map(int, input().split())
    pair.append((c,s,f))
    # print(s+c)
    n = max(prev-s,0)//f
    ns.append((f,n))
    prev = s+c+n*f
# print(ns)
for f,n in ns:
    print(prev-n*f)
print(0)