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())
C=[]
S=[]
F=[]

for i in range(N-1):
    a = input().split()
    C.append(int(a[0]))
    S.append(int(a[1]))
    F.append(int(a[2]))

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

for i in Time_list:
    print(i)

Submission status: Wrong Answer

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

for i in range(N-1):
    a = input().split()
    C.append(int(a[0]))
    S.append(int(a[1]))
    F.append(int(a[2]))

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

for i in Time_list:
    print(i)

Submission status: Wrong Answer

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

for i in range(N-1):
    a = input().split()
    C.append(int(a[0]))
    S.append(int(a[1]))
    F.append(int(a[2]))

Time_list=[]
for i in range(N):
    cnt=0
    for j in range(i,N-1):
        if cnt <= S[j]:
            cnt = S[j] + C[j]
        elif cnt % F[j] == 0:
            cnt += C[j]
        else:
            cnt = cnt + F[j] - (cnt % F[j])
    Time_list.append(cnt)

for i in Time_list:
    print(i)

Submission status: Wrong Answer

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

for i in range(N-1):
    a = input().split()
    C.append(int(a[0]))
    S.append(int(a[1]))
    F.append(int(a[2]))

Time_list=[]
for i in range(N):
    cnt=0
    for j in range(i,N-1):
        if cnt <= S[j]:
            cnt = S[j] + C[j]
        elif cnt % F[j] == 0:
            cnt += C[j]
        else:
            cnt = cnt + F[j] - (cnt % F[j])
    Time_list.append(cnt)
print(Time_list)

Submission status: Wrong Answer

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

for i in range(N-1):
    a = input().split()
    C.append(int(a[0]))
    S.append(int(a[1]))
    F.append(int(a[2]))

Time_list=[]
for i in range(N):
    cnt=0
    for j in range(i,N-1):
        if cnt <= S[j]:
            cnt = S[j] + C[j]
        else:
            x=0
            while cnt > S[j] + x:
                x += F[j]
            cnt = C[j] + S[j] + x
    Time_list.append(cnt)
print(Time_list)

Submission status: Wrong Answer

Solution code:
N = int(input())
C,S,F = [],[],[]
time = []
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):
  t = S[i]+C[i] #駅i -> 駅i+1
  for j in range(i+1,N-1):
    if(t<S[j]): #始発前についたら
     t = S[j]
    else: #始発後についたら(次発以降のとき）
     tmp = (t-S[j])%F[j]
     t += tmp
    t += C[j] #駅j -> 駅j+1
  time.append(t)
time.append(0)

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

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):
    ans = S[i] + C[i]
    j = i + 1
    while j < n-1:
        if ans <= S[j]:
            ans += (S[j] - ans) + C[j]
        else:
            if (ans-S[j])%F[j] == 0:
                ans += C[j]
            else:
                ans += C[j] + F[j]
        j += 1
    print(ans)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

min_time = [0 for _ in range(N)]
for i in range(N-1):
    speed, start, interval = map(int, input().split())
    min_time[i] += start + speed
    for j in range(i):
        if min_time[j] - start <= 0:
            min_time[j] = start
        else:
            min_time[j] += interval - ((min_time[j] - start) % interval)
        min_time[j] += speed

for ans in min_time:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

min_time = [0 for _ in range(N)]
for i in range(N-1):
    speed, start, interval = map(int, input().split())
    min_time[i] += start + speed
    for j in range(i):
        if min_time[j] - start < 0:
            min_time[j] = start
        else:
            min_time[j] += interval - ((min_time[j] - start) % interval)
        min_time[j] += speed

for ans in min_time:
    print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

min_time = [0 for _ in range(N)]
for i in range(N-1):
    speed, start, interval = map(int, input().split())
    min_time[i] += start + speed
    for j in range(i):
        if min_time[j] - start < 0:
            min_time[j] -= min_time[j] - start
        else:
            min_time[j] += (min_time[j] - start) % interval
        min_time[j] += speed

for ans in min_time:
    print(ans)

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=0
  for j in range(i,n-1):
    t=max(t,l[j][1])
    if t%l[j][2]!=0:
      t=(t%l[j][2]+1)*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=0
  for j in range(i,n-1):
    if t<l[j][1]:
      t=l[j][1]
    if t%l[j][2]!=0:
      t=(t%l[j][2]+1)*l[j][2]
    t+=l[j][0]
  print(t)
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
total = 0
diff = []
st = []

