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())
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 += i[2] - (ans % i[1])

    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] != 0:
        ans += i[2] - (ans % i[1])

    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] - ans
    else:
      if ans % i[1] != 0:
        ans += i[2] - (ans % i[1])

    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] - ans
    else:
      ans += i[2] - ans % i[1]

    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] - ans
    else:
      ans += ((ans - i[1]) % i[2])

    ans += i[0]
  print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

me = 0
for i in range(n-1):
  remain = n - i - 1
  cost = 0
  time = 0
  for r in range(remain):
    c, s, f = stations[r+i]
    if time < s:
      time = s
    else:
      time = s + ((time - s)//f)*f
    time += c
  print(time)
  
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

me = 0
for i in range(n-1):
  remain = n - i - 1
  cost = 0
  time = 0
  for r in range(remain):
    c, s, f = stations[r+i]
    if time < s:
      time = s
    else:
      if time - s < s:
        time = s*2
      else:
        time = s + ((time - s)//f)*f
    time += c
  print(time)
  
print(0)

Submission status: Wrong Answer

Solution code:
def solve(n, CSF):
    # https://atcoder.jp/contests/abc084/tasks/abc084_c
    times = [0] * n
    for i, (c, s, f) in enumerate(CSF):
        for j in range(i + 1):
            if times[j] < s:
                times[j] = s
            else:
                times[j] += times[j] % f
            times[j] += c
    return times

_n = int(input())
_CSF = [map(int, input().split()) for _ in range(_n - 1)]
print(*solve(_n, _CSF), sep='\n')

Submission status: Wrong Answer

Solution code:
def solve(n, CSF):
    # https://atcoder.jp/contests/abc084/tasks/abc084_c
    times = [0] * n
    total = 0
    for i, (c, s, f) in enumerate(CSF):
        if total < s:
            total = s
        else:
            total += total % f
        total += c
        times[i] = total - times[i - 1]
    ret = [total - times[n - i - 1] for i in range(n)]
    return ret

_n = int(input())
_CSF = [map(int, input().split()) for _ in range(_n - 1)]
print(*solve(_n, _CSF), sep='\n')

Submission status: Wrong Answer

Solution code:
import sys
[a]=list(map(int,input().split()))

lst=[]
for i in range(a-1):
    lst.append(list(map(int,input().split())))

#print(a,lst)

lst2=[]
for i in range(a-1):
    tmp=lst[i][0]+lst[i][1]
    for ii in range(i+1,a-1):
        tmp=tmp+lst[ii][0]
    lst2.append(tmp)

#print(lst2)
for i in range(1,a):
    print(max(lst2[i-1:]))
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)

ans =[]
#O(N^2)
for i in range(N-1):
    t = S[i]
    for j in range(i,N-1):
        if t >= S[j]:
            pass
        else:
            t = S[j]
        if t % F[j] == 0:
            t += C[j]
        else:

            b = t % F[j]
            t += S[j] - b
            t += C[j]
    ans.append(t)

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

Submission status: Wrong Answer

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

for j in range(n-1):
    a = [0] * (j+1)
    for i in range(j, n-1):
        c = csf[i][0]
        s = csf[i][1]
        f = csf[i][2]
        if a[i] <= s:
            a.append(s+c)
        else:
            if (a[i] - s) % f == 0:
                a.append(a[i] + c)
            else:
                a.append(a[i] + (s + math.ceil((a[i] - s)/f) * f) -
                         (a[i] - s) % f + c)
    print(a[-1])
print(0)

Submission status: Wrong Answer

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

for i in range(n):
    s=i
    ti=0
    while s!=n-1:
        if ti<t[s][1]:
            ti+=t[s][1]+t[s][0]
        else:
            ti=t[s][2]*(math.ceil(ti/t[s][2]))+t[s][0]
        s+=1
    print(ti)

Submission status: Wrong Answer

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

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

print(0)

Submission status: Wrong Answer

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

for i in range(N-1):
    t = 0
    for c,s,f in csf[i:]:
        t = max(t, s)
        if t%f:
            t += -t//f
        t += c
    print(t)

print(0)

Submission status: Wrong Answer

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

for i in range(N-1):
    t = 0
    for c,s,f in csf[i:]:
        t = max(t, s)
        if t%f:
            t += 0--t//f
        t += c
    print(t)

print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = []
s = []
f = []
for _ in range(n-1):
    p,q,r = map(int,input().split())
    c.append(p)
    s.append(q)
    f.append(r)
a = [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 = s[j]+c[j]
        else:
            t += t%f[j]+c[j]
    a[i] = t
print('\n'.join(map(str, a)))

Submission status: Wrong Answer

Solution code:
import sys
import math

class cin():
    def getInt():
        return int(sys.stdin.readline().rstrip())
    def getString():
        return sys.stdin.readline().rstrip()

N = cin.getInt()
A = [list(map(int,cin.getString().split())) for i in range(N - 1)]

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

Submission status: Wrong Answer

Solution code:
import sys
import math

class cin():
    def getInt():
        return int(sys.stdin.readline().rstrip())
    def getString():
        return sys.stdin.readline().rstrip()

N = cin.getInt()
A = [list(map(int,cin.getString().split())) for i in range(N - 1)]

for i in range(N):
    t = 0
    for j in range(i,N - 1):
        if t <= A[j][1]:
            t = A[j][1] + A[j][0]
        else:
            n = math.floor(t / A[j][2]) * A[j][2]
            t = n + A[j][0]
    print(t)

Submission status: Wrong Answer

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

for n in range(N):
    if n != N - 1:
        # start n-th station
        t = S[n]
        for i in range(n, N - 1):
            # time to take a train i -> i+1
            t += C[i]
            # goto next station
            if i != N - 2:
                if t <= S[i + 1]:
                    t = S[i + 1]
                else:
                    if t%F[i + 1] != 0:
                        next_start_t = F[i + 1]
                        n = 1
                        while True:
                            if next_start_t >= t:
                                break
                            n += 1
                            next_start_t *= n
                        t = next_start_t
        print(t)
    else:
        # start at final destination
        print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst1 = [list(map(int,input().split())) for i in range(n-1)]
ans = []
for i in range(n-1):
    res = 0
    for j in range(i,n-1):
        if res < lst1[j][1]:
            res = lst1[j][1]
        else:
            res += (res-lst1[j][1])%lst1[j][2] #駅を経つまでの時間を加算
        res += lst1[j][0]
        
    ans.append(res)

ans.append(0)

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst1 = [list(map(int,input().split())) for i in range(n-1)]
ans = []
for i in range(n-1):
    res = 0
    res += lst1[i][1]
    for j in range(i,n-1):
        res += lst1[j][0] #駅間の距離[s]
        if j == n-2:
            break
        if res < lst1[j+1][1]: #まだ開通時間でないなら
            res = lst1[j+1][1] #開通時間を適用して次の駅へ
        else:
            res += (res-lst1[j+1][1])%lst1[j+1][2] #駅を経つまでの時間を加算
        
    ans.append(res)

ans.append(0)

for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst1 = [list(map(int,input().split())) for i in range(n-1)]
ans = []
for i in range(n-1):
    res = 0
    res += lst1[i][1]
    for j in range(i,n-1):
        if res < lst1[j][1]: #まだ開通時間でないなら
            res = lst1[j][1] #開通時間を適用して次の駅へ
        else:
            res += (res-lst1[j][1])%lst1[j][2] #駅を経つまでの時間を加算
        res += lst1[j][0] #駅間の距離[s]
    ans.append(res)

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
dat = []
for i in range(n-1):
    c, s, f = map(int, input().split())
    dat.append([c, s, f])
for i in range(n-1):
    #print("i={0}".format(i))
    t = 0
    for j in range(i, n-1):
        # 発車時刻前ならその時刻まで待たないといけない
        #print("reqch j={0}, t={1}".format(j, t))
        t = dat[j][1] if t <= dat[j][1] else t
        # w = (t - dat[j][1]) % dat[j][2]
        w = t % dat[j][2]
        #print("    t={0}, w={1}".format(t, w))
        t += w + dat[j][0]
        #print("next t={0}".format(t, w))
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
dat = []
for i in range(n-1):
    c, s, f = map(int, input().split())
    dat.append([c, s, f])
for i in range(n-1):
    #print("i={0}".format(i))
    t = 0
    for j in range(i, n-1):
        # 発車時刻前ならその時刻まで待たないといけない
        #print("reqch j={0}, t={1}".format(j, t))
        t = dat[j][1] if t < dat[j][1] else t
        w = (t - dat[j][1]) % dat[j][2]
        #print("    t={0}, w={1}".format(t, w))
        t += w + dat[j][0]
        #print("next t={0}".format(t, w))
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
dat = []
for i in range(n-1):
    c,s,f = map(int, input().split())
    dat.append([c, s, f])
for i in range(n-1):
    #print("i={0}".format(i))
    t = 0
    for j in range(i, n-1):
        # 発車時刻前ならその時刻まで待たないといけない
        #print("reqch j={0}, t={1}".format(j, t))
        t = dat[j][1] if t < dat[j][1] else t
        w = (t - dat[j][1]) % dat[j][2]
        #print("    t={0}, w={1}".format(t, w))
        t += w + dat[j][0]
        #print("next t={0}".format(t, w))
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:

a = int(input())
l = []

for i in range(a-1):
    ta,tb,tc  = map(int,input().split())
    l.append([ta,tb,tc])

for i in range(a-1):
    s = 0
    s += sum(l[i][:2])
    for j in range(i+1,a-1):
        # print(i,j,s)
        if s<= l[j][1]:s = sum(l[j][:2])
        else: s+= l[j][2]-s%l[j][2]+l[j][0]
        # print(l[j][0])
    print(s)
print(0)

Submission status: Wrong Answer

Solution code:
a = int(input())
l = []

for i in range(a-1):
    ta,tb,tc  = map(int,input().split())
    l.append([ta,tb,tc])

for i in range(a-1):
    s = 0
    s += sum(l[i][:2])
    for j in range(i+1,a-1):
        # print(i,j,s)
        if s<= l[j][1]:s = sum(l[j][:2])
        else: s+= s%l[j][2]+l[j][0]
        # print(l[j][0])
    print(s)
print(0)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left

N=int(input())
t = [0 for i in range(N)]
times = [list(map(int, input().split())) for i in range(N-1)]
for start in range(N-1):
    current = start + 1
    elapsed =  times[start][1] + times[start][0]
    while current < N-1:
        if elapsed >= times[current][1]:
            elapsed += times[current][0] + (elapsed % times[current][2])
            current += 1
        else:
            elapsed = times[current][1]

    t[start] = elapsed

[print(time) for time in t]

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left

N=int(input())
t = [0 for i in range(N)]
times = [list(map(int, input().split())) for i in range(N-1)]
for start in range(N-1):
    current = start
    elapsed =  times[start][1]
    while current < N-1:
        if elapsed >= times[current][1]:
            elapsed += times[current][0] + (elapsed % times[current][2])
            current += 1
        else:
            elapsed = times[current][1]

    t[start] = elapsed

[print(time) for time in t]

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  l=[LI() for _ in range(n-1)]

  for i in range(n-1):
    t=0
    for x in l[i:]:
      c,s,f=x
      if t<s:
        t=s
      else:
        _t=t-s
        t+=int(_t%f)
      t+=c
    print(t)
  print(0)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  l=[LI() for _ in range(n-1)]

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

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  l=[LI() for _ in range(n-1)]

  for i in range(n-1):
    t=0
    for x in l[i:]:
      c,s,f=x
      if t<s:
        t=s
      else:
        _t=t-s
        t+=_t%f
      t+=c
    print(int(t))
  print(0)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()

  l=[LI() for _ in range(n-1)]

  for i in range(n-1):
    t=0
    for x in l[i:]:
      c,s,f=x
      if t<s:
        t=s
        t+=c
      else:
        _t=t-s
        t+=_t%f
        t+=c
    print(t)
  print(0)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    CSF=LLIN(N-1)
    def solve(CSF):
        now = 0
        for c,s,f in CSF:
            if now<=s:
                now = s
            else:
                over = s-now
                if over%f:
                    now += (f-(over%f))
            now += c
        print(now)
                
    for i in range(N):
        solve(CSF[i:])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    CSF=LLIN(N-1)
    def solve(CSF):
        now = 0
        for c,s,f in CSF:
            if now<=s:
                now = s
            else:
                over = s-now
                if over%f:
                    now += over+(f-(over%f))
            now += c
        print(now)
                
    for i in range(N):
        solve(CSF[i:])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

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

def dfs(i):
  DP = [99999999999999] * N
  DP[i] = M[i][1]

  for j in range(i+1, N):
    prev_start = max(M[j-1][1], DP[j-1])
    DP[j] = prev_start + M[j-1][0] + ( prev_start - M[j-1][1] ) % M[j-1][2]
  
  print(DP[N-1])

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

print(0)

Submission status: Wrong Answer

Solution code:

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

def dfs(i):
  DP = [99999999999999] * N
  DP[i] = M[i][1]

  for j in range(i+1, N):
    prev = DP[j-1] + M[j-1][0]
    start = M[j-1][1] + M[j-1][0]
    if start >= prev:
      DP[j] = start
    else:
      DP[j] = prev + ( DP[j-1] - M[j-1][1] ) % M[j-1][2]
  
  print(DP[N-1])

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

print(0)

Submission status: Wrong Answer

Solution code:

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

def dfs(i):
  DP = [99999999999999] * N
  DP[i] = M[i][1]
  for j in range(i+1, N):
    prev = DP[j-1] + M[j-1][0]
    start = M[j-1][1] + M[j-1][0]
    if start >= prev:
      DP[j] = start
    else:
      DP[j] = prev + ( prev - M[j-1][1] ) % M[j-1][2]
  print(DP[N-1])

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

print(0)

Submission status: Wrong Answer

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

ans=[]
for i in range(n):
    time=0
    for j in range(i,n-1):
        c,s,f=csf[j][0],csf[j][1],csf[j][2]
        if time>s:
            time=s -(-(time-s)//f)*f
        else:
            time=s
        time+=c

        #print(i,j,c,s,f,time)
    ans.append(time)
print(ans)

Submission status: Wrong Answer

Solution code:
# 駅jjを出発する時刻は、
#S[j]+F[j]×kS[j]+F[j]×kとなる(kは車両数)。
#出発する時刻は現在時刻tt以上である必要があるので、
#S[j]+F[j]×k≥tS[j]+F[j]×k≥tとする。 式変形
import math
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N-1)]

for i in range(N): # 駅iを始点とする
  t = 0 # 現在時刻
  for j in range(i, N-1):
    c, s, f = CSF[j]
    if t <= s: # 始発がまだ
      t = s+c
    else: # 始発以降      
      t += math.ceil(t / f) * f + c
  print(t)

Submission status: Wrong Answer

Solution code:
n=int(input())
csf=[0]
for i in range(n-1):
    csf.append(list(map(int,input().split())))
for i in range(1,n):
    t=0
    for j in range(i,n):
        if t<=csf[j][1]:
            t=csf[j][1]+csf[j][0]
        else:
            for k in range(1000):
                if t<=csf[j][1]+k*csf[j][2]:
                    t=csf[j][1]+k*csf[j][2]+csf[j][0]
                    break
    print(t)
print(0)

Submission status: Wrong Answer

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

ans = []
for i in range(N-1):
    time = arr[i][1]
    for j in range(i, N-1):
        if time > arr[j][1]:
            time = arr[j][0] + time
        else:
            time += arr[j][1] - time
            time += arr[j][0]
    print(time)
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
t = [tuple(map(int, input().split())) for _ in range(N)]
res = [0] * N
for i in range(N):
  p = 0
  for j in range(i, N - 1):
    if p <= t[j][1]:
      p = t[j][1]
    else:
      px = p - t[j][1]
      p += (px % t[j][2])
      #print(px)
    p += t[j][0]
    #print(i, p)
  res[i] = p
for r in res: print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = []
for _ in range(n - 1):
  lst.append([int(i) for i in input().split()])

for i in range(n):
  now = 0
  for c, s, f in lst[i:]:
    if now < s:
      now = c + s
    else:
      mod = now % f
      if mod == 0:
        now += c
      else:
        now += f - mod
  print(now)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2000)

