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:
#!/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] - ns

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



# 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 = [10**9 for _ in range(N-1)] + [0] # N-1
# print("len of trains: ", len(trains))

t = trains[N-2]
dp[N-2] = t[0]+t[1]
# print(dp)

limited_by = [0 for _ in range(N)]

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

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

Submission status: Wrong Answer

Solution code:
# encoding:utf-8

import copy
import numpy as np
import random

N = int(input())
n = N
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)

answer = []
for i in range(n-1):
    to_goal = C[i] + S[i]
    for j in range(i+1,n-1):
        if to_goal >= S[j]:
            if to_goal % F[j] == 0:
                to_goal += C[j]
            else:
                to_goal = ((to_goal//F[j])+1)*F[j]+C[j]
        elif to_goal < S[j]:
            to_goal = S[j]+C[j]

    answer.append(to_goal)


answer.append(0)
print(answer)

Submission status: Wrong Answer

Solution code:
# encoding:utf-8

import copy
import numpy as np
import random

N = int(input())
n = N
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)

answer = []
for i in list(reversed(range(n))):
    if i == n-1:
        answer.append(0)
    elif i == n-2:
        answer.insert(0,C[i]+S[i])
    else:
        to_next_station = C[i]+S[i]
        if to_next_station > S[i+1]:
            if to_next_station % F[i+1] == 0:
                to_goal = to_next_station+answer[0]-S[i+1]
            else:
                to_goal = ((to_next_station//F[i+1])+1)*F[i+1]+answer[0]-S[i+1]
            to_goal = min(to_goal,answer[0])
        elif to_next_station == S[i+1]:
            to_goal =to_next_station+answer[0]-C[i+1]
        else:
            to_goal = answer[0]
        # print(to_goal)
        answer.insert(0,to_goal)

for i in answer:
    print(i)

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-1):
    t = 0
    for c,s,f in info[i:]:
        # 開通式の待ち時間
        if t <= s:
            wait = s - t
            t += s - t
        else:
            pass_time = t - s
            pass_time %= f
            wait = f - pass_time
        # 通行時間
        t += c
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
B = []
C = []
for i in range(n - 1):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)

D = [0]
for i in range(n - 1):
    
    ans = (sum(A[-i-1:]) + B[n - i - 2])
    if(D[i] > ans):
        D.append(D[i])
    else:
        D.append(ans)
D.reverse()
for i in range(n):
    print(D[i])

Submission status: Wrong Answer

Solution code:
N = int(input())
data = [list(map(int,input().split())) for l in range(N-1)]
for i in range(N-1):
    time = 0
    for j in range(i,N-1):
        if j==i:
            waitTime = data[j][1]
        elif time < data[j][1]:
            waitTime = data[j][1] - time
        else:
            waitTime =time % data[j][2]
        time += waitTime + data[j][0]
    else:
        print(time)

print('0')

Submission status: Wrong Answer

Solution code:
def solve_impl(ini, T):
    t = 0
    for Ci, Si, Fi in T[ini:]:
        # wait until start
        if t < Si:
            t = Si
        elif t % Fi != 0:
            t += t + Fi - t % Fi

        t += Ci
    return t


def solve():
    N = int(input())
    T = [ [int(n) for n in input().split()] for _ in range(N-1) ]

    for i in range(N):
        print(solve_impl(i,T))

    return 0


def main():
    ans = solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve_impl(ini, T):
    t = 0
    for i in range(ini, len(T)):
        [Ci, Si, Fi] = T[i]

        # wait until start
        if t < Si:
            t += (Si - t)
        elif t % Fi != 0:
            t += t + Fi - t % Fi

        t += Ci
    return t


def solve():
    N = int(input())
    T = [ [int(n) for n in input().split()] for _ in range(N-1) ]

    for i in range(N):
        print(solve_impl(i,T))

    return 0


def main():
    ans = solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve_impl(ini, T):
    t = 0
    for i in range(ini, len(T)):
        [Ci, Si, Fi] = T[i]

        # wait until start
        if t < Si:
            t += (Si - t)

        if t % Fi != 0:
            t += t + Fi - t % Fi

        t += Ci
    return t


def solve():
    N = int(input())
    T = [ [int(n) for n in input().split()] for _ in range(N-1) ]

    for i in range(N):
        print(solve_impl(i,T))

    return 0


def main():
    ans = solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve_impl(ini, T):
    t = 0
    for i in range(ini, len(T)):
        [Ci, Si, Fi] = T[i]

        # wait until start
        if t < Si:
            t += (Si - t)

        if t % Fi != 0:
            t += t % Fi

        t += Ci
    return t


def solve():
    N = int(input())
    T = [ [int(n) for n in input().split()] for _ in range(N-1) ]

    for i in range(N):
        print(solve_impl(i,T))

    return 0


def main():
    ans = solve()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    tmp = list(int(i) for i in input().split())
    c.append(tmp[0])
    s.append(tmp[1])
    f.append(tmp[2])

for i in range(n-1):
    time_sum = 0
    for j in range(i,n-1):
        time_sum = time_sum+f[j]-time_sum%f[j] if time_sum>s[j] else s[j]
        time_sum += c[j]
    print(time_sum)
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    tmp = list(int(i) for i in input().split())
    c.append(tmp[0])
    s.append(tmp[1])
    f.append(tmp[2])

for i in range(n-1):
    time_sum = 0
    time_sum += s[i]
    for j in range(i,n-1):
        time_sum = time_sum+f[j]-time_sum%f[j] if time_sum>s[j] else s[j]
        time_sum += c[j]
    print(time_sum)
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    tmp = list(int(i) for i in input().split())
    c.append(tmp[0])
    s.append(tmp[1])
    f.append(tmp[2])

for i in range(n-1):
    time_sum = 0
    time_sum += s[i]
    for j in range(i,n-1):
        time_sum = time_sum+time_sum%f[j] if time_sum>s[j] else s[j]
        time_sum += c[j]
    print(time_sum)
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
res = [0] * N
for i in range(N - 1):
    C, S, F = map(int, raw_input().split())
    for j in range(i + 1):
        res[j] = max(S, res[j] + res[j] % F)
        res[j] += C
for t in res:
    print t

Submission status: Wrong Answer

Solution code:
N = input()
res = [0] * N
for i in range(N - 1):
    C, S, F = map(int, raw_input().split())
    for j in range(i + 1):
        res[j] = max(S, res[j])
        res[j] += res[j] % F
        res[j] += C
for t in res:
    print t

Submission status: Wrong Answer

Solution code:
N = input()
res = [0] * N
for i in range(N - 1):
    C, S, F = map(int, raw_input().split())
    for j in range(i + 1):
        res[j] = max(S, res[j])
        res[j] += C
for t in res:
    print t

Submission status: Wrong Answer

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


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

print('0')

Submission status: Wrong Answer

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


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

print('0')

Submission status: Wrong Answer

Solution code:
N = int(input())

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

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

	print(x)

Submission status: Wrong Answer

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

#print(n)
#print(e)

#ans=[]
#ans.append(0)
#ans.append(e[1][0]+e[1][1])
#ans.append(e[0][0]+e[0][1]+e[1][0])

ans=[0]
c=0
for i in range(n):
  x=e[n-i-2][0]+e[n-i-2][1]+c
  ans.append(x)
  c+=e[n-i-2][0]

for i in range(n-2):
  if ans[i+1] > ans[i+2]:
    ans[i+2]=ans[i+1]

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

Submission status: Wrong Answer

Solution code:
n = (int)(input())  # num of station
cost = []  # list of costed timeto next
s = []  # list of init train time
freq = []  # list of freq of train departure
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):  # return time will cost to go from (num)station to end
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  # if init train has not departed
      time = s[j]
    elif time % freq[j] != 0:  # if next train has not arrived
      time = wait_next(time, freq[j])
    time += cost[j]  # add time to next station
  return time


