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())
CSF=[list(map(int,input().split())) for _ in range(1,N)]

for i,csf in enumerate(CSF):
    c,s,f=csf[0],csf[1],csf[2]
    ans=c+s
    for j in range(i+1,N-1):
        csf_=CSF[j]
        c_,s_,f_=csf_[0],csf_[1],csf_[2]
        if (ans>=s_) and (ans%f_==0):
            ans+=c_
            continue
        if ans<s_:
            ans+=(s_-ans)
            ans+=(ans%f_)
        else:
            ans+=(ans%f_)
        ans+=c_
    print(ans)
print(0)

Submission status: Wrong Answer

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

for i,csf in enumerate(CSF):
    c,s,f=csf[0],csf[1],csf[2]
    ans=c+s
    for j in range(i+1,N-1):
        csf_=CSF[j]
        c_,s_,f_=csf_[0],csf_[1],csf_[2]
        if (ans>=s_) and (ans%f_==0):
            ans+=c_
            continue
        if ans<s_:
            ans+=(s_-ans)
        ans+=(ans%f_)
        ans+=c_
    print(ans)
print(0)

Submission status: Wrong Answer

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

for i,csf in enumerate(CSF):
    c,s,f=csf[0],csf[1],csf[2]
    ans=c+s
    for j in range(i+1,N-1):
        csf_=CSF[j]
        c_,s_,f_=csf_[0],csf_[1],csf_[2]
        if (ans>=s_) and (ans%f_==0):
            ans+=c_
            continue
        ans+=ans%f_
        if ans<s_:
            ans+=(s_-ans)
            ans+=(ans%f_)
        ans+=c_
    print(ans)
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for j in range(N-1):
  T[j] = C[j] + S[j]
  for i in range(j, N-1):
    if T[j] >= S[i+1] or S[i+1] == 0:
      T[j] = T[j] + C[i+1]
    elif T[j] < S[i+1]:
      T[j] = S[i+1]

T[N-1] = 0
for i in range(N):
  print(T[i])

Submission status: Wrong Answer

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

for j in range(N-1):
  T[j] = C[j] + S[j]
  for i in range(j, N-2):
    if T[j] >= S[i+1] or S[i+1] == 0:
      T[j] = T[j] + C[i+1]
    elif T[j] < S[i+1]:
      T[j] = S[i+1]

T[N-1] = 0
for i in range(N):
  print(T[i])

Submission status: Wrong Answer

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

for j in range(N-1):
  T[j] = C[j] + S[j]
  for i in range(N-2):
    if T[j] >= S[i+1] or S[i+1] == 0:
      T[j] = T[j] + C[i+1]
    elif T[j] < S[i+1]:
      T[j] = S[i+1]

T[N-1] = 0
for i in range(N):
  print(T[i])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

def next_station(Time,s):
    Time+=path[s][0]
    ns=s+1
    if ns==N-1:
        print(Time)
    elif Time<=path[ns][1]:
        Time=path[ns][1]
        next_station(Time,ns)
    else:
        Time+=Time%path[ns][2]
        next_station(Time,ns)

for i in range(N-1):
    next_station(path[i][1],i)
print(0)

Submission status: Wrong Answer

Solution code:
N=int(input())
numbers=[]
for a in range(N-1):
    list=[]
    C,S,F=input().split()
    list.append(int(C))
    list.append(int(S))
    list.append(int(F))
    numbers.append(list)
if N==1:
    print(0)
elif N==2:
    print(numbers[0][0]+numbers[0][1])
    print(0)
else:
    for a in range(N - 1):
        b = numbers[a][0] + numbers[a][1]
        while a < N - 2:
            if b>=numbers[a+1][1]:
                c = b - numbers[a + 1][1]
                d = c / numbers[a + 1][2]
                e = numbers[a + 1][1] + numbers[a + 1][2] * d
                b = e + numbers[a + 1][0]
            else:
                b=numbers[a+1][1]+numbers[a+1][0]
            a+=1
        print(round(b))
    print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(0)

Submission status: Wrong Answer

