Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().rstrip().split()))
B=list(A[i]-i for i in range(N))
C=B.sort()
work=C[N//2]
testA=sum(abs(B[i]-work) for i in range(N))
testB=sum(abs(B[i]-work-1) for i in range(N))
testC=sum(abs(B[i]-work+1) for i in range(N))
output=min(testA,testB,testC)
print(output)

Fixed submission:
N=int(input())
A=list(map(int, input().rstrip().split()))
B=list(A[i]-i for i in range(N))
C=list(A[i]-i for i in range(N))
C.sort()
work=C[N//2]
testA=sum(abs(B[i]-work) for i in range(N))
testB=sum(abs(B[i]-work-1) for i in range(N))
testC=sum(abs(B[i]-work+1) for i in range(N))
output=min(testA,testB,testC)
print(output)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int, input().rstrip().split()))
work=int()
testA=int()
testB=int()
testC=int()
work=sum(A)//N-N//2
test=list((sum(abs(A[i]-i-work+N//2-j) for i in range(N))) for j in range(N))
output=min(test)
print(output)

Fixed submission:
N=int(input())
A=list(map(int, input().rstrip().split()))
B=list(A[i]-i for i in range(N))
C=list(A[i]-i for i in range(N))
C.sort()
work=C[N//2]
testA=sum(abs(B[i]-work) for i in range(N))
testB=sum(abs(B[i]-work-1) for i in range(N))
testC=sum(abs(B[i]-work+1) for i in range(N))
output=min(testA,testB,testC)
print(output)
Buggy python submission (verdict: Runtime Error):
A=int(input())
B=int(input())
ans=str()
if max(A,B)<9:
    ans="Yay!"
else:
    ans=":("
print(ans)

Fixed submission:
A,B=map(int, input().rstrip().split())
ans=str()
if max(A,B)<9:
    ans="Yay!"
else:
    ans=":("
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
A,B,K=map(int, input().rstrip().split()) #input parameters\
work=[] #make list
for i in range(A,B+1):
    if (A<=i and i<A+K) or (B-K<i and i<=B):
        print(i)

Fixed submission:
A,B,K=map(int, input().rstrip().split()) #input parameters\
work=[] #make list
for i in range(0,K):
    if A+i<=B:
        print(A+i)
for i in range(0,K):
    if B-K+i+1>=A+K:
        print(B-K+i+1)
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())

INF = 10001
minimum = INF
for i in range(N):
    c,t = map(int, input())
    if t <= T:
        minimum = min(minimum, c)

if minimum == INF:
    print('TLE')
else
    print(minimum)



Fixed submission:
N, T = map(int, input().split())

INF = 10001
minimum = INF
for i in range(N):
    c, t = map(int, input().split())
    if t <= T:
        minimum = min(minimum, c)

if minimum == INF:
    print('TLE')
else:
    print(minimum)
Buggy python submission (verdict: Runtime Error):
n, m, q = map(int, input().split())
cum = [[0]
for i in range(m):
    li, ri = map(int, input().split())
    lis.append(li)
    ris.append(ri)

for i in range(q):
    pi, qi = map(int, input().split())
    total = 0
    for (li, ri) in zip(lis, ris):
        if pi <= li and ri <= qi:
            total += 1
    print(total)



Fixed submission:
n, m, qq = map(int, input().split())
lr = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    lr[l - 1][r - 1] += 1

for i in range(n):
    for j in range(n - 1):
        lr[i][j + 1] += lr[i][j]
for j in range(n):
    for i in range(n-1, 0, -1):
        lr[i - 1][j] += lr[i][j]

for _ in range(qq):
    p, q = map(int, input().split())
    if q == n:
        print(lr[p - 1][q - 1])
    else:
        print(lr[p - 1][q - 1] - lr[q][q - 1])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())
lis = []
ris = []
for i in range(m):
    li, ri = map(int, input().split())
    lis.append(li)
    ris.append(ri)
pis = []
qis = []

for i in range(q):
    pi, qi = map(int, input().split())
    pis.append(pi)
    qis.append(qi)

for (pi, qi) in zip(pis, qis):
    total = 0
    for (li, ri) in zip(lis, ris):
        if pi <= li and ri <= qi:
            total += 1
    print(total)




Fixed submission:
n, m, qq = map(int, input().split())
lr = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    lr[l - 1][r - 1] += 1

for i in range(n):
    for j in range(n - 1):
        lr[i][j + 1] += lr[i][j]
for j in range(n):
    for i in range(n-1, 0, -1):
        lr[i - 1][j] += lr[i][j]

for _ in range(qq):
    p, q = map(int, input().split())
    if q == n:
        print(lr[p - 1][q - 1])
    else:
        print(lr[p - 1][q - 1] - lr[q][q - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

amounts = [0] * N

for n in range(N):
    spot = A[:n] + A[(n+1):]

    amount = 0
    for i in range(1, N - 1):
        amount += abs(spot[i-1] - spot[i])
    amount += abs(spot[0])
    amount += abs(spot[N - 2])
    amounts[n] = amount

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


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

total = 0
total = abs(A[0])
total += abs(A[N - 1])
for i in range(1, N):
    total += abs(A[i - 1] - A[i])

amounts = [0] * N
for i in range(N):
    left = 0
    right = 0
    if i > 0:
        left = A[i - 1]
    if i < N - 1:
        right = A[i + 1]
    amounts[i] = total + abs(left - right) - (abs(left - A[i]) + abs(A[i] - right))

for i in range(N):
    print(amounts[i])
Buggy python submission (verdict: Runtime Error):
coin500 = int(input())
coin100 = int(input())
coin50 = int(input())
total = int(input())

ans = 0
for i_500 in range(coin500 + 1):
    for i_100 in range(coin100 + 1):
        for i_50 in range(coin50 + 1):
            if 500 * i_500 + 100 * i_100 + 50 * i_50 = total:
                ans += 1
print(ans)


Fixed submission:
coin500 = int(input())
coin100 = int(input())
coin50 = int(input())
total = int(input())

ans = 0
for i_500 in range(coin500 + 1):
    for i_100 in range(coin100 + 1):
        for i_50 in range(coin50 + 1):
            if 500 * i_500 + 100 * i_100 + 50 * i_50 == total:
                ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
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 = s[j]
        elif (total - s[j]) % f[j] == 0:
            total += f[j] - total % f[j]
        total += c[j]

    print(total)

print(0)


Fixed submission:
n = int(input())
print(48 - n)
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))

cnt = 0
while all(a % 2 == 0 for i in A):
  A = [a / 2 for a in A]
  cnt += 1
print(cnt)

Fixed submission:
n = int(input())
nums = list(map(int, input().split()))
cnt = 0
while all(num % 2 == 0 for num in nums):
    nums = [num / 2 for num in nums]
    cnt += 1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())

if N==1:
  print('Hello World')

else:
  print(A+B)

Fixed submission:
N = int(input())
 
if N==1:
  print('Hello World')
 
else:
  A = int(input())
  B = int(input())
  print(A+B)
Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split(' '))

List = []
 
for _ in range(N):
  list = list(map(int,input().split(' ')))
  List.append(list)
 
List = [x[0] for x in List if x[1]<=T]
  
print(min(List))

Fixed submission:
N,T = map(int,input().split(' '))

clist = []
tlist = []

for _ in range(N):
  L = list(map(int,input().split(' ')))
  clist.append(L[0])
  tlist.append(L[1])
  
List = [c for c,t in zip(clist,tlist) if t<=T]

if len(List):
  print(min(List))
else:
  print('TLE')

Buggy python submission (verdict: Runtime Error):
N,T = map(int,input().split(' '))

for _ in range(N):
  list = list(map(int,input().split(' ')))
  List.append(list)

List = [x[0] for x in List if x[1]<=T]
  
print(min(List))

Fixed submission:
N,T = map(int,input().split(' '))

clist = []
tlist = []

for _ in range(N):
  L = list(map(int,input().split(' ')))
  clist.append(L[0])
  tlist.append(L[1])
  
List = [c for c,t in zip(clist,tlist) if t<=T]

if len(List):
  print(min(List))
else:
  print('TLE')
Buggy python submission (verdict: Runtime Error):
count = 0
N,M,X,Y = list(map(int,input().split(' ')))
XL = list(map(int,input().split(' ')))
YL = list(map(int,input().split(' ')))

XL.sort()
YL.sort()

for z range(X+1,Y+1):
	if z>XL[N-1] and z<=YL[0]:
		count = 1 

if count>0:
	print('No war')
else:
	print('war')

Fixed submission:
count = 0
N,M,X,Y = list(map(int,input().split(' ')))
XL = list(map(int,input().split(' ')))
YL = list(map(int,input().split(' ')))
 
for z in range(X+1,Y+1):
  if z>max(X,max(XL)) and z<=min(Y,min(YL)):
    count += 1 

if count>0:
  print('No War')
else:
  print('War')
Buggy python submission (verdict: Runtime Error):
n,k = int(input().split(' '))
s = 1
if n%k==0:
	s-=1
print(s)

Fixed submission:
n = list(map(int,input().split(' ')))
s = 1
if n[0]%n[1]==0:
	s-=1
print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = 1+n//4
q = ['No','Yes']
s = 0
for a in range(x):
	if (n-a*4)%7==0:
    	s = 1
        
print(q[s])

Fixed submission:
n = int(input())
x = 1+n//4
q = ['No','Yes']
s = 0
for a in range(x):
  if (n-a*4)%7==0:
    s += 1
    break
        
print(q[s])
Buggy python submission (verdict: Runtime Error):
import statistics
N = int(input())
L = list(map(int,input().split( )))
f1 = [li-j for li,j in zip(L,range(1+N+1))]
b = statistics.median(f1)
if N%2 != 0:
	ans = sum([abs(li-j-b) for li,j in zip(L,range(1+N+1))])
else:
	b1 = f1[int(b/2-0.5)]
	b2 = f1[int(b/2+0.5)]
	ans1 = sum([abs(li-j-b1) for li,j in zip(L,range(1+N+1))])
	ans2 = sum([abs(li-j-b2) for li,j in zip(L,range(1+N+1))])
	ans = min(ans1,ans2)
print(ans)

Fixed submission:
import statistics
N = int(input())
L = list(map(int,input().split( )))
f1 = [li-j for li,j in zip(L,range(1+N+1))]
b = statistics.median(f1)
if N%2 != 0:
	ans = sum([abs(li-j-b) for li,j in zip(L,range(1+N+1))])
else:
	b1 = int(b+0.5)
	b2 = int(b-0.5)
	ans1 = sum([abs(li-j-b1) for li,j in zip(L,range(1+N+1))])
	ans2 = sum([abs(li-j-b2) for li,j in zip(L,range(1+N+1))])
	ans = min(ans1,ans2)
print(ans)
Buggy python submission (verdict: Runtime Error):
count = 0
N,K = map(int,input().split( ))
J = list(map(int,input().split( )))
for i,j in zip(range(N),J):
    if j==1:
        s = i
        t = N-1-i
for _ in range(N+N):
    if s<=0:
        break
    else:
        s -= K-1
        count += 1

for _ in range(N+N):
    if t<=0:
        break
    else:
        t -= K-1
        count += 1
        
if N<=K:
    count = 1
print(count)

Fixed submission:
kazu = 0
S = input()
for s in S:
    if s=='+':
        kazu += 1
    else:
        kazu -= 1
        
print(kazu)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')

Fixed submission:
a,b = map(int,input().split( ))
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')

Fixed submission:
a,b = map(int,input().split( ))
if a <= 8 and b <= 8:
    print('Yay!')
else:
    print(':(')
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split( ))
if b!=100:
    x = b*100**a
else:
    101*100**a
print(x)

Fixed submission:
a,b = map(int,input().split( ))
if b!=100:
    for r in range(a):
        b *= 100
else:
    c = b+1
    for r in range(a):
        c *= 100
    b = c
print(b)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split( ))
if b!=100:
    x = b*100**a