n = int(input())
lst = []
for _ in range(n - 1):
  lst.append([int(i) for i in input().split()])

def time_cost(i, now, lst):
  if i == n - 1:
    return now
  if now >= lst[i][1]:
    now += lst[i][0] + lst[i][2] - now % lst[i][2]
  else:
    now = lst[i][1] + lst[i][0]
  return time_cost(i+1, now, lst)

for i in range(n):
  print(time_cost(i, 0, lst))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2000)

n = int(input())
lst = []
for _ in range(n - 1):
  lst.append([int(i) for i in input().split()])


time_list = []

def time_cost(i, now, lst):
  if i == n - 1:
    return now
  if now >= lst[i][1]:
    now += lst[i][0] - now % lst[i][2]
  else:
    now = lst[i][1] + lst[i][0]
  return time_cost(i+1, now, lst)

for i in range(n):
  print(time_cost(i, 0, lst))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)

n = int(input())
lst = []
for _ in range(n - 1):
  lst.append([int(i) for i in input().split()])

for i in range(n):
  if i == n - 1:
    print(0)
    quit()
  now = 0
  for j in range(i, n - 1):
    if now >= lst[j][1]:
      now += now % lst[j][2] + lst[j][0]
    else:
      now = lst[j][0] + lst[j][1]
  print(now)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000)

