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

results = []
for i in range(n-1):
    cur = 0
    for j in range(i, n-1):
        k = max(0, (cur - setting[j][1]) / setting[j][2])
        cur = setting[j][0] + setting[j][1] + setting[j][2] * k
    results.append(int(cur))
results.append(0)
for result in results:
    print(result)

Submission status: Wrong Answer

Solution code:
N = int(input())

CSF = [[int(i) for i in input().split()] for _ in range(N-1)]
for i in range(N-1) :
    x = 0
    for j in range(i, N-1) :
        C, S, F = CSF[j]
        if x < S :
            x = S + C
        else :
            x = S + F * ((x - S) // F) + C
    print(x)
print(0)

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# 
N =  int(sys.stdin.readline())
L =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N - 1)]

for i in range(N - 1):
    start = L[i]
    cnt = start[0] + start[1]
    for j in range(i + 1, N - 1):
        next = L[j]
        # 開通しているか確認
        if cnt < next[1]:
            cnt = next[1]
        else:
            cnt += (cnt - next[1]) % next[2]
        cnt += next[0]
    print(cnt)

print(0)

Submission status: Wrong Answer

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


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    ans = [0]*(N)
    for k in range(N-1):
        cst = S[k]+C[k]
        for i in range(k+1,N-1):
            cst = max(cst, S[i])
            cst += (cst%F[i]+C[i])
        ans[k] = cst

    for i in ans:
        print(i)

    return

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    global N, C, S, F
    N = int(next(tokens))  # type: int
    C = [int()] * (N-1)  # type: "List[int]" 
    S = [int()] * (N-1)  # type: "List[int]" 
    F = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    ans = [0]*(N)
    for k in range(N-1):
        cst = S[k]+C[k]
        for i in range(k+1,N-1):
            cst = max(cst, S[i])
            cst += cst%F[i]+C[i]
        ans[k] = cst

    for i in ans:
        print(i)

    return

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    global N, C, S, F
    N = int(next(tokens))  # type: int
    C = [int()] * (N-1)  # type: "List[int]" 
    S = [int()] * (N-1)  # type: "List[int]" 
    F = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    csfs = [[int(i) for i in input().split()] for j in range(N-1)] + [[-1,0,0]]

    for i in range(N):
        state = i
        time = csfs[state][1]
        while state < N-1:
            if time % csfs[state][2] == 0:
                time += csfs[state][0]
                state += 1
            else:
                time += (csfs[state][2] - time%csfs[state][2])
        print(time)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc084/tasks/abc084_c
# C - Special Trains
import math

N = int(input().split()[0])
csf_list = []

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

x_list = []
total_c_list = []

for start_i in range(N-1):  # N <= 500
    total_c = csf_list[start_i][0] + csf_list[start_i][1]

    for csf in csf_list[start_i+1:]:  # N <= 500
        c, s, f = csf
        total_c = s if total_c < s else total_c
        i = math.floor((total_c - s) / f)
        total_c = s + f * i + c
    total_c_list.append(str(total_c))

ans = '\n'.join(total_c_list + ['0'])
print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc084/tasks/abc084_c
# C - Special Trains
import math

N = int(input().split()[0])
csf_list = []

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

x_list = []
total_c_list = []

for start_i in range(N-1):  # N <= 500
    total_c = csf_list[start_i][0] + csf_list[start_i][1]

    for csf in csf_list[start_i+1:]:  # N <= 500
        c, s, f = csf
        total_c = total_c + s if total_c < s else total_c
        i = math.floor((total_c - s) / f)
        total_c = s + f * i + c
    total_c_list.append(str(total_c))

ans = '\n'.join(total_c_list + ['0'])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

CSF = []

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

CSF.append([0, 0, 1])

ans = [0] * N

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

Submission status: Wrong Answer

Solution code:
N = int(input())
CSF = []
for i in range(0, N-1):
    CSF.append(list(map(int, input().split())))