else:
    101*100**a
print(x)

Fixed submission:
a,b = map(int,input().split( ))
if b!=100:
    for r in range(a):
        b *= 100
else:
    c = b+1
    for r in range(a):
        c *= 100
    b = c
print(b)

Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split( ))
if b!=100:
    x = b*100**a
else:
    101*100**a
print(x)

Fixed submission:
a,b = map(int,input().split( ))
if b!=100:
    for r in range(a):
        b *= 100
else:
    c = b+1
    for r in range(a):
        c *= 100
    b = c
print(b)
Buggy python submission (verdict: Runtime Error):
import functools
import operator

count = 0
N = int(input())
L = list(map(int,input().split( )))

L2 = functools.reduce(operator.mul,L)

for l in range(L2):
    if L2%2 == 0:
        L2 /= 2
        count += 1
    else:
        break

print(count)

Fixed submission:
count = 0
N = int(input())
L = list(map(int,input().split( )))

for n in range(N):
    for l in range(L[n]):
        if L[n]%2 == 0:
            L[n] /= 2
            count += 1
        else:
            break
            
print(count)

Buggy python submission (verdict: Runtime Error):
import functools
import operator

count = 0
N = int(input())
L = list(map(int,input().split( )))

L2 = functools.reduce(operator.mul,L)