for i in range(n-1):
    c2, s2, f2 = map(int, input().split())
    if total < s2:
        d = s2 - total + c2
        total += d
        diff.append(d)
    else:
        if (total-s2)%f2 == 0:
            total += c2
            diff.append(c2)
        else:
            while(total < s2):
                s2 += f2
            d = total - s2 + c2
            total += d
            diff.append(d)
    st.append(s2)

print(diff)
sum = sum(diff)
print(sum)

for d, s in zip(diff, st[1:]):
    sum -= d - s
    print(sum)

Submission status: Wrong Answer

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

for i in range(n):
    total_time = 0
    for c, s, f in csf[i:]:
        time = 0
        # wait for start
        if total_time < s:
            time += s - total_time
        # wait for next train
        else:
            time += total_time % f
        # take train
        time += c
        total_time += time
    print(total_time)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)


N = I()
CSF = []
for i in range(1, N):
    CSF.append(LI())

for i in range(N-1):
    # i駅から出発する場合
    current = i
    time = 0
    for csf in CSF[i:]:
        if time < csf[1]:
            # timeのほうが小さい場合、初発まで待つ
            time = csf[1] + csf[0]
        else:
            # timeが初発を超えていた場合、きりのいい次発までまつ
            rest = time - csf[1]
            div = rest % csf[2]
            time += div
            time += csf[0]
        current += 1
    print(time)

print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
stack = [0]
queue = []
for i in range(n-1):
  c,s,f = (int(i) for i in input().split())
  queue.append((c,s,f))
for i in range(n):
 ans = 0
 for j in range(n-i-1):
   c,s,f = queue[i+j]
   #print(c,s,f)
   if s >= ans:
    ans = s+c
   else:
     if ans%f == 0:
      ans +=c
     elif ans%f != 0:
      ans += ans%f+c
 if n-i-1 == 0:
  ans = 0
 print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
  x,y,z=map(int,input().split())
  c.append(x)
  s.append(y)
  f.append(z)
def needtime(t,i):
  if s[i]>=t:
    T=s[i]
  else:
    T=t+f[i]-(t-s[i])%f[i]
  return T+c[i]
for i in range(n):
  t=0
  for j in range(i,n-1):
    t=needtime(t,j)
  print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for _ in range(n-1):
    l.append([int(i) for i in input().split()])
for j in range(n):
    l_ = l[j:]
    c = 0
    for i in range(n-1-j):
        c = max(c, l_[i][1])
        c += l_[i][0]
    print(c)

Submission status: Wrong Answer

Solution code:
N = int(input())
train = [[] for _ in range(N)]
take_time = []
for cnt in range(N - 1):
    x, y , z = map(int,input().split())
    take_time.append(x)
    for _ in range(10**3):
        train[cnt].append(y)
        y += z

from bisect import bisect_left
for place in range(N):
    now = 0
    for i in range(place,N - 1):
        try:
            index = bisect_left(train[i],now)
            now = train[i][index]
            now += take_time[i]
        except:
            pass
    print(now)

Submission status: Wrong Answer

Solution code:
N = int(input())
tc,ts,tf = 0,0,0
C, S, F, =[], [], []
t = 0
for i in range(N-1):
    tc,ts,tf = map(int,input().split())
    C.append(tc)
    S.append(ts)
    F.append(tf)
#print(C,S,F)
for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        t = max(t,S[j])+C[j]
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
tc,ts,tf = 0,0,0
C, S, F, =[], [], []
t = 0
for i in range(N-1):
    tc,ts,tf = map(int,input().split())
    C.append(tc)
    S.append(ts)
    F.append(tf)
print(C,S,F)
for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        t = max(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)]

# print(csf)

for i in range(n-1):

    ans = csf[i][0] + csf[i][1]

    for j in range(i+1,n-1):
        here = csf[j]
        
        ans = max(ans,here[1])
        
        rm = ans % here[2]
        if rm != 0:
            ans += rm
            
        ans += here[0]

#        print(ans)
    print(ans)

print(0)

Submission status: Wrong Answer

Solution code:

n = int(input())


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

# print(csf)

for i in range(n-1):

    ans = csf[i][0] + csf[i][1]

    for j in range(i+1,n-1):
        here = csf[j]
        
        ans = max(ans,here[1])
        
        rm = (ans - here[1]) % here[2]
        if rm != 0:
            ans += rm
            
        ans += here[0]

#        print(ans)
    print(ans)

print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
inputs = [list(map(int, input().split())) for i in range(N-1)]
if len(inputs) != N:
  inputs. append([0, 0, 1])

