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:


class Diagram:
    def __init__(self, n, xs):
        self.n = n
        self.xs = xs + [[0, 0, 0]]

    def departure(self, i, t):
        if i == self.n - 1:
            return t
        s = self.xs[i][1]
        f = self.xs[i][2]
        c = s // f
        d, m = divmod(t, f)
        if m == 0:
            if d > c:
                return t
            else:
                return s
        else:
            return s + f*(d+1)

    def arrival(self, i, t):
        return self.departure(i, t) + self.xs[i][0]



if __name__ == "__main__":
    n = int(input())
    xs = [list(map(int, input().split())) for i in range(n-1)]
    d = Diagram(n, xs)

    ys = [0]*n
    for i in range(n):
        for j in range(i,n) :
            ys[i] = d.arrival(j, ys[i])
    for y in ys:
        print(y)

Submission status: Wrong Answer

Solution code:


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

for i in range(1, n):
    x, y, z = map(int, input().strip().split( ' '))
    c[i] = x
    s[i] = y
    f[i] = z

def time(i, after=0):
    #print(i, after, c[i], s[i], f[i])
    if i == n:
        return after
    if (after < s[i]):
        start_time = s[i]
    else:
        if (after - s[i]) % f[i] == 0:
            start_time = after
        else:
            start_time = ((after - s[i])  / f[i] + 1) * f[i] + s[i]
    return time(i + 1, after=start_time+c[i])

for i in range(1,n+1):
    print(time(i))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    Ci, Si, Fi = list(map(int, input().split((" "))))
    C.append(Ci)
    S.append(Si)
    F.append(Fi)

ans = []
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 + F[j] - (t % F[j])
        t += C[j]
    print(t)

Submission status: Wrong Answer

Solution code:
N = int(input())
C = []
S = []
F = []
T = [0 for i in range(N)]

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

for t in T:
    print(t)

Submission status: Wrong Answer

Solution code:
import numpy as np
import pdb

def main():
    N = int(raw_input())
    Cs = np.zeros(N-1).astype(int)
    Ss = np.zeros(N-1).astype(int)
    Fs = np.zeros(N-1).astype(int)

    for k in range(N-1):
        CSF = np.array(raw_input().split(' ')).astype(int)
        Cs[k] = CSF[0]
        Ss[k] = CSF[1]
        Fs[k] = CSF[2]

    schedule = train(Cs, Ss, Fs)
    for m in range(len(schedule)):
        print schedule[m]

def train(Cs, Ss, Fs):
    N = len(Cs)
    finaltimes = np.zeros(len(Cs) + 1).astype(int)
    arrivaltimes = 0
    destination = N - 1
    for k in range(N):
        currentloc = k
        arrivaltimes = Ss[k]
        for j in range(k, N):
            arrivaltimes = np.ceil(arrivaltimes/ Fs[j]) * Fs[j] + Cs[j]
        finaltimes[k] = int(arrivaltimes)

    return finaltimes



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
ans = [0]
N = int(input())
train = [list(map(int,input().split())) for _ in range(N-1)]
P = 0
for i in range(N-2,-1,-1):
    s = train[i][0] + train[i][1]
    if i != N-2:
        for j in range(N-2, i, -1):
            if s < ans[0]:
                s = ans[0]
            elif s % train[j][2] == 0:
                s = s
            elif s % train[j][2] != 0:
                s = s + train[j][2] - (s % train[j][2])
        s += P
    ans.insert(0,s)
    P += train[i][0]
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
ans = [0]
N = int(input())
train = [list(map(int,input().split())) for _ in range(N-1)]
P = 0
for i in range(N-2,-1,-1):
    s = train[i][0] + train[i][1]
    if i != N-2:
        for j in range(N-2, i, -1):
            if s < ans[0]:
                s = ans[0]
            elif s % train[j][2] == 0:
                s = s
            elif s % train[j][2] != 0:
                s = s + train[j][2] - (s % train[j][2])
        s += 0
    ans.insert(0,s)
    P += train[i][0]
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:

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

def arrive(time, i):
    times = -(-(time - S[i]) / F[i])
    ans = 0 if times < 0 else times
    return S[i] + F[i] * ans


def solve():
    N = int(input())
    for i in range(N-1):
        c,s,v = map(int, input().split())
        C.append(c)
        S.append(s)
        F.append(v)

    for start_sta in range(N):
        now = 0
        for station in range(start_sta,N-1):
            arr = arrive(now, station)
            now = arr + C[station]
        print(int(now))

solve()

Submission status: Wrong Answer

Solution code:

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