for l in range(L2):
    if L2%2 == 0:
        L2 /= 2
        count += 1
    else:
        break

print(count)

Fixed submission:
count = 0
N = int(input())
L = list(map(int,input().split( )))

for n in range(N):
    for l in range(L[n]):
        if L[n]%2 == 0:
            L[n] /= 2
            count += 1
        else:
            break
            
print(count)
Buggy python submission (verdict: Runtime Error):
x = list(map(int,input().split( )))
z = x[1]-x[0]
t = 0
for s in range(z+2):
    t += s
    
print(t-x[1])

Fixed submission:
x = int(input())

if x > 999:
    print('ABD')
    
else:
    print('ABC')
Buggy python submission (verdict: Runtime Error):
x,y = map(int,input( ))
z = y-x
t = 0
for s in range(z+1):
    t += s
    
print(t-y)

Fixed submission:
x = list(map(int,input().split( )))
z = x[1]-x[0]
t = 0
for s in range(z+1):
    t += s
    
print(t-x[1])
Buggy python submission (verdict: Runtime Error):
s = list(map(int,input().split( ))
karians = []
karians.append(karians[0]-karians[1])
karians.append(karians[0]+karians[1])
karians.append(karians[0]*karians[1])
ans = max(karians)
print(ans)

Fixed submission:
s = list(map(int,input().split( )))
x = []
x.append(s[0]+s[1])
x.append(s[0]-s[1])
x.append(s[0]*s[1])
ans = max(x)
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = list(map(int,input.split( )))

if abs(c-a) <= d or (abs(b-a) <= d and abs(c-b) <= d):
    print('Yes')
else:
    print('No')

Fixed submission:
a,b,c,d = list(map(int,input().split( )))

if abs(c-a) <= d or (abs(b-a) <= d and abs(c-b) <= d):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

a = input().split("")
sum = 700
for i in a:
    if i == 'o':
        sum += 100

print(sum)


Fixed submission:
# -*- coding: utf-8 -*-

a = list(input())
sum = 700
for i in a:
    if i == 'o':
        sum += 100

print(sum)
Buggy python submission (verdict: Runtime Error):
N, i = list(map(int, input().split()))
print(n + 1 - i)


Fixed submission:
n, i = list(map(int, input().split()))
print(n - i + 1 )

Buggy python submission (verdict: Runtime Error):
N , i = list(map(int, input().split()))
print(n + 1 - i)


Fixed submission:
n, i = list(map(int, input().split()))
print(n - i + 1 )

Buggy python submission (verdict: Runtime Error):
N , i = list(map(int, input().split()))
print(n + 1 -i)

Fixed submission:
n, i = list(map(int, input().split()))
print(n - i + 1 )

Buggy python submission (verdict: Runtime Error):
N = int(input())
i = int(input())
print(N - i + 1)

Fixed submission:
n, i = list(map(int, input().split()))
print(n - i + 1 )
Buggy python submission (verdict: Runtime Error):
r = int(input())
if r < 1200:
    print(ABC)
    if 1200 <= r <2800:
        print(ARC)
    else:
        print(AGC)

Fixed submission:
r = int(input())
if r < 1200:
    print("ABC")
else:
    if r < 2800:
        print("ARC")
    else:
        print("AGC")
Buggy python submission (verdict: Runtime Error):
import numpy as np

dataNum, timeMax = input().strip().split(' ')
dataNum, timeMax = [int(dataNum), int(timeMax)]

cost = []
time = []

"""
for i in range(dataNum):
    A, B = list(map(int, input().strip().split(' ')))   
    cost.append(A)
    time.append(B)

if min(time) > timeMax:
    print('TLE')
else :
    print(min(cost))
"""
for i in range(dataNum):
    A, B = list(map(int, input().strip().split(' ')))   
    if B <= timeMax:
        cost.append(A)
        time.append(B)
    
if min(time) > timeMax:
    print('TLE')
else :
    print(min(cost))


Fixed submission:
import numpy as np

dataNum, timeMax = input().strip().split(' ')
dataNum, timeMax = [int(dataNum), int(timeMax)]

cost = [10000]
time = [10000]

"""
for i in range(dataNum):
    A, B = list(map(int, input().strip().split(' ')))   
    cost.append(A)
    time.append(B)

if min(time) > timeMax:
    print('TLE')
else :
    print(min(cost))
"""
for i in range(dataNum):
    A, B = list(map(int, input().strip().split(' ')))   
    if B <= timeMax:
        cost.append(A)
        time.append(B)
    
if min(time) > timeMax:
    print('TLE')
else :
    print(min(cost))
Buggy python submission (verdict: Runtime Error):

array = list(map(int, input().strip().split()))
#array.sort(reverse = True)
N = array[0]
M = array[1]
X = array[2]
Y = array[3]

xarray = list(map(int, input().strip().split()))
xarray.sort(reverse = True)
##print(xarray)
xmax = xarray[0]

yarray = list(map(int, input().strip().split()))
yarray.sort()
##print(yarray)
ymin = yarray[0]
if (ymin > xmax):
    if((abs(ymin) - abs(xmax)) >= 1):
        print("No War")
    else:
        print("War")
else:
    print("War")

##print(array)


Fixed submission:
array = list(map(int, input().strip().split()))
array.sort(reverse = True)
A = 10 * array[0] + array[1] + array[2]
print(A)
Buggy python submission (verdict: Runtime Error):
res = [0,0]
for i in range(n[0]):
    get = input().split(" ")
    get = list(map(int,get))
    

    if get[1] < n[1]:
        res[0] = get[0]
        res[1] = get[1]
    
if res[0]==0 and res[1]==0:
    print('TLE')
else:print(res[0])

Fixed submission:
n = input().split(" ")
n = list(map(int,n))


cost = 10000
res = [0,0]

for i in range(n[0]):
    get = input().split(" ")
    get = list(map(int,get))
    
    if get[1] <= n[1]:
        res[1] = get[1]
        if get[0] < cost:
            cost = get[0]


if res[1]==0:
    print('TLE')
else:print(cost)

Buggy python submission (verdict: Runtime Error):
res = [0,0]
for i in range(n[0]):
    get = input().split(" ")
    get = list(map(int,get))
    

    if get[1] < n[1]:
        res[0] = get[0]
        res[1] = get[1]
    
if res[0]==0 and res[1]==0:
    print('TLE')
else:print(res[0])

Fixed submission:
n = input().split(" ")
n = list(map(int,n))


cost = 10000
res = [0,0]

for i in range(n[0]):
    get = input().split(" ")
    get = list(map(int,get))
    
    if get[1] <= n[1]:
        res[1] = get[1]
        if get[0] < cost:
            cost = get[0]


if res[1]==0:
    print('TLE')
else:print(cost)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = int(input())
B = int(input())
C = A + B
if N == 1:
    print("Hello World")
else:
    print(C)

Fixed submission:
N = int(input())
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A+B)
Buggy python submission (verdict: Runtime Error):
A=[]
while True:
    try:
        A.append(list(map(int,input().split())))
              

    except:
        break;