for i in range(N):
  reach = 0
  for j in range(i, N):
    info = inputs[j]
    if reach < info[1]:
      reach = info[1]
    reach += info[0]+ (reach-info[1])%info[2]
  print(reach)

Submission status: Wrong Answer

Solution code:
N = int(input())
inputs = [list(map(int, input().split())) for i in range(N-1)]
if len(inputs) != N:
  inputs. append([0, 0, 1])

for i in range(N):
  reach = 0
  for j in range(i, N):
    info = inputs[j]
    if reach < info[1]:
      reach = info[1]
    reach += info[0] + reach%info[2]
  print(reach)

Submission status: Wrong Answer

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

for i in range(N-1):
  reach = 0
  for j in range(i, N-1):
    info = inputs[j]
    if reach < info[1]:
      reach = info[1]
    reach += info[0] + reach%info[2]
  print(reach)
print(0)

Submission status: Wrong Answer

Solution code:
n=int(input())
ls=[]
for i in range(n-1):
  c,s,f=map(int,input().split())
  ls.append(s)
  ls=list(map(lambda x:(x+c+(0 if x%f==0 else x%f) if s<=x else s+c),ls))

ls=ls+[0]
print(*ls,sep="\n")

Submission status: Wrong Answer

Solution code:
def tcalc(station):
  time = 0
  for i in range(station-1,n-1):
    f = l[i][2]
    s = l[i][1]
    c = l[i][0]
    time = max(((time-1)//f+1)*f, s)+c
  return time
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n-1)]
for i in range(1,n):
  print(tcalc(i))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
e = [[int(i) for i in input().split()] for i in range(n-1)]

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

result = [0, e[-1][0]+e[-1][1]]
if n==2:
    for x in result[::-1]:
        print(x)
    exit()

if n > 2:
    for i in range(1,n-1):
        a = e[-i-1][0] + e[-i-1][1]
        if a <= e[-i][1]:
            result.append(result[-1]) 

        b = math.ceil((a - e[-i][1]) / e[-i][2])
        result.append(result[-1]+b* e[-i][2])
        #print(e[-i])

for x in result[::-1]:
    print(x)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
ans = []
for i in range(len(l)):
    m = l[i][1]
    for j in range(i,len(l)):
        if m<l[j][1]:
            m = l[j][1]+l[j][0]
        elif m==l[j][1] or (m-l[j][1])%l[j][2]==0:
            m += l[j][0]
        else:
            next = l[j][1]+l[j][2]*m//l[j][2]+l[j][2]-2*m
            m += next+l[j][0]
    ans.append(m)
ans.append(0)
for i in ans:
    print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
ans = []
for i in range(len(l)):
    m = l[i][1]
    for j in range(i,len(l)):
        if m<l[j][1]:
            m = l[j][1]+l[j][0]
        elif m==l[j][1] or (m-l[j][1])%l[j][2]==0:
            m += l[j][0]
        else:
            m += (m-l[j][1])%l[j][2]+l[j][0]
    ans.append(m)
ans.append(0)
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):
    res = 0
    for j in range(i, n-1):
        if res < csf[j][1]:
            res += abs(csf[j][1] - res)
            res += csf[j][0]
        else:
            res += (res - csf[j][1]) % csf[j][2]
            res += csf[j][0]
    print(res)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
time = [0 for _ in range(n)]

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

for t in time:
  print(t)

Submission status: Wrong Answer

Solution code:
n = int(input())
time = [0 for _ in range(n)]