def wait_next(now, freq):  # calc time we will wait to get next train
  while(1):
    if not now % freq:
      break
    now += 1
#  return now
  return (now//freq+1)*freq


for i in range(n):
  print(t(i))

Submission status: Wrong Answer

Solution code:
n = (int)(input())  # num of station
cost = []  # list of costed timeto next
s = []  # list of init train time
freq = []  # list of freq of train departure
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):  # return time will cost to go from (num)station to end
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  # if init train has not departed
      time = s[j]
    elif time % freq[j]:  # if next train has not arrived
      time = wait_next(time, freq[j])
    time += cost[j]  # add time to next station
  return time


def wait_next(now, freq):  # calc time we will wait to get next train
  while(1):
    if not now % freq:
      break
    now += 1
#  return now
  return (now//freq+1)*freq


for i in range(n):
  print(t(i))

Submission status: Wrong Answer

Solution code:
n = (int)(input())  # num of station
cost = []  # list of costed timeto next
s = []  # list of init train time
freq = []  # list of freq of train departure
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):  # return time will cost to go from (num)station to end
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  # if init train has not departed
      time = s[j]
    elif time % freq[j]:  # if next train has not arrived
      time = wait_next(time, freq[j])
    time += cost[j]  # add time to next station
  return time


def wait_next(now, freq):  # calc time we will wait to get next train
  while(1):
    if not now % freq:
      break
    now += 1