n = int(input())
lst = []
for _ in range(n - 1):
  lst.append([int(i) for i in input().split()])


time_list = []

def time_cost(i, now, lst):
  if i == n - 1:
    return now
  if now >= lst[i][1]:
    now += now % lst[i][2] + lst[i][0]
  else:
    now = lst[i][1] + lst[i][0]
  return time_cost(i+1, now, lst)

for i in range(n):
  print(time_cost(i, 0, lst))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2000)

n = int(input())
lst = []
for _ in range(n - 1):
  lst.append([int(i) for i in input().split()])


time_list = []

def time_cost(i, now, lst):
  if i == n - 1:
    return now
  if now >= lst[i][1]:
    now += now % lst[i][2] + lst[i][0]
  else:
    now = lst[i][1] + lst[i][0]
  return time_cost(i+1, now, lst)

for i in range(n):
  print(time_cost(i, 0, lst))

Submission status: Wrong Answer

Solution code:
import sys


if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
T = [MAP() for _ in range(N-1)]

S = [0] * N

for i in range(N-1):
	m = 0
	for j in range(i, N-1):
		c, s, f = T[j]
		# 最初の駅
		if m == 0:
			m += c+s
		else:
			# 2駅目以降に到着してすぐに出発できるケース
			if m % f == 0:
				m += c
			# 次の電車を待つケース(f分刻みで出発する電車の次のやつに乗りたい)	
			else:
				m = max(s, m+f-(m%f))
				m += c
	S[i] = m

#print(S)

for s in S:
	print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = []
for _ in range(N-1):
    arr.append(list(map(int, input().split())))
for i in range(N-1):
    start = i
    tmp = 0
    while start < N-1:
        if tmp < arr[start][1]:
            tmp = arr[start][1]
        else:
            tmp += arr[start][2]-((tmp-arr[start][1]) % arr[start][2])
        tmp += arr[start][0]
        start += 1
    print(tmp)
print(0)