for i in range(0, N):
    ans = 0
    for j in range(i, N-1):
        ans = max(CSF[j][1], ans)
        ans += (ans % CSF[j][2])
        ans += CSF[j][0]
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N-1)[::-1]:
  ans = S[i] + C[i]
  for j in range(i, N-2):
    if ans <= S[j+1]:
      ans = A[j+1]
      break
    else:
      ans = (ans // F[j+1]) * F[j+1] + C[j+1]
  A[i] = ans
  
for i in range(N):
  print(A[i])

Submission status: Wrong Answer

Solution code:
N = int(input())

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

for i in range(N-1)[::-1]:
  ans = S[i] + C[i]
  for j in range(i, N-2):
    if ans <= S[j+1]:
      ans = A[j+1]
    else:
      ans = ans // F[j+1] * F[j+1] + C[j+1]
  A[i] = ans
  
for i in range(N):
  print(A[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):
    time = 0
    for j in range(i, n-1):
        if  time <= s[j]:
            time = s[j]
        else:
            time -= ((time - s[j]) % f[j])
        time += c[j]
    print(time)
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):
    time = 0
    for j in range(i, n-1):
        if  time <= s[j]:
            time = s[j]
        else:
            time += ((time - s[j]) % f[j])
        time += c[j]
    print(time)
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):
    time = 0
    for j in range(i, n-1):
        if  time <= s[j]:
            time = s[j]
        else:
            time += (time % f[j])
        time += c[j]
    print(time)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = [list(map(int, input().split())) for i in range(N-1)]
ans = []
for i in range(N-1):
  t = lst[i][0] + lst[i][1]
  for j in range(i+1, N-1):
    if (t >= lst[j][1]):
      if (t % lst[j][2] == 0):
        t += lst[j][0]
      else:
        i = 1
        while (t >= lst[j][1] + (i * lst[j][2])):
          t = lst[j][1] + (i * lst[j][2])
          i += 1
    else:
      t = lst[j][1] + lst[j][0]
  ans.append(t)
ans.append(0)

for i in ans:
  print(i)

Submission status: Wrong Answer

Solution code:
N = int(input())

