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:
def slove(n, data):
    answer = []
    #answer.append(data[0][0] + data[0][1])
    for i in range(n-1):
        start = int(data[i][0]) + int(data[i][1])
        j = i + 1
        while j <= n-2:
            next = int(data[j][1])
            if start == next:
                start += int(data[j][0])
            elif start > next:
                while start == next:
                    next += int(data[j][2])
                start += (next - int(data[j][1]) + int(data[j][0]))
            else:
                start = int(data[j][0]) + int(data[j][1])
            j += 1
        answer.append(start)
    answer.append(0)

    return answer

if __name__ == "__main__":
    n = int(input())
    data = []
    for _ in range(n-1):
        data.append(input().split(" "))

    answer = slove(n, data)
    for i in range(n):
        print(answer[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):
        s += P
    if s < ans[0]:
        s = ans[0]
    ans.insert(0,s)
    P += train[i][0]
for i in range(N):
    print(ans[i])

Submission status: Wrong Answer

Solution code:
def slove(n, data):
    answer = []
    #answer.append(data[0][0] + data[0][1])
    for i in range(n-1):
        start = int(data[i][0]) + int(data[i][1])
        j = i + 1
        while j <= n-2:
        #for j in range(i+1, n-2, 1):
            next = int(data[j][1])
            if start == next:
                start += int(data[j][0])
            elif start >= next:
                while start == next:
                    next += int(data[0][2])
                start += (next - int(data[j][1]) + int(data[j][0]))
            else:
                start = int(data[j][0]) + int(data[j][1])
            j += 1
        answer.append(start)
    answer.append(0)

    return answer

if __name__ == "__main__":
    n = int(input())
    data = []
    for _ in range(n-1):
        data.append(input().split(" "))

    answer = slove(n, data)
    for i in range(n):
        print(answer[i])

Submission status: Wrong Answer

Solution code:
def slove(n, data):
    print("coll")
    answer = []
    #answer.append(data[0][0] + data[0][1])
    for i in range(n-1):
        start = int(data[i][0]) + int(data[i][1])
        j = i + 1
        while j <= n-2:
        #for j in range(i+1, n-2, 1):
            next = int(data[j][1])
            if start == next:
                start += int(data[j][0])
            elif start >= next:
                while start == next:
                    next += int(data[0][2])
                start += (next - int(data[j][1]) + int(data[j][0]))
            else:
                start = int(data[j][0]) + int(data[j][1])
            j += 1
        answer.append(start)
    answer.append(0)

    return answer

if __name__ == "__main__":
    n = int(input())
    data = []
    for _ in range(n-1):
        data.append(input().split(" "))

    answer = slove(n, data)
    for i in range(n):
        print(answer[i])

Submission status: Wrong Answer

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

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

'''
print('C ', C)
print('S ', S)
print('F ', F)
'''

ans = {}
for i in range(N-1):
    ans[i] = S[i]
    for j in range(N-1-i):
        ans[i] += C[j+i]

for k in ans:
    print(ans[k])

print(0) # 最後の駅

Submission status: Wrong Answer

Solution code:
# coding: utf-8

N = int(raw_input())
CSF = [map(int, raw_input().split()) for _ in range(N-1)]

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]

    for j in range(i+1, N-1):
        s, t, u = CSF[j][0], CSF[j][1], CSF[j][2]
        if t < ans:
            ans = int(s + t + u * (ans - t) / u)
        else:
            ans = s + t

    print ans

print 0

Submission status: Wrong Answer

Solution code:
n = int(input())
cn = []
sn = []
fn = []
for i in range(n-1):
    ci, si, fi = map(int, input().split())
    cn.append(ci)
    sn.append(si)
    fn.append(fi)

ans = [0] * n

for i in range(n-1):
     c = cn[i]
     s = sn[i]
     f = fn[i]
     ans[i] += s + c
     t = ans[i]
     for j in range(i+1, n-1):
        c2 = cn[j]
        s2 = sn[j]
        f2 = fn[j]
        if s2 <= t and t % f2 == 0:
            w = 0
        elif s2 > t:
            w = s2 - t
        else:
            if t - s2 > f:
                w = t % f2
        ans[i] += w+c2
        t = ans[i]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line.rstrip("\n"))

        timestamps = [0]
        for i in xrange(N - 1):
            if i > 0:
                timestamps.append(0)

            c, s, f = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))

            for i in xrange(len(timestamps)):
                if timestamps[i] <= s:
                    timestamps[i] = s + c
                else:
                    timestamps[i] += timestamps[i] % f + c

        for timestamp in timestamps:
            print timestamp
        print 0

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math