#2列めがT以下で且つ、コストが最小なものを抽出
min = A[1][1] #最小を7とす

for i in range(1, len(A)):
  j = int(i)
  if A[j][1] =< A[0][1]:
    if A[j][0] < min:
      min = A[j][0]

if min < A[0][1]:
  print(min)
else:
  print("TLE")
    

Fixed submission:
A=[]
while True:
    try:
        A.append(list(map(int,input().split())))
              
 
    except:
        break;
#2列めがT以下で且つ、コストが最小なものを抽出
T = A[0][1]
Tc = 0
min = A[1][0] #最小を7とす
 
for i in range(1, len(A)):
  j = int(i)
  if A[j][1] <= T:
    Tc = Tc+1
    if A[j][0] <= min:
      min = A[j][0]
     
      
if Tc == 0:
  print("TLE")
else:
  print(min)
Buggy python submission (verdict: Runtime Error):
N=int(input())
dSum=0
tmpN=N
while tmpN>=10:
    dSum+=tmpN%10
    tmpN/=10
if N%dSum==0:
    print("Yes")
else:
    print("No")

Fixed submission:
N=int(input())
dSum=0
tmpN=N
while tmpN>=1:
    dSum += tmpN % 10
    tmpN = int(tmpN/10)
#print(dSum)
if N % dSum == 0:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
N=int(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,input().split())
for i in range(N-1): #一周につき一つの駅([0]..[N-2])から[N-1]までの計算
    arrivalTime=S[i]+C[i]#最初発車駅の次の駅に着く時間
    for j in range(i+1,N-1):
        leaveTime=S[j]#現在考慮中の駅から初めて発車する時間
        if arrivalTime <leaveTime:
            pass
        elif arrivalTime % F[j]==0:
            leaveTime=arrivalTime
        else:
            leaveTime=arrivalTime+F[j]- arrivalTime % F[j]-
        '''
        while arrivalTime > leaveTime:
            leaveTime+=F[j]
        '''
        arrivalTime=leaveTime+C[j]
    print(arrivalTime)