for i in range(n-1):
  c, s, f = map(int, input().split())
  for j in range(0, i+1):
    time[j] = max(time[j] // f * f, s) + c

for t in time:
  print(t)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#ABC084C
N=int(input())
csf=[]
for n in range(N-1):
	csf.append(list(map(int,input().split())))
for nn in range(N):
	#print(nn)
	t=0
	for n in range(nn,N-1):
		#print(" ",n)
		if t>csf[n][1]:
			t=csf[n][1]+((t-csf[n][1])//csf[n][2])*csf[n][2]+csf[n][0]
			#t=S+((t-S)//F+1)*F+C
		else:
			t=csf[n][1]+csf[n][0]
		#print(" ",t)
	print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
p=[list(map(int,input().split()))for i in range(n-1)]
for i in range(n):
    c=0
    d=p[i:]
    for j in range(n-i-1):
        if c<d[j][1]:
            c+=d[j][1]+d[j][0]
        else:
            c+=((c-1)//d[j][2]+1)*d[j][2]+d[j][0]-c
    else:
        print(c)

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 j in range(n-i-1):
        c,s,f=CSF[i+j][0],CSF[i+j][1],CSF[i+j][2]
        if t<=s:
            t=s+c
        elif t%f==0:
            t+=c
        else:
            t=(t%f+1)*f+c
    print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
X=[]
for _ in range(n-1):
    T=list(map(int,input().split()))
    X.append(T)
if n==1:
    print(0)
elif n==2:
    print(X[n-2][0]+X[n-2][1])
else:
    A=[0]*n
    A[1]=X[n-2][0]+X[n-2][1]
    for i in range(n-2):
        tmp=X[n-i-3][0]+X[n-i-3][1]
        if tmp<=A[i+1]:
            A[i+2]=A[i+1]
        else:
            k=(tmp-X[n-i-2][1])//X[n-i-2][2]
            l=(tmp-X[n-i-2][1])%X[n-i-2][2]
            if l==0:
                A[i+2]=A[i+1]+k*X[n-i-2][2]
            else:
                A[i+2]=A[i+1]+(k+1)*X[n-i-2][2]
    for i in range(n):
        print(A[n-i-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
X=[]
for _ in range(n-1):
    T=list(map(int,input().split()))
    X.append(T)
if n==1:
    print(0)
elif n==2:
    print(X[n-2][0]+X[n-2][1])
else:
    A=[0]*n
    A[1]=X[n-2][0]+X[n-2][1]
    for i in range(n-2):
        tmp=X[n-i-3][0]+X[n-i-3][1]
        if tmp<=X[n-i-2][1]:
            A[i+2]=A[i+1]
        else:
            A[i+2]=A[i+1]+((tmp-X[n-i-2][1])//X[n-i-2][2])*X[n-i-2][2]
    for i in range(n):
        print(A[n-i-1])

Submission status: Wrong Answer

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

def calculate(i):
  time=ls[i][1]+ls[i][0]
  for j in range(i+1,len(ls)):
    if time<ls[j][1]:
      time=ls[j][1]+ls[j][0]
    elif time %ls[j][2]==0:
      time+=ls[j][0]
    else:
      time+=ls[j][1]+ls[j][2]-time%ls[j][2]
  return time

for i in range(len(ls)):
  ans.append(calculate(i))
ans.append(0)
for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
trains = [ [int(j) for j in input().split()] for _ in range(N-1)] + [(0,0,0)]
dp = [float("inf") for _ in range(N-1)] + [0] # N-1

t = trains[N-2]
dp[N-2] = t[0]+t[1]
limited_by = [0 for _ in range(N)]
limited_by[N-2] = t[1]

for i in range(N-3, -1, -1):
    c,s,f = trains[i]
    nc,ns,nf = trains[i+1]
    arrive_at = c+s # start with A : B # at next station

    if arrive_at < limited_by[i+1]:
        dp[i] = dp[i+1]
        limited_by[i] = limited_by[i+1] -c 

    else:
        dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - ns
        limited_by[i] = s

for i in range(N): print(dp[i])
# print(limited_by)



# print(dp)
# 
# 
# for i in range(N-3, -1, -1):
#     c,s,f = trains[i]
#     nc,ns,nf = trains[i+1]
#     arrive_at = c+s
#     # print("i: ", i, "c,s,f: ", c,s,f, end=" ")
#     # print("arrive_at: ", arrive_at, end=" ")
#     # print(" arrive_at<ns: ", arrive_at < ns)
# 
#     if arrive_at < ns:
#         dp[i] = dp[i+1]
#         limited_by[i] = ns - c
#     elif arrive_at < limited_by[i+1]:
#         dp[i] = dp[i+1]
#         limited_by[i] = limited_by[i+1] - c
#     else:
#         # print("arrive_at: ", arrive_at, "f: ", f, "dp[i+1] : ", dp[i+1], "ns: ", ns)
#         dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - ns
#

Submission status: Wrong Answer

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
trains = [ [int(j) for j in input().split()] for _ in range(N-1)] + [(0,0,0)]
dp = [float("inf") for _ in range(N-1)] + [0] # N-1

t = trains[N-2]
dp[N-2] = t[0]+t[1]
limited_by = [0 for _ in range(N)]
limited_by[N-2] = t[1]

for i in range(N-3, -1, -1):
    c,s,f = trains[i]
    nc,ns,nf = trains[i+1]
    arrive_at = c+s # start with A : B # at next station

    if arrive_at < limited_by[i+1]:
        dp[i] = dp[i+1]
        limited_by[i] = limited_by[i+1] -c 

    else:
        dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - limited_by[i+1]
        limited_by[i] = s

for i in range(N): print(dp[i])
# print(limited_by)



# print(dp)
# 
# 
# for i in range(N-3, -1, -1):
#     c,s,f = trains[i]
#     nc,ns,nf = trains[i+1]
#     arrive_at = c+s
#     # print("i: ", i, "c,s,f: ", c,s,f, end=" ")
#     # print("arrive_at: ", arrive_at, end=" ")
#     # print(" arrive_at<ns: ", arrive_at < ns)
# 
#     if arrive_at < ns:
#         dp[i] = dp[i+1]
#         limited_by[i] = ns - c
#     elif arrive_at < limited_by[i+1]:
#         dp[i] = dp[i+1]
#         limited_by[i] = limited_by[i+1] - c
#     else:
#         # print("arrive_at: ", arrive_at, "f: ", f, "dp[i+1] : ", dp[i+1], "ns: ", ns)
#         dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - ns
#

Submission status: Wrong Answer

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
trains = [ [int(j) for j in input().split()] for _ in range(N-1)] + [(0,0,0)]
dp = [float("inf") for _ in range(N-1)] + [0] # N-1

t = trains[N-2]
dp[N-2] = t[0]+t[1]
limited_by = [0 for _ in range(N)]
limited_by[N-2] = t[1]

for i in range(N-3, -1, -1):
    c,s,f = trains[i]
    nc,ns,nf = trains[i+1]
    arrive_at = c+s # start with A : B
    # limited_by[i] = max(limited_by[i+1]-c, s)
    
    # if arrive_at <

    if arrive_at < limited_by[i+1]-c:
        dp[i] = dp[i+1]
        limited_by[i] = limited_by[i+1] -c 

    else:
        dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - limited_by[i+1]
        limited_by[i] = s

for i in range(N): print(dp[i])
# print(limited_by)



# print(dp)
# 
# 
# for i in range(N-3, -1, -1):
#     c,s,f = trains[i]
#     nc,ns,nf = trains[i+1]
#     arrive_at = c+s
#     # print("i: ", i, "c,s,f: ", c,s,f, end=" ")
#     # print("arrive_at: ", arrive_at, end=" ")
#     # print(" arrive_at<ns: ", arrive_at < ns)
# 
#     if arrive_at < ns:
#         dp[i] = dp[i+1]
#         limited_by[i] = ns - c
#     elif arrive_at < limited_by[i+1]:
#         dp[i] = dp[i+1]
#         limited_by[i] = limited_by[i+1] - c
#     else:
#         # print("arrive_at: ", arrive_at, "f: ", f, "dp[i+1] : ", dp[i+1], "ns: ", ns)
#         dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - ns
#

Submission status: Wrong Answer

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
trains = [ [int(j) for j in input().split()] for _ in range(N-1)] + [(0,0,0)]
dp = [float("inf") for _ in range(N-1)] + [0] # N-1

t = trains[N-2]
dp[N-2] = t[0]+t[1]
limited_by = [0 for _ in range(N)]
limited_by[N-2] = t[1]

for i in range(N-3, -1, -1):
    c,s,f = trains[i]
    nc,ns,nf = trains[i+1]
    arrive_at = c+s # start with A : B
    limited_by[i] = max(limited_by[i+1]-c, s)
    
    # if arrive_at <

    if arrive_at < limited_by[i]:
        dp[i] = dp[i+1]

    else:
        dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - limited_by[i+1]

for i in range(N): print(dp[i])
# print(limited_by)



# print(dp)
# 
# 
# for i in range(N-3, -1, -1):
#     c,s,f = trains[i]
#     nc,ns,nf = trains[i+1]
#     arrive_at = c+s
#     # print("i: ", i, "c,s,f: ", c,s,f, end=" ")
#     # print("arrive_at: ", arrive_at, end=" ")
#     # print(" arrive_at<ns: ", arrive_at < ns)
# 
#     if arrive_at < ns:
#         dp[i] = dp[i+1]
#         limited_by[i] = ns - c
#     elif arrive_at < limited_by[i+1]:
#         dp[i] = dp[i+1]
#         limited_by[i] = limited_by[i+1] - c
#     else:
#         # print("arrive_at: ", arrive_at, "f: ", f, "dp[i+1] : ", dp[i+1], "ns: ", ns)
#         dp[i] = arrive_at+ (f - arrive_at%f)%f + dp[i+1] - ns
#