Solution code:
def main():
  import math
  n=int(input())
  CSF=[list(map(int,input().split())) for _ in [0]*(n-1)]
  t=0
  for i in range(n-1):
    t=CSF[i][1]
    for csf in CSF[i:]:
      c,s,f=csf[0],csf[1],csf[2]
      t=math.ceil(max(s,t)//f)*f+c      
    print(t)
  print(0)
if __name__=='__main__':
  main()

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

Submission status: Wrong Answer

Solution code:
n=int(input())
ab = []
for _ in range(n-1):
    a, b, c = (int(x) for x in input().split())
    ab.append([a, b, c])

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

Submission status: Wrong Answer

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

print(CSF)
ans = [0 for _ in range(N)]

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

for answer in ans :
    print(answer)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
inf = float('inf')
mod = 1000000007
 
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
    N = inputInt()
    csf = []
    for _ in range(N-1):
        c,s,f = inputMap()
        csf.append((c,s,f))
        
    ans = []
    for i in range(N-1):
        c,s,f = csf[i]
        tmp = s+c
        for j in range(i+1,N-1):
            c,s,f = csf[j]
            #print("{} {}".format(tmp,s))
            if tmp < s:
                tmp = tmp + (s-tmp) + c
            else:
                if (tmp-s)%f == 0:
                    tmp = tmp + c
                else:
                    tmp = tmp + (-(-(tmp-s) // f))*f + c
        print(tmp)
        
    print(0)
    
     
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
 
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y
         
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline
 
##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力
 
# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと
 
##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順
 
# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順
 
##### 累乗 #####
# pow(x, y, z) -> x**y % z

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
inf = float('inf')
mod = 1000000007
 
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def main():
    N = inputInt()
    csf = []
    for _ in range(N-1):
        c,s,f = inputMap()
        csf.append((c,s,f))
        
    ans = []
    for i in range(N-1):
        c,s,f = csf[i]
        tmp = s+c
        for j in range(i+1,N-1):
            c,s,f = csf[j]
            #print("{} {}".format(tmp,s))
            if tmp < s:
                tmp = tmp + (s-tmp) + c
            else:
                if (tmp-s)%f == 0:
                    tmp = tmp + c
                else:
                    tmp = tmp + (-(-(tmp-s) // f)) + c
        print(tmp)
        
    print(0)
    
     
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
# special thanks :
#  https://nagiss.hateblo.jp/entry/2019/07/01/185421
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res
 
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
 
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y
         
if __name__ == "__main__":
	main()

Submission status: Wrong Answer

Solution code:
import math
import itertools
import statistics
#n = int(input())
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    x,y,z = [int(j) for j in input().split()]
    c.append(x)
    s.append(y)
    f.append(z)

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

print(0)

Submission status: Wrong Answer

Solution code:
import math
import itertools
import statistics
#n = int(input())
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    x,y,z = [int(j) for j in input().split()]
    c.append(x)
    s.append(y)
    f.append(z)

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

print(0)

Submission status: Wrong Answer

Solution code:
import math
import itertools
import statistics
#n = int(input())
n = int(input())
c = []
s = []
f = []
for i in range(n-1):
    x,y,z = [int(j) for j in input().split()]
    c.append(x)
    s.append(y)
    f.append(z)

total = 0
for i in range(n-1):
    total = 0
    total += s[i]
    total += c[i]
    for j in range(i+1, n-1):
        if total < s[j]:
            total = s[j]
        #total += f[j]
        total += c[j]
    print(total)

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):
    t = S[i]
    while i != (n-1):
        if t < S[i]:  # 最初の列車の発車時刻前に到着
            wait = (S[i] - t)
        else:
            wait = (t - S[i])%F[i]
        t += wait
        move = C[i]
        t += move
        i += 1
    print(t)
print(0)  # すでに駅Nにいる

Submission status: Wrong Answer

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

ans_list=[]

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

for l in range(n):
    print(ans_list[l])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
n -= 1
for i in range(n):
    N, S, F = map(int, input().split())
    a.append([N, S, F])

for i in range(n + 1):
    cnt = 0
    for j in range(i, n):
        # print(i, j,n)
        if j == i:
            cnt += a[j][1] + a[j][0]
        else:
            if cnt >= a[j][1]:
                amari = cnt % a[j][2]
                cnt += a[j][0] - (a[j][2] - amari if amari != 0 else 0)
            else:
                cnt = a[j][1] + a[j][0]
    print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
n -= 1
for i in range(n):
    N, S, F = map(int, input().split())
    a.append([N, S, F])

for i in range(n + 1):
    cnt = 0
    for j in range(i, n):
        # print(i, j,n)
        if j == i:
            cnt += a[j][1] + a[j][0]
        else:
            if cnt >= a[j][1]:
                pass
            else:
                cnt = a[j][1]
            amari = cnt % a[j][2]
            cnt += a[j][0] - (a[j][2] - amari if amari != 0 else 0)
    print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    n=int(input())
    train=[list(map(int,input().split())) for i in range(n-1)]

    for i in range(n-1):
        t=0
        for j in range(i,n-1):
            c=train[j][0]
            s=train[j][1]
            f=train[j][2]
            if t>=s:
                t+=(t+f)%f+c
            else:
                t=s+c
        print(t)
    print(0)
if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
CSFlist = [list(map(int, input().split())) for _ in range(N-1)]
def calc_time(start):
    now = 0
    for i in range(start, N-1):
        C, S, F = CSFlist[i]
        now = max(now, C)
        if now % F != 0:
            now += F - now % F
        now += C
    return now
for _ in range(N-1):
    print(calc_time(_))
print(0)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    csf = list()
    for i in range(n-1):
        csf.append(list(map(int, input().split())))

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

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    n = int(input())
    csf = list()
    for i in range(n-1):
        csf.append(list(map(int, input().split())))

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

Submission status: Wrong Answer

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

    for i in range(n):
        if i == n - 1:
            print(0)
            exit()
        tmp = num_list[i][0] + num_list[i][1]
        for j in range(i+1,n-1):
            if tmp >= num_list[j][1]:
                tmp += num_list[j][0]
            else:
                tmp = num_list[j][1] + num_list[j][0]
            
        print(tmp)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
ans=0
if n>1:
    data=[]
    for _ in range(n-1):
        data_=list(map(int,input().split()))
        data.append(data_)
    if n>2:
        for i in range(0,n-2):
            time=data[i][1]
            for j in range(i,n-2):
                arrive=time+data[j][0]
                s=data[j+1][1]
                if arrive<=s:
                    time=s
                else:
                    f=data[j+1][2]
                    time=s+f*(math.floor((arrive-s)//f))
            time+=data[n-2][0]
            print(time)
    time=data[n-2][0]+data[n-2][1]
    print(time)
print(ans)

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):
    ans = 0
    for j in range(i, n-1):
        if csf[j][1] >= ans:
            ans = csf[j][0] + csf[j][1]
        else:
            ans += csf[j][0] + ans % csf[j][2]
    print(ans)

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):
    ans = 0
    for j in range(i, n-1):
        if csf[j][1] >= ans:
            ans = csf[j][0] + csf[j][1]
        else:
            ans += csf[j][0] + (ans - csf[j][1]) % csf[j][2]
    print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil


def get_required_time(trains, station_num, station):
    arrival = [0] * station_num
    for i in range(station, station_num):
        if arrival[i - 1] < trains[i - 1][1]:
            arrival[i] = trains[i - 1][0] + trains[i - 1][1]
        else:
            arrival[i] = trains[i - 1][0] + trains[i - 1][2] * ceil(arrival[i - 1] / trains[i - 1][2])
    return arrival


def main():
    station_num = int(input())
    trains = [list(map(int, input().split())) for _ in range(station_num - 1)]
    for i in range(station_num):
        arrival = get_required_time(trains, station_num, i)
        if i == 0:
            answer = arrival[-1]
        elif i == station_num - 1:
            answer = 0
        else:
            answer = min(arrival[-1] - arrival[i] + trains[i][1], arrival[-1])
        print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil


def main():
    station_num = int(input())
    trains = [list(map(int, input().split())) for _ in range(station_num - 1)]
    arrival = [0] * station_num
    for i in range(1, station_num):
        if arrival[i - 1] < trains[i - 1][1]:
            arrival[i] = trains[i - 1][0] + trains[i - 1][1]
        else:
            arrival[i] = trains[i - 1][0] + trains[i - 1][2] * ceil(arrival[i - 1] / trains[i - 1][2])
    for i in range(station_num):
        if i == 0:
            answer = arrival[-1]
        elif i == station_num - 1:
            answer = 0
        else:
            answer = min(arrival[-1] - arrival[i] + trains[i][1], arrival[-1])
            if i < station_num - 2:
                # 駅Nへの所要時間は単調非減少
                next_i = min(arrival[-1] - arrival[i + 1] + trains[i + 1][1], arrival[-1])
                if answer < next_i:
                    answer = next_i
        print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    station_num = int(input())
    trains = [list(map(int, input().split())) for _ in range(station_num - 1)]
    arrival = [0] * station_num
    for i in range(1, station_num):
        arrival[i] = trains[i - 1][0] + max(arrival[i - 1] + abs(arrival[i - 1] % (-trains[i - 1][2])), trains[i - 1][1])
    for i in range(station_num):
        if i == 0:
            answer = arrival[-1]
        elif i == station_num - 1:
            answer = 0
        else:
            answer = min(arrival[-1] - arrival[i] + trains[i][1], arrival[-1])
            if i < station_num - 2:
                # 駅Nへの所要時間は単調非減少
                next_i = min(arrival[-1] - arrival[i + 1] + trains[i + 1][1], arrival[-1])
                if answer < next_i:
                    answer = next_i
        print(answer)


if __name__ == '__main__':
    main()

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):
    ca,sa,fa = list(map(int,input().split()))
    C[i] = ca
    S[i] = sa
    F[i] = fa
time = [0] * N
for i in range(N-1):
    t = C[i]+S[i]
    for j in range(i+1,N-1):
        if t<= S[j]:
            t = S[j]
        else:
            d = t - S[j]
            k = d // F[j]
            m = d % F[j]
            if m != 0:
                t = S[j] + (k+1) * F[j]
            t += C[j]
    time[i] = t
for i in range(N):
    print(time[i])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
for _ in range(N - 1):
    C, S, F = map(int, input().split())
    ans.append(S + C)
    for i in range(len(ans) - 1):
        if ans[i] <= S:
            ans[i] = S + C
        else:
            start = F * ((ans[i] - S) // F + 1)
            ans[i] += start + C

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

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = []
for _ in range(N - 1):
    C, S, F = map(int, input().split())
    ans.append(S + C)
    for i in range(len(ans) - 1):
        if ans[i] < S:
            ans[i] = S + C
        else:
            wait = (ans[i] - S) % F
            ans[i] += wait + C

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

Submission status: Wrong Answer

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

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

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(n):
    time=0
    now=i
    while now < n-1:
        if time > l[now][1]:
            wait = (time - l[now][1]) % l[now][2]
            time+= wait + l[now][0]
        else:
            time+=l[now][1] - time + l[now][0]
        now+=1

    print(time)

Submission status: Wrong Answer

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

for n in range(N):
  if n == N - 1:
    print(0)
    break
  
  ans = 0
  for index, i in enumerate(li):
    if index < n:
      continue

    if ans < i[1]:
      ans = i[1]
    else:
      if (ans - i[1]) % i[2] != 0:
        ans += (ans - i[1]) % i[2]

    ans += i[0]
  print(ans)

Submission status: Wrong Answer

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

for n in range(N):
  if n == N - 1:
    print(0)
    break
  
  ans = 0
  for index, i in enumerate(li):
    if index < n:
      continue

    if ans < i[1]:
      ans = i[1]
    else:
      if (ans - i[1]) % i[2] != 0:
        ans += (ans % i[1]) % i[2]

    ans += i[0]
  print(ans)

Submission status: Wrong Answer

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

for n in range(N):
  if n == N - 1:
    print(0)
    break
  
  ans = 0
  for index, i in enumerate(li):
    if index < n:
      continue

    if ans < i[1]:
      ans = i[1]
    else:
      if (ans - i[1]) % i[2] != 0:
        ans += abs(i[2] - (ans % i[1]))

    ans += i[0]
  print(ans)