def arrive(time, i):
    times = -(-(time - S[i]) / F[i])
    ans = 0 if times < 0 else times
    return S[i] + F[i] * ans


def solve():
    N = int(input())
    for i in range(N-1):
        c,s,v = map(int, input().split())
        C.append(c)
        S.append(s)
        F.append(v)

    for start_sta in range(N-1):
        now = 0
        for i in range(N-start_sta-1):
            station = start_sta + i
            arr = arrive(now, station)
            now = arr + C[station]
        print(int(now))
    print("0")

solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
inputList = []
for count in range(1,N):
    C,S,F = map(int, input().split())
    tempList = [C,S,F]
    inputList.append(tempList)

outputList = []
# 最後の行
outputList.append(0)
# 下から２番目
lastC = inputList[N-2][0]
lastS = inputList[N-2][1]
outputList.insert(0, lastC+lastS)

for i in range(N-3,-1,-1):
    C = inputList[i][0]
    S = inputList[i][1]
    F = inputList[i][2]

    notArrivalFlag = False
    for j in range(N-2,i,-1):
        if C+S < inputList[j][1]:
            notArrivalFlag = True

    if notArrivalFlag:
        outputList.insert(0, outputList[0])
    else:
        sumC = 0
        for j in range(N-2,i,-1):
            sumC += inputList[j][0]
        outputList.insert(0, C+S+sumC)

for output in outputList:
    print(output)

Submission status: Wrong Answer

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

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

print(0)

Submission status: Wrong Answer

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

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

print(0)

Submission status: Wrong Answer

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

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

print(0)

Submission status: Wrong Answer

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

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

print(0)

Submission status: Wrong Answer

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

time_list = []

for i in range(n):
    total_time = 0

    for j in range(i, n-1):
        if total_time <= data[j][1]:
            total_time = data[j][1] + data[j][0]

        elif total_time % data[j][2] == 0:
            total_time += data[j][0]

        else:
            total_time += total_time - total_time % data[j][2] + data[j][0]

    time_list.append(total_time)

answer = map(str, time_list)
print("\n".join(answer))

Submission status: Wrong Answer

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

time_list = []

for i in range(n):
    total_time = 0

    for j in range(i, n-1):
        if total_time <= data[j][1]:
            total_time = data[j][1] + data[j][0]

        elif total_time % data[j][2] == 0:
            total_time += data[j][0]

        else:
            total_time += total_time % data[j][2] + data[j][0]

    time_list.append(total_time)

answer = map(str, time_list)
print("\n".join(answer))

Submission status: Wrong Answer

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

time_list = []

for i in range(n-1):
    total_time = 0

    for j in range(i, n-1):
        if total_time <= data[j][1]:
            total_time = data[j][1] + data[j][0]

        elif total_time % data[j][2] == 0:
            total_time += data[j][0]

        else:
            total_time += total_time % data[j][2] + data[j][0]

    time_list.append(total_time)

time_list.append(0)

answer = map(str, time_list)
print("\n".join(answer))

Submission status: Wrong Answer

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

time_list = []

for i in range(n-1):
    total_time = data[i][1] + data[i][0]

    for j in range(i+1, n-1):
        if total_time <= data[j][1]:
            total_time = data[j][1] + data[j][0]

        elif total_time % data[j][2] == 0:
            total_time += data[j][0]

        else:
            total_time += total_time % data[j][2] + data[j][0]

    time_list.append(total_time)

time_list.append(0)

answer = map(str, time_list)
print("\n".join(answer))

Submission status: Wrong Answer

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

time_list = []

for i in range(n-1):
    total_time  = data[i][1] + data[i][0]

    for j in range(i+1, n-1):
        if total_time <= data[j][1]:
            total_time = data[j][1] + data[j][0]

        elif total_time % data[j][2] == 0:
            total_time += data[j][0]

        else:
            total_time += total_time % data[j][2] + data[j][0]

    time_list.append(total_time)

time_list.append(0)

answer = map(str, time_list)
print("\n".join(answer))

Submission status: Wrong Answer

Solution code:
n = int(input())
X = [[int(i) for i in input().split()] for i in range(n-1)]
ans = [0 for i in range(n)]

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

        else:
            ans[j] = X[i][1] + X[i][0]

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

Submission status: Wrong Answer

Solution code:
from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  N = GI()
  CSF = [GIS() for _ in xrange(N-1)]

  for i in xrange(N):
    ct = 0  # Current Time
    for cs in xrange(i, N-1):
      #print '*' * 20, 'DEPART', cs, ct
      c, s, f = CSF[cs]
      if ct < s:
        ct = s
      elif ct % f:
        #ct += f - ct % f
        ct += f % ct
      ct += c
      #print '*' * 20, 'ARRIVE', cs, ct
    print(ct)