#  return now
  return (now/freq+1)*freq


for i in range(n):
  print(t(i))

Submission status: Wrong Answer

Solution code:
n = (int)(input())  # num of station
cost = []  # list of costed timeto next
s = []  # list of init train time
freq = []  # list of freq of train departure
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):  # return time will cost to go from (num)station to end
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  # if init train has not departed
      time = s[j]
    elif time % freq[j]:  # if next train has not arrived
      time = wait_next(time, freq[j])
    time += cost[j]  # add time to next station
  return time


def wait_next(now, freq):  # calc time we will wait to get next train
  while(1):
    if not now % freq:
      break
    now += 1
#  return now
  return (now/freq)*freq


for i in range(n):
  print(t(i))

Submission status: Wrong Answer

Solution code:
n = (int)(input())  # num of station
cost = []  # list of costed timeto next
s = []  # list of init train time
freq = []  # list of freq of train departure
for i in range(n-1):
  a, b, c = (list)(map(int, input().split()))
  cost.append(a)
  s.append(b)
  freq.append(c)


def t(num):  # return time will cost to go from (num)station to end
  time = 0
  for j in range(num, n-1):
    if time < s[j]:  # if init train has not departed
      time = s[j]
    elif time % freq[j]:  # if next train has not arrived
      time = wait_next(time, freq[j])
    time += cost[j]  # add time to next station
  return time


def wait_next(now, freq):  # calc time we will wait to get next train
  while(1):
    if not now % freq:
      break
    now += 1
#  return now
  return now/freq*freq


for i in range(n):
  print(t(i))

Submission status: Wrong Answer

Solution code:
n = int(input())

arr = []
arr += [list(map(int,input().split())) for i in range(n-1)]

for j in range(n-1):
    time = 0
    tmp = 0
    for k in range(j, n-1):
        if arr[k][1] >= time:
            time = arr[k][1] + arr[k][0]
        else:
            tmp = arr[k][1]
            while time >= tmp:
                tmp += arr[k][2]
            time = tmp - arr[k][2] + arr[k][0]
    
    print(time)
print(0)

Submission status: Wrong Answer

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

def move_time(i, t):
    ride = 0
    if t > S[i]:
        if t % F[i] == 0:
            ride = t
        else:
            ride = (t/F[i] + 1) * F[i]
    else:
        ride = S[i]

    return ride + C[i]

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        t = move_time(j, t)
    print(t)

print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
csf = []
for _ in range(n-1):
    c,s,f = map(int, input().split())
    csf.append((c,s,f))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