N = int(raw_input())
CSF = [map(int, raw_input().split()) for _ in range(N-1)]

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]

    for j in range(i+1, N-1):
        s, t, u = CSF[j][0], CSF[j][1], CSF[j][2]
        if t < ans:
            ans = int(s + t + u * math.ceil((ans - t) / u))
        else:
            ans = s + t

    print ans

print 0

Submission status: Wrong Answer

Solution code:
# coding:utf-8                                                                                     

N = int(raw_input())
C = []
S = []
F = []

for i in range(N-1):
    c, s, f = map(int, raw_input().split())
    C.append(c)
    S.append(s)
    F.append(f)

res = []
T = []

for i in range(N-1):
    t = 0
    for j in range(i, N-1):
        if S[j] >= t:
            t = 0
            t += S[j] + C[j]
        elif t % F[j] == 0:
            t += C[j]
        else:
            t = t + F[j] - (t - (S[j] + F[j] * (t-S[j])/F[j])) + C[j]
    T.append(t)

for t in T:
    print t
print 0

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
sta = []

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

for i in range(n):
    time = 0
    while i < n - 1:
        x = int((time - sta[i]['s']) / sta[i]['f']) if time > sta[i]['s'] else 0
        time = sta[i]['s'] + sta[i]['f'] * x + sta[i]['c']
        i += 1
    print(str(time))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line.rstrip("\n"))

        timestamps = [0]
        for i in xrange(N - 1):
            if i > 0:
                timestamps.append(0)

            c, s, f = map(
              lambda i: int(i), sys.stdin.readline().rstrip("\n").split(" "))

            for i in xrange(len(timestamps)):
                if timestamps[i] <= s:
                    timestamps[i] = s + c
                else:
                    if timestamps[i] % f == 0:
                        timestamps[i] += c

        for timestamp in timestamps:
            print timestamp
        print 0

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Submission status: Wrong Answer

Solution code:
n = int(input())

if n == 1:
  s = list(map(int, input().split()))
else:
  s = []
  for i in range(n-1):
    s.append(list(map(int, input().split())))

for i in range(n-1):
  sum = s[i][0] + s[i][1]
  for j in range(i+1, n-1):
    if j == n:
      break
    if s[j][1] >= sum:
      sum = s[j][1]
      sum += s[j][0]
    else:
      sum += s[j][0]
  
  print(sum)

if n == 1:
  print(s[0] + s[1])
print(0)

Submission status: Wrong Answer

Solution code:
def special_trains(time, c, s, f):
	if time < s:
		return s+c
	else:
		buff = (time-s) % f
		return time+buff+c

def loop(start, N, C,S,F):

	time = 0
	for i in range(start, N-1):
		time = special_trains(time, C[i], S[i], F[i])

	print(time)

N = int(input())
C = list()
S = list()
F = list()

for i in range(N-1):
	C_i, S_i, F_i = map(int, input().split())
	C.append(C_i)
	S.append(S_i)
	F.append(F_i)


for i in range(N-1):
	loop(i, N, C, S, F)
print("0")

Submission status: Wrong Answer

Solution code:
N = int(input())
array = []

for i in range(N-1):
  _input = str(input()).split(' ')
  array.append((int(_input[0]), int(_input[1])))

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


print(0)

Submission status: Wrong Answer

Solution code:

n = int(input())
cn = []
sn = []
fn = []
for i in range(n-1):
    ci, si, fi = map(int, input().split())
    cn.append(ci)
    sn.append(si)
    fn.append(fi)

ans = [0] * n

for i in range(n-1):
     c = cn[i]
     s = sn[i]
     f = fn[i]
     ans[i] += s + c
     t = ans[i]
     for j in range(i+1, n-1):
        c2 = cn[j]
        s2 = sn[j]
        f2 = fn[j]
        if s2 <= t and t % f2 == 0:
            w = 0
        else:
            w = s2 - t
        ans[i] += w+c2
        t = ans[i]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
C = [0] * (N - 1)
S = [0] * (N - 1)
F = [0] * (N - 1)

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