main()

Submission status: Wrong Answer

Solution code:
from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  N = GI()
  CSF = [GIS() for _ in xrange(N-1)]

  for i in xrange(N):
    cs = i  # Current Station
    ct = 0  # Current Time
    for cs in xrange(i, N-1):
      #print '*' * 20, 'DEPART', cs, ct
      CS = CSF[cs]
      if ct < CS[1]:
        ct = CS[1]
      elif ct > CS[1]:
        ct += ct % CS[2]
      ct += CS[0]
      #print '*' * 20, 'ARRIVE', cs, ct
    print(ct)

main()

Submission status: Wrong Answer

Solution code:
from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  N = GI()
  CSF = [GIS() for _ in xrange(N-1)]

  res = []
  for i in xrange(N):
    cs = i  # Current Station
    ct = 0  # Current Time
    while cs < N-1:
      #print '*' * 20, 'DEPART', cs, ct
      CS = CSF[cs]
      if ct < CS[1]:
        ct = CS[1]
      else:
        ct += ct % CS[2]
      ct += CS[0]
      cs += 1
      #print '*' * 20, 'ARRIVE', cs, ct
    print(ct)

main()

Submission status: Wrong Answer

Solution code:
from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  N = GI()
  CSF = [GIS() for _ in xrange(N-1)]

  res = []
  for i in xrange(N-1):
    cs = i  # Current Station
    ct = 0  # Current Time
    while cs < N-1:
      #print '*' * 20, 'DEPART', cs, ct
      CS = CSF[cs]
      if ct < CS[1]:
        ct = CS[1]
      else:
        ct += CS[2] - CS[2] % ct
      ct += CS[0]
      cs += 1
      #print '*' * 20, 'ARRIVE', cs, ct
    print(ct)
  print(0)

main()

Submission status: Wrong Answer

Solution code:
from pprint import pprint as pp
def GI(): return int(raw_input())
def GIS(): return map(int, raw_input().split())

def main():
  N = GI()
  CSF = [GIS() for _ in xrange(N-1)]

  res = []
  for i in xrange(N-1):
    cs = i  # Current Station
    ct = 0  # Current Time
    while cs < N-1:
      #print '*' * 20, 'DEPART', cs, ct
      CS = CSF[cs]
      if ct < CS[1]:
        ct = CS[1]
      else:
        ct += ct % CS[2]
      ct += CS[0]
      cs += 1
      #print '*' * 20, 'ARRIVE', cs, ct
    print(ct)
  print(0)

main()

Submission status: Wrong Answer

Solution code:
def main():
    n = int(raw_input())
    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, raw_input().split())
 
    for i in range(n):
        t = 0
        for j in range(i, n-1):
            if t <= s[j]:
                t += s[j] - t
            else:
                t += (t - s[j]) % f[j]
 
            t += c[j]
            
        print t
 

 
if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n = int(raw_input())
    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, raw_input().split())

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

            t += c[j]
            
        print t

    print 0

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n = int(raw_input())
    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, raw_input().split())

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

            t += c[j]
            
        print t

    print 0

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:

def main():
    n = int(raw_input())
    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, raw_input().split())

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

            t += c[j]
            
        print t

    print 0

if __name__=="__main__":
    main()

Submission status: Wrong Answer