print(0)#[N-1]駅

Fixed submission:
N=int(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,input().split())
for i in range(N-1): #一周につき一つの駅([0]..[N-2])から[N-1]までの計算
    arrivalTime=S[i]+C[i]#最初発車駅の次の駅に着く時間
    for j in range(i+1,N-1):
        leaveTime=S[j]#現在考慮中の駅から初めて発車する時間
        if arrivalTime <leaveTime:
            pass
        elif arrivalTime % F[j]==0:
            leaveTime=arrivalTime
        else:
            leaveTime=arrivalTime+F[j]- arrivalTime % F[j]
        '''
        while arrivalTime > leaveTime:
            leaveTime+=F[j]
        '''
        arrivalTime=leaveTime+C[j]
    print(arrivalTime)
print(0)#[N-1]駅

Buggy python submission (verdict: Time Limit Exceeded):
N=int(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,input().split())
for i in range(N-1): #一周につき一つの駅([0]..[N-3])から[N-1]までの計算
    arrivalTime=S[i]+C[i]#最初発車駅の次の駅に着く時間
    for j in range(i+1,N-1):
        leaveTime=S[j]#現在考慮中の駅から初めて発車する時間
        while arrivalTime > leaveTime:
            leaveTime+=F[j]
        arrivalTime=leaveTime+C[j]
    print(arrivalTime)
print(0)#[N-1]駅

Fixed submission:
N=int(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,input().split())
for i in range(N-1): #一周につき一つの駅([0]..[N-2])から[N-1]までの計算
    arrivalTime=S[i]+C[i]#最初発車駅の次の駅に着く時間
    for j in range(i+1,N-1):
        leaveTime=S[j]#現在考慮中の駅から初めて発車する時間
        if arrivalTime <leaveTime:
            pass
        elif arrivalTime % F[j]==0:
            leaveTime=arrivalTime
        else:
            leaveTime=arrivalTime+F[j]- arrivalTime % F[j]
        '''
        while arrivalTime > leaveTime:
            leaveTime+=F[j]
        '''
        arrivalTime=leaveTime+C[j]
    print(arrivalTime)
print(0)#[N-1]駅