for i in range(1, N + 1):
    t = 0
    for n in range(i - 1, N - 1):
        if t < S[n]:
            t = S[n]
        else:
            t = t + t % F[n]
        t = t + C[n]
    print(t)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math
N = int(input())
Cs = []
Ss = []
Fs = []
for n in range(N-1):
    C, S, F = map(int, input().split())
    Cs.append(C)
    Ss.append(S)
    Fs.append(F)

for n in range(N-1):
    current_time = 0
    for i in range(n,N-1,1):
        if Ss[i] - current_time <= 0:
            wait_time = (current_time + Ss[i]) % Fs[i]
            #print('after first train')
            #print(n, i, wait_time)
        else:
            wait_time = (Ss[i] - current_time)
            #print('before first train')
            #print(n, i, wait_time)
        current_time += wait_time
        current_time += Cs[i]
        #print("current_time", current_time)
    print(current_time)
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
data=[]
for i in range(N-1):
  tmp=input().split(' ')
  data.append(tmp)
for i in range(N-1):
  time=0
  for j in range(N-1-i):
    k=j+i
    if time<=int(data[k][1]):
      time=int(data[k][1])+int(data[k][0])
    else:
      num=time%int(data[k][2])
      time=time-num+int(data[k][0])
  print(time)
print(0)

Submission status: Wrong Answer

Solution code:
N = int(input())
c = []
s = []
f = []
for _ in range(N - 1):
    _c, _s, _f = [int(x) for x in input().split()]
    c.append(_c)
    s.append(_s)
    f.append(_f)

def solve(i):
    start_time = 0
    for j in range(i, N - 1):
        # print("---")
        # print(j)
        # print("start_time: {}".format(start_time))
        depart_time = get_dep_time(start_time, s[j], f[j])
        # print("depart_time: {}".format(depart_time))
        arrived_time = depart_time + c[j]
        # print("arrived_time: {}".format(arrived_time))
        start_time = arrived_time
    return arrived_time

def get_dep_time(start, s, f):
    """
    E.g.:
        start = 18
        s = 15
        f = 5
        ret = 20
        start = 13
        s = 15
        f = 5
        ret = 15
    """
    if start % f == 0:
        t = start
    else:
        t = (start / f + 1) * f
    if start > s:
        return t
    else:
        return s

for i in range(N - 1):
    # print("===")
    # print("solving {}".format(i))
    print(solve(i))
    # print("===")
print(0)

Submission status: Wrong Answer

Solution code:

n = int(input())
cn = []
sn = []
fn = []
for i in range(n-1):
    ci, si, fi = map(int, input().split())
    cn.append(ci)
    sn.append(si)
    fn.append(fi)

ans = [0] * n

for i in range(n-1):
     c = cn[i]
     s = sn[i]
     f = fn[i]
     ans[i] += s + c
     t = ans[i]
     for j in range(i+1, n-1):
        c2 = cn[j]
        s2 = sn[j]
        f2 = fn[j]
        if s2 <= t:
            w = 0
        else:
            w = s2 - t
        ans[i] += w+c2
        t = ans[i]
for i in ans:
    print(i)

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
c = np.zeros((n-1), dtype=np.int)
s = np.zeros((n-1), dtype=np.int)
f = np.zeros((n-1), dtype=np.int)
for i in range(n-1):
    c[i], s[i], f[i] = map(int, input().split(" "))

t = np.zeros(n, dtype=np.int)
for i in range(n-1):
    w = np.zeros((n-1), dtype=np.int)
    w = s
    t[i] = s[i] + c[i]
    for j in range((i+1), (n-1), 1):
        if(w[j] >= t[i]):
            t[i] = w[j]
        t[i] += c[j]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
def gcd(a, b):
  while b:
    a,b = b,a%b
  return a
def lcm(a, b):
   return a*b//gcd(a, b)
CSF = []
for i in range(n-1):
  CSF.append(list(map(int, input().split())))
for i in range(n-1):
  s = CSF[i][1]
  for j in range(i,n-1):
    s += CSF[j][0]
    if j < n-2:
      if s < CSF[j+1][1]:
        s = CSF[j+1][1]
      if s%CSF[j+1][2] != 0:
        s = lcm(s, CSF[j+1][2])
  print(s)