Solution code:
def hoge(t, i):
	global data
	C, S, F = int(data[i][0]), int(data[i][1]), int(data[i][2])
	if S > t:
		t = S

	return ((t - S) // F) * F + C + S

if __name__ == '__main__':
	N = int(input())
	data = list()

	for i in range(N - 1):
		l = input().split()
		data.append(l)

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

Submission status: Wrong Answer

Solution code:
def hoge(t, i):
	global data
	C, S, F = int(data[i][0]), int(data[i][1]), int(data[i][2])
	if S > t:
		t = S

	return ((t - S % F) // F) * F + C + S

if __name__ == '__main__':
	N = int(input())
	data = list()

	for i in range(N - 1):
		l = input().split()
		data.append(l)

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

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

print(0)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

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

# main
for i in range(n - 1):
    count = 0
    
    for j in li[i:]:
        if count > j[1]:
            count += j[0]
        elif 0 < count <= j[1]:
            count = j[0] + j[1]
        else:
            count += j[0] + j[1]
    print(count)

print(0)

Submission status: Wrong Answer

Solution code:
# C - Special Trains
import math

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

for station in range(N):
  now = station
  time = 0
  while now != N-1:
    time = S[now] + C[now] if time <= S[now] else int(math.ceil(time/F[now]))*F[now] + C[now]
    now += 1
  result[station] = time

for i in result: print i

Submission status: Wrong Answer

Solution code:
# C - Special Trains
import math

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

for station in range(N):
  now = station
  time = 0
  while now != N-1:
    time = S[now] + C[now] if time <= S[now] else int(math.floor(time/F[now]))*F[now] + C[now]
    now += 1
  result[station] = time

for i in result: print i

Submission status: Wrong Answer

Solution code:
# C - Special Trains
import math

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

for station in range(N):
  now = station
  time = 0
  while now != N-1:
    time = S[now] + C[now] if time <= S[now] else int(math.floor((time-S[now])/F[now]))*F[now] + S[now] + C[now]
    now += 1
  result[station] = time

for i in result: print i

Submission status: Wrong Answer

Solution code:
# C - Special Trains
import math

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

for station in range(N):
  now = station
  time = 0
  while now != N-1:
    time = S[now] + C[now] if time < S[now] else int(math.floor((time-S[now])/F[now]))*F[now] + S[now] + C[now]
    now += 1
  result[station] = time

for i in result: print i

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#WA 2018-01-01 15:35:55 => Fix
N=input()
a=[tuple( map(int,raw_input().split()) ) for i in range(N-1)]
print a
 
for i in range(N-1):
	val=0
	for c,s,f in a[i::]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val+=c
			else:
				val=f*((val/f)+1)
				val+=c

	print val
print 0

Submission status: Wrong Answer

Solution code:
N=input()
a=[tuple( map(int,raw_input().split()) ) for i in range(N-1)]
 
for i in range(N-1):
	val=0
	for c,s,f in a[i::]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val+=c
			else:
				val=f*((val%f)+1)
				val+=c
	print val
print 0

Submission status: Wrong Answer

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

for i in range(N-1):
	val=0
	for c,s,f in a[i:]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val+=c
			else:
				val=val+f-(val%f)
				val=+c
	print val
print 0

Submission status: Wrong Answer

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

for i in range(N-1):
	val=0
	for c,s,f in a[i:]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val+=c
			else:
				val=f*((val/f)+1)
				val=+c
	print val
print 0

Submission status: Wrong Answer

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

for i in range(N-1):
	val=0
	for c,s,f in a[i:]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val+=c
			else:
				val=f*((val%f)+1)
				val=+c
	print val
print 0

Submission status: Wrong Answer

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

for i in range(N-1):
	val=0
	for c,s,f in a[i::]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val+=c
			else:
				val=val+f-(val%f)
				val=+c
	print val
print 0

Submission status: Wrong Answer

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

for i in range(N-1):
	val=0
	for c,s,f in a[i::]:
		if val<=s:
			val=s+c
		else:
			if val%f==0:
				val+=c
			else:
				val=f*((val%f)+1)
				val=+c
	print val
print 0

Submission status: Wrong Answer

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

for i in range(N-1):
	val=0
	for c,s,f in a[i::]:
		if val<=s:
			val=s+c
		else:
			if (val-s)%f==0:
				val+=c
			else:
				sho=(val-s)/f+1
				val=s+f*sho
				val=+c
	print val
print 0

Submission status: Wrong Answer

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

for i in range(N-1):
	val=0
	for c,s,f in a[i::]:
		if val<=s:
			val=s+c
		else:
			if (val-s)%f==0:
				val+=c
			else:
				sho=(val-s)/f+1
				val=s+f*sho
	print val
print 0

Submission status: Wrong Answer

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

d=[]	#Distance


for i in range(N-1):
	val=a[i][1]
	for c,s,f in a[i::]:
		if val<=s:
			val=s+c
		else:
			if (val-s)%f==0:
				val+=c
			else:
				sho=(val-s)/f+1
				val+=s+f*sho
	print val
print 0

Submission status: Wrong Answer

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

# C,S,FについてN-1の大きさのlistを作る
for i in range(1,N):
    a, b, c = map(int, input().split())
    C.append(a)
    S.append(b)
    F.append(c)

# Sを順番に更新して駅iに最初に列車が来る時刻のlistを作る
for i in range(1,N-1):
    if S[i] > S[i-1] + C[i-1]:
        S[i] = S[i-1] + C[i-1]

# answerを出力    
for i in range(0,N-1):
    print(S[i]+sum(C[i:]))
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
clis = [];slis =[];flis = []
for i in range(N-1):
    c,s,f = map(int,input().split())
    clis.append(c);slis.append(s);flis.append(f)
for i in range(N):
    count=0
    for i2 in range(N-i-1):
        c=clis[i+i2];s=slis[i+i2];f=flis[i+i2]
        if count <= s:
            count=s+c
        elif (count-s)%f ==0:
            count = count+c
        else:
            count = count + c + (count-s)%f
    print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
clis = [];slis =[];flis = []
for i in range(N-1):
    c,s,f = map(int,input().split())
    clis.append(c);slis.append(s);flis.append(f)
for i in range(N):
    count=0
    for i2 in range(N-i-1):
        c=clis[i+i2];s=slis[i+i2];f=flis[i+i2]
        if count < s:
            count=s+c
        elif (count-s)%f ==0:
            count = count+c
        else:
            count = count + c + (count-s)%f
    print(count)

Submission status: Wrong Answer

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

    # 逆順に計算して、結果の再利用
    res = [0] * N
    for i in range(1, N):
        res[i] = res[i - 1] + C[-i]
    # 後続の列車より早くない
    for i in range(1, N):
        res[i] = max(res[i - 1], res[i] + S[-i])

    for r in reversed(res):
        print(r)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    C = []
    S = []
    F = []
    for _ in range(N - 1):
        tmp_c, tmp_s, tmp_f = list(map(int, input().split(" ")))
        C.append(tmp_c)
        S.append(tmp_s)
        F.append(tmp_f)

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

            t += C[j]

        print(t)
    
    print(0)


solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    C = []
    S = []
    F = []
    for _ in range(N - 1):
        tmp_c, tmp_s, tmp_f = list(map(int, input().split(" ")))
        C.append(tmp_c)
        S.append(tmp_s)
        F.append(tmp_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]):
                t += t + F[j] - (t % F[j])

            t += C[j]

        print(t)


solve()

Submission status: Wrong Answer

Solution code:
def solve():
    N = int(input())
    C = []
    S = []
    F = []
    for _ in range(N - 1):
        tmp_c, tmp_s, tmp_f = list(map(int, input().split(" ")))
        C.append(tmp_c)
        S.append(tmp_s)
        F.append(tmp_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 + F[j] - (t % F[j])

            t += C[j]

        print(t)


solve()

Submission status: Wrong Answer

Solution code:
ans = [0]
N = int(input())
train = [list(map(int,input().split())) for _ in range(N-1)]
P = 0
t = 0
for i in range(N-2,-1,-1):
    s = train[i][0] + train[i][1]
    if i != N-2:
        for j in range(N-2, i, -1):
            if s % train[j][2] != 0:
                s = s + train[j][2] - (s % train[j][2])
        s += P
    if s < ans[0]:
        s = ans[0]
    ans.insert(0,s)
    P += train[i][0]
    Q = train[i][1]
    R = train[i][2]
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
ans = [0]
N = int(input())
train = [list(map(int,input().split())) for _ in range(N-1)]
P = 0
t = 0
for i in range(N-2,-1,-1):
    s = train[i][0] + train[i][1]
    if i != N-2:
        if s % R != 0:
            s += R - (s % R)
        s += P
    if s < ans[0]:
        s = ans[0]
    ans.insert(0,s)
    P += train[i][0]
    Q = train[i][1]
    R = train[i][2]
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
ans = [0]
N = int(input())
train = [list(map(int,input().split())) for _ in range(N-1)]
P = 0
t = 0
for i in range(N-2,-1,-1):
    s = train[i][0] + train[i][1]
    if i != N-2:
        s += P
        if s % R != 0:
            s += R - (s% R)
    if s < ans[0]:
        s = ans[0]
    ans.insert(0,s)
    P += train[i][0]
    Q = train[i][1]
    R = train[i][2]
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
ans = [0]
N = int(input())
train = [list(map(int,input().split())) for _ in range(N-1)]
P = 0
t = 0
for i in range(N-2,-1,-1):
    s = train[i][0] + train[i][1]
    if s < ans[0]:
        s = ans[0]
    elif i != N-2:
        s += P
        if s % R != 0:
            s += R - (s% R)
    ans.insert(0,s)
    P += train[i][0]
    Q = train[i][1]
    R = train[i][2]
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
ans = [0]
N = int(input())
train = [list(map(int,input().split())) for _ in range(N-1)]
P = 0
t = 0
for i in range(N-2,-1,-1):
    s = train[i][0] + train[i][1]
    if i != (N-2):
        s += P
        s += s % R - R + 1
    if s < ans[0]:
        s = ans[0]
    ans.insert(0,s)
    P += train[i][0]
    Q = train[i][1]
    R = train[i][2]
for i in range(N):
    print(ans[i])