def 解():
    iN = int(sys.stdin.readline())
    aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
    def fCeil(a):
        return int(-1* ( int(-1*a)))

    for i in range(iN-1):
        Tjb = aData[i][0] + aData[i][1]
        for j in range(i+1,iN-1):
            Cj = aData[j][0]
            Sj = aData[j][1]
            Fj = aData[j][2]
            Tjb = max( fCeil(Tjb/Fj),Sj//Fj)*Fj+Cj
        print(Tjb)
    print(0)
解()

Submission status: Wrong Answer

Solution code:
import sys
def 解():
    iN = int(sys.stdin.readline())
    aData = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
    def fCeil(a):
        return -1* ( int(-1*a))

    for i in range(iN-1):
        Tjb = aData[i][0] + aData[i][1]
        for j in range(i+1,iN-1):
            Cj = aData[j][0]
            Sj = aData[j][1]
            Fj = aData[j][2]
            Tjb = max( fCeil(Tjb)//Fj,Sj//Fj)*Fj+Cj
        print(Tjb)
    print(0)
解()

Submission status: Wrong Answer

Solution code:
import math
def lcm(x,y):
  return (x*y)//math.gcd(x,y)
N = int(input())

C=[]
S=[]
F=[]

for i in range(N-1):
  a,b,c = map(int,input().split())
  C.append(a)
  S.append(b)
  F.append(c)
for i in range(N-1):
  #駅iからSの最大値の駅を見つける
  for k in range(i,N-1):
    if max(S[i:])==S[k]:
      break
  if S[k] > sum(C[i:k])+S[i]:
    print(S[k]+sum(C[k:]))
  else:
    print(sum(C[i:])+S[i])
    
print(0)

Submission status: Wrong Answer

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

for i in range(n - 1):
    csf.append(list(map(int, input().split())))

for i in range(n - 1):
    t = 0
    for j in range(i, n - 1):
        t = max(t, csf[j][1])
        t += csf[j][2] * (t % csf[j][2]) - t % csf[j][2] + csf[j][0]
    print(t)
print(0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())

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


for i in range(N-1):
    estime = 0
    for (c,s,f) in CSF[i:]:
        estime += c + max([s,estime])%f + max([0,s - estime])

    print(estime)

print(0)

Submission status: Wrong Answer

Solution code:
class Station:
    def __init__(self, c, s, f):
        self.c = c
        self.s = s
        self.f = f


N = int(input())
stations = []
for _ in range(N-1):
    c, s, f = map(int, input().split())
    stations.append(Station(c, s, f))

for i in range(N):
    arrive_time = 0
    for j in range(i, N-1):
        current_station = stations[j]
        next_time = current_station.c + arrive_time
        if arrive_time > current_station.s:
            next_time += (arrive_time - current_station.s) % current_station.f
        else:
            next_time += (current_station.s - arrive_time)
        arrive_time = next_time
    print(arrive_time)

Submission status: Wrong Answer

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

for i in range(n-1):
    j = i
    ans = 0
    ans += list_prob[j][1]
    ans += list_prob[j][0]
    j += 1
    while j < n-1:
        if ans < list_prob[j][1]:
            ans = list_prob[j][1]
        else:
            if ans % list_prob[j][2] != 0:
                ans += (list_prob[j][2] - (ans % list_prob[j][2]))
            else:
                pass
        ans += list_prob[j][0]
        j += 1
    print(ans)
print(0)

Submission status: Wrong Answer

Solution code:
def cal_t():
    for i in range(N-1):
        for j in range(N-1-i): # jは区間
            if j == 0:
                t[i][0] = S[i] + C[i]
            else:
                if t[i][j-1] > S[i+j]:
                    wait_t = (t[i][j-1] - S[i+j]) % F[i+j]
                else:
                    wait_t = S[i+j] - t[i][j-1]
                t[i][j] = t[i][j-1] + wait_t + C[i+j]

N, = map(int, input().split())
C = [0]*N
S = [0]*N
F = [0]*N
t = [[0 for _ in range(N)] for _  in range(N)]
for i in range(N-1):
    C[i], S[i], F[i] = map(int, input().split())
cal_t()
for i in range(N-1):
    print(t[i][N-2-i])
print("0")

Submission status: Wrong Answer

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

def main():
    n = int(input())
    station_list = list(tuple(map(int, input().split())) for _ in range(n-1))
    for i in range(n-1):
        ans = 0
        for j in range(i, n-1):
            c, s, f = station_list[j]
            if ans <= s:
                ans = s
            else:
                if ans % f != 0:
                    ans += f - (ans % s)
            ans += c
        print(ans)
    print(0)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
csf = [[int(i) for i in input().split()] for _ in range(N-1)]

for i in range(N):
	t = 0
	for j in range(i, N-1):
		c, s, f = csf[j]
		if t <= s: #開始まで待つ
			t = s
		else: #一番近い出発時刻
			t = s + f * math.ceil((t-s) // f)
		t += c #i+1駅に着く時間
	print(int(t))

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
csf = [[int(i) for i in input().split()] for _ in range(N-1)]

for i in range(N):
	t = 0
	for j in range(i, N-1):
		c, s, f = csf[j]
		if t <= s: #開始まで待つ
			t = s
		else: #一番近い出発時刻
			t = s + f * math.ceil((t-s) // f)
		t += c #i+1駅に着く時間
	print(t)

Submission status: Wrong Answer

Solution code:
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 - 1):
    total = 0
    for j in range(i, n - 1):
        if total < s[j]:
            total = c[j] + s[j]
        else:
            total += c[j] - total % f[j]

    print(total)

print(0)

Submission status: Wrong Answer

Solution code:
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 - 1):
    total = 0
    for j in range(i, n - 1):
        if total < s[j]:
            total = c[j] + s[j]
        else:
            total += c[j] + (total % f[j])

    print(total)

print(0)

Submission status: Wrong Answer

Solution code:
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 - 1):
    total = 0
    for j in range(i, n - 1):
        if total <= s[j]:
            total = c[j] + s[j]
        else:
            total += c[j] + (total % f[j])

    print(total)

print(0)

Submission status: Wrong Answer

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

for i in range(N - 1):
    sec = 0
    for j in range(i, N - 1):
        if sec < S[j][1]:
            sec = S[j][1]
        elif sec % S[j][2]:
            sec += S[j][2]
        sec += S[j][0]
    print(sec)
print(0)

Submission status: Wrong Answer

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

def f(i):
	s = 0
	while i < N-1:
		# find the fastest train at time s from i stattion.
		if s <= S[i]:
			s = S[i]+C[i]
		else:
			m = s // F[i]
			if m == 0:
				s = s + C[i]
			else:
				s = m * F[i] + C[i]
			# we use the fact that F[i] | S[i]
		i += 1
	return s

for i in range(N):
	print(f(i))

Submission status: Wrong Answer

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

def f(i):
	s = 0
	while i < N-1:
		# find the fastest train at time s from i stattion.
		if s <= S[i]:
			s = S[i]+C[i]
		else:
			# we use the fact that F[i] | S[i]
			s = (s//F[i])*F[i] + C[i]
		i += 1
	return s

for i in range(N):
	print(f(i))

Submission status: Wrong Answer

Solution code:
N = int(input())

sta = [0] * (N-1)
time = [0] * (N-1)

for i in range(N-1):
  sta[i] = input().split(" ")

for i in range(N-1):
  time[i] = int(sta[i][1])

for i in range(N-1):
  for j in range(N-1-i):
    n = j + i
    if time[i] < (int(sta[n][0]) + int(sta[n][1])):
      time[i] = int(sta[n][0]) + int(sta[n][1])
    else :
      time[i] += int(sta[n][0])
  print(time[i])
print("0")

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8:


def main():
    N = input()
    C = [0] * (N - 1)
    S = [0] * (N - 1)
    F = [0] * (N - 1)

    for i in xrange(N - 1):
        C[i], S[i], F[i] = map(int, raw_input().split())

    t = 0
    for j in xrange(N - 1):
        for i in xrange(N - 1):
            if i + j == N - 1:
                break
            t = spend_waited_time(t, S[i + j], F[i + j])
            t += C[i + j]

        print(t)
        t = 0

    print(0)


def spend_waited_time(t, S, F):
    if t <= S:  # 始発がまだなら
        t = S
    elif S < t:  # 始発済みなら、次の電車まで何秒待つ？
        if 0 <= F - (t - S):
            t = S + F
        else:  # 始発の次の次以降は？
            a = (t - S) % F
            if a == 0:
                pass
            else:
                t += F + a

    return t


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# vim: set fileencoding=utf-8:


def main():
    N = input()
    C = [0] * (N - 1)
    S = [0] * (N - 1)
    F = [0] * (N - 1)

    for i in xrange(N - 1):
        C[i], S[i], F[i] = map(int, raw_input().split())

    t = 0
    for j in xrange(N-1):
        for i in xrange(N - 1):
            if i + j == N - 1:
                break
            t = spend_waited_time(t, S[i + j], F[i + j])
            t += C[i + j]

        print(t)
        t = 0

    print(0)


def spend_waited_time(t, S, F):
    if t <= S:  # 始発がまだなら
        t = S
    elif S < t:  # 始発済みなら、次の電車まで何秒待つ？
        if 0 <= F - (t - S):
            t = S + F
        else:  # 始発の次の次以降は？
            a = (t - S) % F
            if a == 0:
                pass
            else:
                print(a)
                t += F + a

    return t


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil
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-1):
  t = 0
  for j in range(i,N-1):
    if S[j] >= t:
      t = S[j] + C[j]
    else:
      t = ceil(t // F[j]) * F[j] + C[j]

  print(t)

print(0)