print(0)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = [None for i in range(n-1)]
s = [None for i in range(n-1)]
f = [None for i in range(n-1)]
for i in range(n-1):
    c[i], s[i], f[i] = list(map(int, input().split()))
answer = [0 for i in range(n)]
for i in range(n-1):
    for j in range(i, n-1):
        if answer[i] > s[j]:
            answer[i] += c[j]
        else:
            answer[i] = s[j] + c[j]
for i in answer:
    print (i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
c = []
s = []
f = []
for _ in range(N - 1):
    _c, _s, _f = [int(x) for x in input().split()]
    c.append(_c)
    s.append(_s)
    f.append(_f)

def solve(i):
    start_time = 0
    for j in range(i, N - 1):
        # print("---")
        # print(j)
        # print("start_time: {}".format(start_time))
        depart_time = get_dep_time(start_time, s[j], f[j])
        # print("depart_time: {}".format(depart_time))
        arrived_time = depart_time + c[j]
        # print("arrived_time: {}".format(arrived_time))
        start_time = arrived_time
    return arrived_time

def get_dep_time(start, s, f):
    """
    E.g.:
        start = 18
        s = 15
        f = 5
        ret = 20
        start = 13
        s = 15
        f = 5
        ret = 15
    """
    if start % f == 0:
        t = start
    else:
        t = (start / f + 1) * f
    if start >= s:
        return t
    else:
        return s

for i in range(N - 1):
    # print("===")
    # print("solving {}".format(i))
    print(solve(i))
    # print("===")
print(0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
data=[]
for i in range(N-1):
  tmp=input().split(' ')
  data.append(tmp)
for i in range(N-1):
  time=0
  for j in range(N-1-i):
    j=j+i
    if time<=int(data[j][1]):
      time=int(data[j][1])+int(data[j][0])
    else:
      time=time-time%int(data[j][2])+int(data[j][0])
  print(time)
print(0)

Submission status: Wrong Answer

Solution code:
num = int(input())
array = []
for i in range(num-1):
    array.append([int(x) for x in input().split()])
res_array = []
for j in range(len(array)):
    tmp = array[j][0]+array[j][1]
    for k in array[j+1:]:
        if tmp < k[1]:
            tmp = k[1]
            tmp += k[0]
        else:
            tmp += k[0]
    res_array.append(tmp)
for i in res_array:
    print(i)
print(0)

Submission status: Wrong Answer

Solution code:
from pprint import pprint as pp
"""
問題文
Atcoder国に、 1 本の東西方向に走る鉄道が完成しました。
この鉄道には N 個の駅があり、西から順に 1,2,…,N の番号がついています。
明日、鉄道の開通式が開かれます。
この鉄道では、1≦i≦N−1 を満たす全ての整数 i に対して、駅 i から駅 i+1 に、Ci 秒で向かう列車が運行されます。
ただし、これら以外の列車は運行されません。
駅 i から駅 i+1 に移動する列車のうち最初の列車は、開通式開始 Si 秒後に駅 i を発車し、その後は 
Fi 秒おきに駅 i を発車する列車があります。
また、Si は Fi で割り切れることが保証されます。
つまり、A%B で A を B で割った余りを表すとき、Si≦t,t%Fi=0 を満たす全ての t に対してのみ、
開通式開始 t 秒後に駅 i を出発し、開通式開始 t+Ci 秒後に駅 i+1 に到着する列車があります。
列車の乗り降りにかかる時間を考えないとき、全ての駅 i に対して、開通式開始時に駅 i にいる場合、
駅 N に到着できるのは最も早くて開通式開始何秒後か、答えてください。
制約
    1≦N≦500
    1≦Ci≦100
    1≦Si≦105
    1≦Fi≦100
    Si%Fi=0
    入力は全て整数
入力
入力は以下の形式で標準入力から与えられる。

N
C1 S1 F1
:
CN−1 SN−1 FN−1

出力
i 行目 (1≦i≦N) に、開通式開始時に駅 i にいる場合、駅 N に到着できるのが最も早くて開通式開始 x 秒後のとき、x を出力せよ。
"""
n=int(input())
csf = []
for _ in range(n-1):
  csf.append(list(map(int, input().split())))

ts = []

for i in range(n-1):
  t = csf[i][1]
  for c,s,f in csf[i:]:
    if t < s:
      t = s
    t += t % f
    t += c
  ts.append(t)
ts.append(0)

for t in ts:
  print(t)

Submission status: Wrong Answer

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


for i in range(N-1):
	C = info[i][0]
	S = info[i][1]
	F = info[i][2]
	next_arrive = []
	for j in arrive:
		if j <= S:
			next_arrive.append(S+C)
		else:
			if (j - S) % F == 0:
				next_arrive.append(j+C)
			else:
				next_arrive.append(j + F*(((j-S) // F)+1) + C)

	next_arrive.append(S+C)
	arrive = next_arrive[:]

arrive.append(0)

for ans in arrive:
	print(ans)

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

Submission status: Wrong Answer

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

for i in range(n-1):
  sum = s[i][0] + s[i][1]
  for j in range(i+1, n-1):
    if j == n:
      break
    if s[j][1] >= sum:
      sum = s[j][1]
      sum += s[j][0]
    else:
      sum += s[j][0]
  
  print(sum)

print(0)

Submission status: Wrong Answer

Solution code:
n = input()
t = [map(int, raw_input().split()) for _ in xrange(n-1)]

for i in xrange(n-1):
    s = t[i][1]
    for j in xrange(i, n-1):
        if s >= t[j][1]:
            s += (s - t[j][1]) % t[j][2]
            s += t[j][0]
        else:
            s = t[j][0] + t[j][1]
    print s
print 0

Submission status: Wrong Answer

Solution code:
n = input()
t = [map(int, raw_input().split()) for _ in xrange(n-1)]

for i in xrange(n-1):
    s = t[i][1]
    for j in xrange(i, n-1):
        if s >= t[j][1]:
            s += t[j][0]
        else:
            s = t[j][0] + t[j][1]
    print s
print 0

Submission status: Wrong Answer

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

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


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

for i in range(n):
    now = 0
    for c, s, f in csf[i::]:
        while now > s:
            s += f
        now += s - now
        now += c
    print(now)

Submission status: Time Limit Exceeded

Solution code:
# coding = SJIS

n = int(input())
sta = []
for i in range(n - 1):
    a, b, c = map(int, input().split())
    sta.append([a, b, c])
ans = []

for i in range(n - 1):
    time = 0
    for j in range(n - i - 1):
        while sta[i + j][1] > time:
            time += 1
        while (time - sta[i + j][1]) % sta[i + j][2] != 0:
            time += 1
        time += sta[i + j][0]
    print(time)
print(0)

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    c1, s1, f1 = arr[i]
    ct = s1+c1
    for j in range(i+1, n-1):
        c2, s2, f2 = arr[j]
        while ct > s2:
            s2 += f2
        ct = s2 + c2
    print (ct)
print (0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
csf = [list(map(int,input().split())) for i in range(n-1)]
t = [[0] * n for i in range(n)]
for i in range(n-1):
    cc, cs, cf = csf[i][0], csf[i][1], csf[i][2]
    t[i][i] = cs
    for j in range(1+i):
        cs = csf[i][1]
        while t[j][i] > cs:
            cs += cf
        t[j][i+1] = cs + cc 
for i in range(n):
    print(t[i][n-1])

Submission status: Time Limit Exceeded

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

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

res = [0]
res.append(ab[n-2][0]+ab[n-2][1])

for i in range(n-3,-1,-1):
    temp = ab[i][0]+ab[i][1]
    if temp <= ab[i+1][1]:
        res.append(res[-1])
    else:
        for j in range(i,n-2):
            for k in range(0,100010):
                if temp <= ab[j+1][1] + ab[j+1][2]*k:
                    temp = ab[j+1][1]+ab[j+1][2]*k +ab[j+1][0] 
                    break
        res.append(temp)

for l in range(n-1,-1,-1):
    print(res[l])

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    stats = stations[i:]
    t = 0
    for c, s, f in stats:
        if t <= s:
            t = s
        else:
            temp = s
            while temp < t:
                temp += f
            t = temp
        t += c
    print(t)
print(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline


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


def solve(N, CSF, SMAX=200000):
    dp = [[0 for t in range(SMAX)] for i in range(N)]
    for i in range(N):
        dp[i][0] = 1
    for i in range(N-1):
        c, s, f = CSF[i]
        for t in range(s, SMAX-c, f):
            if t == s:
                dp[i+1][t+c] = sum(dp[i][:t+1])
            else:
                dp[i+1][t+c] = sum(dp[i][t-f+1:t+1])
    ans = []
    for t in range(SMAX):
        while dp[N-1][t] > 0:
            ans.append(t)
            dp[N-1][t] -= 1
    for a in ans[::-1]:
        print(a)



if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Time Limit Exceeded

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

for i in range(n-1):
    t = li[i][1] + li[i][0]
    for j in range(i+1,n-1):
        while True:
            if t >= li[j][1] and t%li[j][2] == 0:
                break
            else:
                t += 1
        t += li[j][0]
    print(t)
print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

c, s, f = [], [], []
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

for i in range(n-1):
    ans = 0
    for j in range(i, n-1):
        for k in range(10**8):
            tmp = s[j] + f[j] * k
            if ans <= tmp:
                ans = tmp + c[j]
                break
    else:
        print(ans)

print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

c, s, f = [], [], []
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        for k in range(10**8):
            if tmp <= s[j] + f[j] * k:
                tmp = s[j] + f[j] * k + c[j]
                break
    else:
        print(tmp)

print(0)

Submission status: Time Limit Exceeded

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

anss =[]
for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        for k in range(10**8):
            if tmp <= s[j] + f[j] * k:
                tmp = s[j] + f[j] * k + c[j]
                break
            else:
                k += 1
    else:
        anss.append(tmp)
else:
    anss += [0]

for ans in anss:
    print(ans)

Submission status: Time Limit Exceeded

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

ans_g =[]
for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        for k in range(10**8):
            if tmp <= l[j][1] + l[j][2] * k:
                tmp = l[j][1] + l[j][2] * k + l[j][0]
                break
            else:
                k += 1
    else:
        ans_g.append(tmp)

for ans in ans_g:
    print(ans)

print(0)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

c, s, f = [], [], []
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

anss =[]
for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        for k in range(10**8):
            if tmp <= s[j] + f[j] * k:
                tmp = s[j] + f[j] * k + c[j]
                break
    else:
        anss.append(tmp)
else:
    anss += [0]

for ans in anss:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

c, s, f = [], [], []
for _ in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)

anss =[]
for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        k = 0
        while 1:
            if tmp <= s[j] + f[j] * k:
                tmp = s[j] + f[j] * k + c[j]
                break
            else:
                k += 1
    else:
        anss.append(tmp)
else:
    anss += [0]

for ans in anss:
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

c = [0] * n
f = [0] * n
s = [0] * n

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

lapse = [0] * n

for i in range(n):
    for j in range(i + 1, n):

        t = 0
        while s[j - 1] + t * f[j - 1] < lapse[i]:
            t += 1

        lapse[i] = s[j - 1] + t * f[j - 1] + c[j - 1]

    print(lapse[i])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
inputs = [list(map(int,input().split())) for i in range(n-1)]
out = []
for station_st in range(n-1):
    spend_time = inputs[station_st][1]+inputs[station_st][0] #次の駅に着く時間

    for st_num_cur in range(station_st+1,n-1):
        train_leave_time = inputs[st_num_cur][1] 
        train_i = 0
        while(inputs[st_num_cur][1]+inputs[st_num_cur][2]*train_i < spend_time):
            train_i += 1
        train_leave_time = inputs[st_num_cur][1] + inputs[st_num_cur][2]*train_i
        spend_time = train_leave_time+inputs[st_num_cur][0] #次の駅で乗れる電車が出発する時間
    print(spend_time)
print(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

Cost = [0]
Start = [0]
Frequency = [0]


for __ in range(N-1):
    c, s, f = map(int, input().split())
    Cost.append(c)
    Start.append(s)
    Frequency.append(f)
a = sum(Cost) + max(Start) + sum(Frequency)
DP = [[0] * (2 * a) for _ in range(N+1)]

for i in range(N-1, 0, -1):
    for j in range(a, -1, -1):
        if j < Start[i]:
            DP[i][j] = DP[i][Start[i]] + Start[i] - j
        elif j >= Start[i]:
            sa = j % Frequency[i]
            if sa == 0:
                DP[i][j] = DP[i+1][j+Cost[i]] + Cost[i]
            else:
                DP[i][j] = DP[i][j + Frequency[i] - sa] + Frequency[i] - sa
for i in range(N):
    print(DP[i+1][0])