lst = [list(map(int, input().split())) for i in range(N-1)]
ans = []
for i in range(N-1):
  t = lst[i][0] + lst[i][1]
  for j in range(i+1, N-1):
    if (t >= lst[j][1]):
      if (t % lst[j][2] == 0):
        t += lst[j][0]
      else:
        t = lst[j][2] * ((t // lst[j][2]) + 1)
    else:
      t = lst[j][1] + lst[j][0]
  ans.append(t)
ans.append(0)

for i in ans:
  print(i)

Submission status: Wrong Answer

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

if N >= 2:
    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:
                t = ans - s
                if t % f == 0:
                    ans += c
                else:
                    ans += (t // f + 1) * f + c
        print(ans)
print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())

C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)

for n in range(N-1):
    c, s, f = [int(x) for x in stdin.readline().rstrip().split()]
    C[n] = c
    S[n] = s
    F[n] = f

t = 0
for i in range(N-1):
    for j in range(i,N-1):
        if t < S[j]:
            t = S[j]
        elif (t-S[j])%F[j] == 0:
            pass
        else:
            t += (((t - S[j])//F[j])+1)*F[j]

        t += C[j]
    print(t)
    t = 0
print(0)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())

C = [0] * (N-1)
S = [0] * (N-1)
F = [0] * (N-1)

for n in range(N-1):
    c, s, f = [int(x) for x in stdin.readline().rstrip().split()]
    C[n] = c
    S[n] = s
    F[n] = f

t = 0
for i in range(N-1):
    for j in range(i,N-1):
        if t < S[j]:
            t = S[j]
        elif (t-S[j])%F[j] == 0:
            pass
        else:
            t += ((t-S[j])%F[j])

        t += C[j]
    print(t)
    t = 0
print(0)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]
ret = []
import math
for i in range(n-1):
    ijplus1_time = 0
    for j in range(i,n-1):
        c,s,f = csf[j]
        if ijplus1_time <= s:
            #jの開通式の前にiからjにつけるなら、jからj+1にいくには
            ijplus1_time = s + c
        else:
            #jの開通式までにiからjにつけないなら、jからj+1にいくには
            ijplus1_time = s + c + f * math.ceil((ijplus1_time-s)//f)
    ret.append(ijplus1_time)
ret.append(0)
for i in ret:
    print(i)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
n = int(input())
csf = [list(map(int,input().split())) for _ in range(n-1)]
ret = []
for i in range(n-1):
    ijplus1_time = 0
    for j in range(i,n-1):
        c,s,f = csf[j]
        if ijplus1_time <= s:
            #jの開通式の前にiからjにつけるなら、jからj+1にいくには
            ijplus1_time = s + c
        else:
            #jの開通式までにiからjにつけないなら、jからj+1にいくには
            ijplus1_time = s + c + f * ((ijplus1_time-s)//f)
    ret.append(ijplus1_time)
ret.append(0)
for i in ret:
    print(i)

Submission status: Wrong Answer

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

for i in range(N):
    total=0
    for k in range(i,N):
        if k==i:
            total+=A[k][0]+A[k][1]
        else:
            if A[k][1]>total:
                total=A[k][1]
            elif total%A[k][2]!=0:
                total+=total+A[k][2]-total%A[k][2]
            total+=A[k][0]
    print(total)
print(0)

Submission status: Wrong Answer

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

for i in range(N):
    total=0
    for k in range(i,N):
        if k==i:
            total+=A[k][0]+A[k][1]
        else:
            if A[k][1]>total:
                total=A[k][1]
            if total%A[k][2]!=0:
                total+=total+A[k][2]-total%A[k][2]
            total+=A[k][0]
    print(total)
print(0)

Submission status: Wrong Answer

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

for i in range(N):
    total=0
    for k in range(i,N):
        if k==i:
            total+=A[k][0]+A[k][1]
        else:
            if A[k][1]>total:
                total=A[k][1]
            if total%A[k][2]!=0:
                total+=total%A[k][2]
            total+=A[k][0]
    print(total)
print(0)

Submission status: Wrong Answer

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

ans = [(0, i) for i in range(N)]
for i in range(N - 1):
    for j in range(N - i - 1):
        Cj, Sj, Fj = CSF[ans[j][1]]
        if ans[j][0] <= Sj:
            ans[j] = (Sj + Cj, ans[j][1] + 1)
        elif ans[j][0] % Fj == 0:
            ans[j] = (ans[j][0] + Cj, ans[j][1] + 1)
        else:
            ans[j] = (ans[j][0] + Fj - (ans[j][0] % Fj), ans[j][1] + 1)

for a in ans:
    print(a[0])

Submission status: Wrong Answer

Solution code:
# 2019/08/12

n=int(input())
n-=1
c=[0]*n
s=[0]*n
f=[0]*n

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

ans=[]
for i in range(n):
    res=c[i]+s[i]
    for j in range(i+1,n): #-1?
        if res<s[j]:
            res=s[j]+c[j]
        else:
            res+=res%f[j]+c[j]
    ans.append(res)
print(*ans,sep='\n')
print(0)

Submission status: Wrong Answer

Solution code:
import math
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
    if i == N - 1:
        print(0)
        exit()

    for j in range(i, N-1):
        if t < S[j]:
            t = math.ceil(S[j]/F[j]) * F[j] + C[j]
        elif t >= S[j]:
            t += C[j] + t % F[j]
    
    print(t)

Submission status: Wrong Answer

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

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



print(0)

Submission status: Wrong Answer

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

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



print(0)

Submission status: Wrong Answer

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

# simple solution
# 0: C
# 1: S
# 2: F
# print(status_lst)

rev_res = []
for ix, st_i in enumerate(status_lst):
    elapsed = st_i[1] + st_i[0]
    for next_st in range(ix+1, N-1):
        st_n = status_lst[next_st]
        if elapsed < st_n[1]:
            elapsed = st_n[1] + st_n[0]
        else:
            wait_time = elapsed % st_n[2]
            if wait_time == 0:
                elapsed = elapsed + st_n[0]
            else:
                elapsed = elapsed + st_n[2] - (elapsed % st_n[2])
            # elif wait_time == elapsed:
            #     # elaplsed < F
            #     # ?
            #     elapsed = st_n[2] + st_n[0]
            # else:
            #     elapsed = elapsed + wait_time + st_n[0]

    rev_res.append(elapsed)

rev_res.append(0)

for ans in rev_res:
    print(ans)

Submission status: Wrong Answer

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

# simple solution
# 0: C
# 1: S
# 2: F
# print(status_lst)

rev_res = []
for ix, st_i in enumerate(status_lst):
    elapsed = st_i[1] + st_i[0]
    for next_st in range(ix+1, N-1):
        st_n = status_lst[next_st]
        if elapsed < st_n[1]:
            elapsed = st_n[1] + st_n[0]
        else:
            wait_time = elapsed % st_n[2]
            if wait_time == 0:
                elapsed = elapsed + st_n[0]
            elif wait_time == elapsed:
                # elaplsed < F
                # ?
                elapsed = st_n[2] + st_n[0]
            else:
                elapsed = elapsed + wait_time + st_n[0]

    rev_res.append(elapsed)

rev_res.append(0)

for ans in rev_res:
    print(ans)

Submission status: Wrong Answer

Solution code:
n,*l=map(int,open(0).read().split())
c,s,f=l[::3]+[0],l[1::3]+[0],l[2::3]
for i in range(n):
	t=c[i]+s[i]
	for j in range(i+1,n-1):t=max(-f[j]*-t//f[j],s[j])+c[j]
	print(t)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
n,*l=map(int,open(0).read().split())
c=l[-3::-3]
cc=list(accumulate(c))
s=l[-2::-3]
f=l[-1::-3]
ans=[0,c[0]+s[0]]
for i in range(1,n-1):
	a=ans[-1]
	t=c[i]+s[i]
	t=(t//f[i-1]+(t%f[i-1]!=0))*f[i-1]
	ans.append(max(a,t+cc[i-1]))
for i in ans[::-1]:
	print(i)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys, math, fractions, itertools


def solve(N: int, C: "List[int]", S: "List[int]", F: "List[int]"):
    def step(t, i):
        """i -> i+1 at t"""
        s = S[i] if t < S[i] else math.ceil(t // F[i]) * F[i]
        d = s + C[i]
        return d
    for i in range(N):
        t = 0
        for j in range(i, N-1):
            t = step(t, j)
        print(t)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = [int()] * (N-1)  # type: "List[int]" 
    S = [int()] * (N-1)  # type: "List[int]" 
    F = [int()] * (N-1)  # type: "List[int]" 
    for i in range(N-1):
        C[i] = int(next(tokens))
        S[i] = int(next(tokens))
        F[i] = int(next(tokens))
    solve(N, C, S, F)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def lcm(x, y):
    return (x * y) // gcd(x, y)


N = int(input())

ans = [0] * N
for i in range(1, N):
    c, s, f = [int(zz) for zz in input().split()]
    ans[i] = s + c
    if ans[i - 1] < s:
        for j in range(1, i):
            ans[j] = s + c
    else:

        for j in range(1, i):
            p = (ans[j] - s) % f
            ans[j] += c + p

for i in range(1, N):
    print(ans[i])

print(0)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


def lcm(x, y):
    return (x * y) // gcd(x, y)


N = int(input())

ans = [0] * N
for i in range(1, N):
    c, s, f = [int(zz) for zz in input().split()]
    ans[i] = s + c
    if ans[i - 1] < s:
        for j in range(1, i):
            ans[j] = s + c
    else:

        for j in range(1, i):
            p = f - (ans[j] - s) % f
            ans[j] += c + p

for i in range(1, N):
    print(ans[i])

print(0)

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def lcm(x, y):
    return (x * y) // gcd(x, y)

N = int(input())

ans = [0] * N
for i in range(1, N):
    c, s, f = [int(zz) for zz in input().split()]
    ans[i] = s + c
    if ans[i - 1] < s:
        for j in range(1, i):
            ans[j] = s + c
    else:

        for j in range(1, i):
            p = abs(ans[j] - s - lcm((ans[j] - s),f))
            ans[j] += c + p

for i in range(1,N):
    print(ans[i])

print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = [0] * N
for i in range(1, N):
    c, s, f = [int(zz) for zz in input().split()]
    ans[i] = s + c
    if ans[i - 1] < s:
        for j in range(1, i):
            ans[j] = s + c
    else:

        for j in range(1, i):
            p = (ans[j] - s) % f
            ans[j] += c + p

for i in range(1,N):
    print(ans[i])

print(0)

Submission status: Wrong Answer

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

for idx, station in enumerate(stations):
  time = station[1] + station[0]
  for next in range(idx+1, N-1):
    if time < stations[next][1]:
      time = stations[next][1] + stations[next][0]
    elif (time-stations[next][1])%stations[next][2] == 0:
      time = stations[next][0]
    else:
      time += stations[next][2] - (time-stations[next][1])%stations[next][2] + stations[next][0]
  print(time)
print(0)

Submission status: Wrong Answer

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

for idx, station in enumerate(stations):
  time = station[1] + station[0]
  for next in range(idx+1, N-1):
    if time < stations[next][1]:
      time = stations[next][1] + stations[next][0]
    else:
      time += stations[next][2] - (time-stations[next][1])%stations[next][2] + stations[next][0]
  print(time)
print(0)

Submission status: Wrong Answer

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

for idx, station in enumerate(stations):
  time = station[1] + station[0]
  for next in range(idx+1, N-1):
    if time < stations[next][1]:
      time = stations[next][1] + stations[next][0]
    else:
      time += (time-stations[next][1])%stations[next][2] + stations[next][0]
  print(time)
print(0)

Submission status: Wrong Answer

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

for idx, station in enumerate(stations):
  time = station[1] + station[0]
  for next in range(idx+1, N-1):
    time += (time-stations[next][1])%stations[next][2] + stations[next][0]
  print(time)
print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
#ABC084C

n = int(input())

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

c.append(0)
s.append(0)
f.append(0)
t.append(0)
for i in range(1,n):
	tmp = input().split()
	hoge = list(map(lambda a: int(a), tmp))
	c.append(hoge[0])
	s.append(hoge[1])
	f.append(hoge[2])
	t.append(0)
c.append(0)
t.append(0)
s.append(0)
f.append(1)

for i in range(0,n-1):
	t[n-1-i]=s[n-1-i]+c[n-1-i]
	if(t[n-1-i]<=s[n-i]):
		t[n-1-i]=t[n-i]
	else:
		t[n-1-i]-=s[n-i]
		t[n-1-i]=((t[n-1-i]-1)//f[n-i]+1)*f[n-i]+t[n-i]

for i in range(1,n+1):
	print(t[i])

Submission status: Wrong Answer

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


for i in range(N-1):
     time = 0
     for j in range(i, N-1):
          if time <= S[j]:
               time = S[j]
          elif time % F[j] != 0:
               time += time % F[j]
          time += C[j]
     print(time)
print(0)

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)]

  ans=[]
  for i in range(n-1):
    t=0
    for x in l[i:]:
      if t<x[1]:
        t=x[1]
      else:
        t+=(t-x[1])%x[2]
      t+=x[0]

    ans.append(t)

  ans.append(0)

  for x in ans:
    print(x)

main()
# print(main())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    N = int(input())
    csf = []
    for i in range(N-1):
        c,s,f = map(int, input().split())
        csf.append((c,s,f))
        
    for i, val in enumerate(csf):
        ans = 0
        c,s,f = val
        ans += s + c
        for j, vol in enumerate(csf):
            if i >= j:
                continue
            cc,ss,ff = vol
            if ans <= ss:
                ans = ss + cc
            else:
                tmp = ans - ss
                if tmp == 0:
                    ans += cc
                    continue
                    
                tmp = (tmp // ff)
                tmp = (tmp * ff) + ss
                ans = ans + (tmp - ans) + cc
        print(ans)
                
    print(0)
    
	
if __name__ == "__main__":
	main()

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

Submission status: Wrong Answer

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

n = int(input())

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

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

Submission status: Wrong Answer

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

n = int(input())

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

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