Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03160 (python)

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
dp = [0 for i in range(N)]
if N >= 3 :
    
    for i in range(1,3) :
        dp[i] = abs(L[i]-L[0])
    for i in range(3,len(dp)) :
        a = dp[i-1] + abs(L[i]-L[i-1])
        b = dp[i-2] + abs(L[i]-L[i-2])
        dp[i] = min(a,b)
    print(dp[N-1])
    #print(dp)

else :
    print(abs(L[-1]-L[0]))

Buggy submission (verdict: Runtime Error):
def flog(l) :
    if len(l) <= 1 :
        res = 0
    elif len(l) == 2 :
        res = abs(l[1]-l[0])
    else :
        a = abs(l[2]-l[0])
        b = abs(l[1]-l[0])
        if a <= b :
            res = a + flog(l[2:])
        else :
            res = b + flog(l[1:])
    return res

N = int(input())
H = list(map(int,input().split()))
H = list(reversed(H))

print(flog(H))
Problem p03161 (python)

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

L = list(map(int,input().split()))

dp = [0 for i in range(N)]
if N >= K :    
    for i in range(1,K+1) :
        dp[i] = abs(L[i]-L[0])
    for i in range(K+1,len(dp)) :
        state = float("inf")
        for j in range(i-K,i) :
            calc = abs(L[i]-L[j]) + dp[j]
            if state > calc :
                state = calc
        dp[i] = state
    print(dp[N-1])
else :
    print(abs(min(L[1:])-L[0]))

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
H = list(map(int,input().split()))

dp = [0 for i in range(N)]

for i in range(1,K+1) :
    dp[i] = abs(H[0] - H[i])

for i in range(K+1,N) :
    cost = float("inf")
    for j in range(1,K+1) :
        cost = min(cost, dp[i-j] + abs(H[i-j] - H[i]))
    
    dp[i] = cost

ans = dp[N-1]

print(ans)
Problem p03162 (python)

Fixed submission:
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]

dp = [[0,0,0] for i in range(N+1)]
for i in range(N) :
    for j in range(3) :
        for k in range(3) :
            if j == k :
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + L[i][k])
print(max(dp[-1]))

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [list(map(int,input().split())) for i in range(N)]
NOW = [0]*3
NEXT = [None]*3
for i in range(N) :
    NEXT[0] = max(NOW[1],NOW[2]) + L[0]
    NEXT[1] = max(NOW[2],NOW[0]) + L[1]
    NEXT[2] = max(NOW[0],NOW[1]) + L[2]    
    NOW = NEXT.copy()
print(max(NOW))

Buggy submission (verdict: Runtime Error):
N = int(input())
L = [[map(int,input().split())] for i in range(N)]

dp = [[0,0,0] for i in range(N+1)]
for i in range(N) :
    for j in range(3) :
        for k in range(3) :
            if j == k :
                continue
            dp[i+1][k] = max(dp[i+1][k], dp[i][j] + L[i][k])
print(ax(dp[-1]))
Problem p03166 (python)

Fixed submission:
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.pop()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy submission (verdict: Runtime Error):
import collections

N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.collections.popleft()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]

L_minus = [[] for i in range(N)]
L_plus = [0 for i in range(N)]

dp = [0 for i in range(N)]

for i in range(M) :
    x,y = L[i]
    x -= 1
    y -= 1
    L_plus[y] += 1
    L_minus[x].append(y)

A = []

for i in range(N) :
    if L_plus[i] == 0 :
        A.append(i)

while A :
    x = A.popleft()
    
    for y in L_minus[x] :
        L_plus[y] -= 1
        if L_plus[y] == 0 :
            A.append(y)
        dp[y] = max(dp[y], dp[x]+1)

ans = max(dp)

print(ans)
Problem p03193 (python)

Fixed submission:
N,H,W = map(int,input().split())
L = []
ans = 0
for i in range(N) :
    a,b = map(int,input().split())
    if (a >= H) and (b >= W) :
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N,H,W = map(int,input().split())
L = []
for i in range(N) :
    a,b = map(int,input().split())
    if (a >= H) and (b >= W) :
        ans += 1
print(ans)
Problem p03196 (python)

Fixed submission:
N,P = map(int,input().split())
from collections import Counter
def factorize(n) :
    d = Counter()
    m = 2
    while m*m <= n :
        while n%m == 0 :
            n //= m
            d[m] += 1
        m += 1
    if n > 1 :
        d[n] += 1
    return d

factors = factorize(P)
ans = 1
for k,v in factors.items() :
    a = v//N
    ans *= k**a
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
odd = 0
for i in range(len(A)) :
    a = A[i]
    if a % 2 != 0 :
        odd += 1
        break
if odd == 1 :
    print("first")
else :
    print("second")
Problem p03231 (python)

Fixed submission:
def gcd(m,n) :
    x = max(m,n)
    y = min(m,n)
    if x%y == 0 :
        return y
    else :
        while x%y != 0 :
            z = x%y
            x = y
            y = z
        else :
            return z

def lcm(m,n) :
    return int(m*n/gcd(m,n))

N,M = map(int,input().split())
S = list(input())
T = list(input())
L = lcm(N,M)
A = []
B = []
flag = 0
counter = 0
if N >= M :
    for i in range(N) :
        A.append(i*L//N+1)
    for j in range(M) :
        b = j*L//M+1
        if j*N % M == 0 :
            index = N*j//M
            if S[index] == T[j] :
                counter += 1
            else :
                flag = 1
                break
        else :
            counter += 1
    if flag == 1 :
        print(-1)
    else :
        if counter == M :
            print(L)
else :
    for i in range(M) :
        A.append(i*L//M+1)
    for j in range(N) :
        b = j*L//N+1
        if j*M % N == 0 :
            index = M*j//N
            if T[index] == S[j] :
                counter += 1
            else :
                flag = 1
                break
        else :
            counter += 1
    if flag == 1 :
        print(-1)
    else :
        if counter == N :
            print(L)

Buggy submission (verdict: Runtime Error):
def gcd(m,n) :
    x = max(m,n)
    y = min(m,n)
    if x%y == 0 :
        return y
    else :
        while x%y != 0 :
            z = x%y
            x = y
            y = z
        else :
            return z

def lcm(m,n) :
    return int(m*n/gcd(m,n))

N,M = map(int,input().split())
S = list(input())
T = list(input())
L = lcm(N,M)
A = []
B = []
flag = 0
counter = 0
for i in range(N) :
    A.append(i*L//N+1)
for j in range(M) :
    b = j*L//M+1
    if j % (N//M) == 0 :
        index = N*j//M
        if S[index] == T[j] :
            counter += 1
        else :
            flag = 1
            break
    else :
        counter += 1
if flag == 1 :
    print(-1)
else :
    if counter == M :
        print(L)
#print(A)
#print(counter)
#print(flag)
Problem p03241 (python)

Fixed submission:
import numpy as np
from math import sqrt
ANS = []
N,M = map(int,input().split())
L = np.arange(1,int(sqrt(M))+1,dtype=int)
#L = sorted(L,reverse = True)
for i in L :
    if M % i == 0 :
        ANS.append(i)
        ANS.append(M//i)
ANS = sorted(ANS,reverse = True)
for j in ANS :
    if j * N <= M :
        print(j)
        break

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M = map(int,input().split())
R = M//N+1
R = sorted(np.arange(R),reverse=True)
for i in R :
    if M % i == 0 :
        if (M-i*(N-1))%i == 0 :
            print(i)
            break

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M = map(int,input().split())
R = M//N+1
R = sorted(np.arange(R),reverse=True)
for i in R :
    if (M-i*(N-1))%i == 0 :
        print(i)
        break
Problem p03244 (python)

Fixed submission:
#input phase
N = int(input())
V = list(map(int,input().split()))
#make dictionary
D1 = {}
D2 = {}
#append element to dictionary
for i in range(N):
    if i % 2 == 0 :
        if V[i] in D1 :
            D1[V[i]] += 1
        else:
            D1[V[i]] = 1
    else:
        if V[i] in D2 :
            D2[V[i]] += 1
        else:
            D2[V[i]] = 1
#define max-value of each dictionary
maxD1 = max(D1.values())
maxD2 = max(D2.values())
# I haven't appreciated dictionary method well...
if max(D1, key=D1.get) != max(D2, key=D2.get):
    print(N-maxD1-maxD2)
else:
    D1[max(D1, key=D1.get)] = 0
    D2[max(D2, key=D2.get)] = 0
    maxD12 = max(D1.values())
    maxD22 = max(D2.values())
    if maxD12 >= maxD22 :
        if len(D1) > 1 :
            print(N-maxD12-maxD2)
        else :
            print(N-maxD2)
    else :
        if len(D2) > 1 :
            print(N-maxD1-maxD22)
        else :
            print(N-maxD2)

Buggy submission (verdict: Runtime Error):
N = int(input())
V = list(map(int,input().split()))
D1 = {}
D2 = {}
for i in range(N) :
    if i % 2 == 0:
        if V[i] in D1 :
            D1[V[i]] += 1
        else :
            D1[V[i]] = 1
    else :
        if V[i] in D2 :
            D2[V[i]] += 1
        else :
            D2[V[i]] = 1
m1 = max(D1.values())
m2 = max(D2.values())
if max(D1,key = D1.get) != max(D2,key = D2.get) :
    print(N-m1-m2)
else :
    D1[max(D1,key=D1.get)] = 0
    D2[max(D2,key=D1.get)] = 0
    mm1 = max(D1.values())
    mm2 = max(D2.values())
    if mm1 >= mm2 :
        print(N-m2-mm1)
    else :
        print(N-m1-mm2)
Problem p03262 (python)

Fixed submission:
N, X = map(int, input().split())
A = list(map(int, input().split()))
diff = [abs(a - X) for a in A]

# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


while len(diff) > 1:
    a, b = diff.pop(), diff.pop()
    diff.append(gcd(a, b))

print(diff[0])

Buggy submission (verdict: Runtime Error):
import math
L = []
N,X = map(int,input().split())
L = list(map(int,input().split()))
L.append(X)
L = sorted(L)
D = []
for i in range(len(L)) :
    d = abs(L[i-1] - L[i])
    if i != 0 :
        D.append(d)

D = sorted(D)
if N != 1 :
    answer = math.gcd(D[0],D[1])
    for j in range(len(D)-1) :
        gcd = math.gcd(D[j],D[j+1])
        if answer > gcd :
            answer = gcd
else :
    answer = D[0]
print(answer)

Buggy submission (verdict: Runtime Error):
import math
L = []
N,X = map(int,input().split())
L = list(map(int,input().split()))
L.append(X)
L = sorted(L)
D = []
for i in range(len(L)) :
    d = abs(L[i-1] - L[i])
    D.append(d)

D = sorted(D)
if N != 1 :
    answer = math.gcd(D[0],D[1])
    for j in range(len(D)-1) :
        gcd = math.gcd(D[j],D[j+1])
        if answer > gcd :
            answer = gcd
else :
    answer = D[0]
print(answer)

Buggy submission (verdict: Runtime Error):
import math

N,X = map(int,input().split())
L = list(map(int,input().split()))
L.append(X)
L = sorted(L)
D = []
for i in range(len(L)) :
    d = abs(L[i+1] - L[i])
    D.append(d)

D = sorted(D)
if N != 1 :
    answer = math.gcd(D[0],D[1])
    for j in range(len(D)) :
        gcd = math.gcd(D[i-1],D[i])
        if answer > gcd :
            answer = gcd
else :
    answer = D[0]
print(answer)

Buggy submission (verdict: Runtime Error):
#import functools
import math
N,X = map(int,input().split())
L = list(map(int,input().split()))
L.append(X)
L = sorted(L)
D = []
for i in range(N) :
    d = L[i+1] - L[i]
    D.append(d)

D = sorted(D)
if N != 1 :
    for j in range(N-1) :
        answer = math.gcd(D[0],D[1])
        gcd = math.gcd(D[i-1],D[i])
        if answer > gcd :
            answer = gcd
else :
    answer = D[0]
print(answer)

Buggy submission (verdict: Runtime Error):
import functools
import math
N,X = map(int,input().split())
L = list(map(int,input().split()))
L.append(X)
L = sorted(L)
D = []
for i in range(N) :
    d = L[i+1] - L[i]
    D.append(d)
answer = functools.reduce(math.gcd,D)
print(answer)
Problem p03284 (python)

Fixed submission:
n,k = map(int,input().split())
if n < k :
    print(1)
elif n == k :
    print(0)
elif n % k == 0:
    print(0)
else :
    print(1)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = ""
while N != 0 :
    if N % (-2) == 0 :
        S = "0" + S
    else :
        S = "1" + S
        N -= 1
    N = N / (-2)
if len(S) == 0 :
    print(0)
else :
    print(S)
Problem p03330 (python)

Fixed submission:
N,C = map(int,input().split())
D = [list(map(int,input().split())) for i in range(C)]
L = [list(map(int,input().split())) for i in range(N)]

d0 = {}
d1 = {}
d2 = {}

for i in range(N) :
    for j in range(N) :
        before = L[i][j] - 1
        
        if (i+j) % 3 == 0 :
            if before not in d0 :
                d0[before] = 1
            else :
                d0[before] += 1

        elif (i+j) % 3 == 1 :
            if before not in d1 :
                d1[before] = 1
            else :
                d1[before] += 1

        else :
            if before not in d2 :
                d2[before] = 1
            else :
                d2[before] += 1



A0 = []
A1 = []
A2 = []

for after in range(C) :
    calc = 0
    for before in d0 :
        calc += D[before][after] * d0[before]
    A0.append([calc,after])

for after in range(C) :
    calc = 0
    for before in d1 :
        calc += D[before][after] * d1[before]
    A1.append([calc,after])

for after in range(C) :
    calc = 0
    for before in d2 :
        calc += D[before][after] * d2[before]
    A2.append([calc,after])
    
A0 = sorted(A0,key=lambda x:x[0],reverse=False)[:3]
A1 = sorted(A1,key=lambda x:x[0],reverse=False)[:3]
A2 = sorted(A2,key=lambda x:x[0],reverse=False)[:3]
B = [A0,A1,A2]

ans = float("inf")

for i in range(3) :
    for j in range(3) :
        for k in range(3) :
            if (B[0][i][1] - B[1][j][1]) * (B[1][j][1] - B[2][k][1]) * (B[2][k][1] - B[0][i][1]) == 0 :
                continue
            
            ans = min(ans, B[0][i][0] + B[1][j][0] + B[2][k][0])

print(ans)

Buggy submission (verdict: Runtime Error):
N,C = map(int,input().split())
D = [list(map(int,input().split())) for i in range(C)]
A = [list(map(int,input().split())) for i in range(N)]

ans = float("inf")

L = []
for i in range(1,C+1,3) :
    L.append([i,i+1,i+2])
    L.append([i,i+2,i+1])
    L.append([i+1,i,i+2])
    L.append([i+1,i+2,i])
    L.append([i+2,i,i+1])
    L.append([i+2,i+1,i])


for i in range(len(L)) :
    p,q,r = L[i]
    
    calc = 0
    
    for j in range(N) :
        for k in range(N) :
            if (j+k) % 3 == 0 :
                calc += D[A[j][k]-1][p-1]
            elif (j+k) % 3 == 1 :
                calc += D[A[j][k]-1][q-1]
            else :
                calc += D[A[j][k]-1][r-1]
    ans = min(ans,calc)
print(ans)
Problem p03352 (python)

Fixed submission:
X = int(input())
L = []
ANS = []
for i in range(1,33) :
    for j in range(2,11) :
        if i**j <= 1192 :
            l = i**j
            L.append(l)
L = list(set(L))
L = sorted(L)
for j in range(len(L)) :
    if L[j] <= X < L[j+1] :
        ans = L[j]
        ANS.append(ans)
print(max(ANS))

Buggy submission (verdict: Runtime Error):
X = int(input())
L = []
ANS = []
for i in range(1,33) :
    for j in range(2,11) :
        if i**j <= 1000 :
            l = i**j
            L.append(l)
L = list(set(L))
L = sorted(L)
for j in range(len(L)) :
    if L[j] <= X < L[j+1] :
        ans = L[j]
        ANS.append(ans)
print(max(ANS))
Problem p03382 (python)

Fixed submission:
import bisect

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

A = sorted(A)

ans1 = A[-1]

ind = bisect.bisect_left(A, ans1/2)


c = float("inf")
for i in range(max(0,ind-1), min(N-1,ind+2)) :
    calc = abs(ans1/2 - A[i])
    if calc < c :
        ans2 = A[i]
        c = calc
print(ans1,ans2)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

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

A = sorted(A)

fac = [1]*(A[-1]+1)

for i in range(2,len(fac)) :
    fac[i] = i * fac[i-1]

ans1 = A[-1]
ans2 = 0

c = 0

for i in range(N) :
    a = A[i]
    calc = fac[ans1]//(fac[a] * fac[ans1-a])

    if c < calc :
        ans2 = a
        c = calc

print(ans1,ans2)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))

A = sorted(A)

fac = [1]*(A[-1]+1)

for i in range(2,len(fac)) :
    fac[i] = i * fac[i-1]

ans1 = A[-1]
ans2 = 0

c = 0

for i in range(N) :
    a = A[i]
    calc = fac[ans1]//(fac[a] * fac[ans1-a])

    if c < calc :
        ans2 = a
        c = calc

print(ans1,ans2)
Problem p03409 (python)

Fixed submission:
N = int(input())
Blue = []
Red = []
for i in range(N) :
    a,b = map(int,input().split())
    Red.append([a,b])
for i in range(N) :
    c,d = map(int,input().split())
    Blue.append([c,d])

Blue = sorted(Blue)
Red = list(reversed(sorted(Red,key=lambda x: x[1])))

ans = 0
for i in range(N) :
    for j in range(N) :
        if j >= len(Red) :
            break
        if (Blue[i][0] > Red[j][0]) and (Blue[i][1] > Red[j][1]) :
            ans += 1
            Red.pop(j)
            break
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
R = sorted([list(map(int,input()split())) for i in range(N)], key=lambda x: x[0],reverse=False)
B = sorted([list(map(int,input()split())) for i in range(N)], key=lambda x: x[1],reverse=True)

ans = 0

start = 0

for a,b in R :
    for i in range(start,N) :
        c,d = B[i]
        if (c-a > 0) and (d-b > 0) :
            start = i+1
            ans += 1
print(ans)
Problem p03424 (python)

Fixed submission:
N = int(input())
L = list(map(str,input().split()))
flag = 4
if "P" in L :
    flag -= 1
if "W" in L :
    flag -= 1
if "G" in L :
    flag -= 1
if "Y" in L :
    flag -= 1
if flag == 0 :
    print("Four")
else :
    print("Three")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(str,input().split()))
p = S.count("P")
w = S.count("W")
g = S.count("G")
y = S>count("Y")
ans = p+w+g+y
if ans == 3 :
    print("Three")
else :
    print("Four")

Buggy submission (verdict: Runtime Error):
N = int(input())
S = list(map(int,input().split()))
p = S.count("P")
w = S.count("W")
g = S.count("G")
y = S>count("Y")
ans = p+w+g+y
if ans == 3 :
    print("Three")
else :
    print("Four")
Problem p03452 (python)

Fixed submission:
N,M = map(int,input().split())
A = [[] for i in range(N+1)]

for i in range(M) :
    l,r,d = map(int,input().split())
    
    l -= 1
    r -= 1
    
    A[l].append([r,d])
    A[r].append([l,-d])

distance = ["#" for i in range(N)]

ans = "Yes"

flg = 0

for i in range(N) :
    if flg == 1 :
        break
    
    if distance[i] != "#" :
        continue
    
    distance[i] = 0
    stack = [i]
    
    while stack :
        v = stack.pop()
        
        for to,d in A[v] :
            if distance[to] == "#" :
                distance[to] = distance[v] + d
                stack.append(to)
            
            elif distance[to] != distance[v] + d :
                ans = "No"
                stack = []
                flg = 1
                break
                

print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = [[] for i in range(N+1)]

for i in range(M) :
    l,r,d = map(int,input().split())
    
    l -= 1
    r -= 1
    
    A[l].append([r,d])
    A[r].append([l,d])

distance = ["#" for i in range(N)]

ans = "Yes"

flg = 0

for i in range(N) :
    if flg == 1 :
        break
    
    if distance[i] != "#" :
        continue
    
    distance[i] = 0
    stack = [i]
    
    while stack :
        v = stack.pop()
        
        for to,d in L[v] :
            if distance[to] == "#" :
                distance[to] = distance[v] + d :
                stack.append(to)
            
            elif distance[to] != distance[v] + d :
                ans = "No"
                stack = []
                flg = 1
                break
                

print(ans)
Problem p03456 (python)

Fixed submission:
a,b = map(str,input().split())
ab = int(a+b)
L = []
for i in range(1,318) :
    l = i**2
    L.append(l)
if ab in L :
    print("Yes")
else :
    print("No")

Buggy submission (verdict: Runtime Error):
a,b = map(str,input().split())
ab = int(a+b)
for i in range(1,318) :
    l = i**2
    L.append(l)
if ab in L :
    print("Yes")
else :
    print("No")
Problem p03471 (python)

Fixed submission:
N,Y = map(int,input().split())
flag = 0
for i in range(N+1) :
    a = 10000*i
    for j in range(N+1) :
        b = 5000*j
        if (a+b) <= Y :
            c = Y-(a+b)
            k = c//1000
            if flag == 1 :
                break
            elif (i+j+k) == N :
                print(i,j,k)
                flag += 1
if flag == 0 :
    print(-1,-1,-1)

Buggy submission (verdict: Runtime Error):
N,Y = map(int,input().split())
ans = [-1,-1,-1]
for x in range(N+1) :
    man = x * 10000
    for y in range(N+1-x) :
        gosen = y * 5000
        sen = (N-x-y) * 1000
        if (man+gosen+sen) == Y :
            ans = [x,y,z]
print(*ans)
Problem p03475 (python)

Fixed submission:
N = int(input())
C = []
S = []
F = []
for i in range(N-1) :
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for j in range(N) :
    if j != N-1 :
        answer = 0
        for k in range(j,N-1) :
            if answer < S[k] :
                answer = S[k]
            if answer % F[k] != 0 :
                answer = (answer // F[k] + 1) * F[k]
            answer += C[k]
        print(answer)
    else :
        print(0)

Buggy submission (verdict: Runtime Error):
N = int(input())
C = []
S = []
F = []
for i in range(N-1) :
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N) :
    if j == N-1 :
        print(0)
    else :
        ans = 0
        for j in range(i,N-1) :
            if ans < S[j] :
                ans = S[j]
            if ans % F[j] != 0 :
                ans = (ans//F[j]-1)*F[j]
            ans += C[j]
        print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
C = []
S = []
F = []
for i in range(N-1) :
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N) :
    if j == N-1 :
        print(0)
    else :
        ans = 0
        for j in range(i,N-1) :
            if ans < S[j] :
                ans = S[j]
            if ans % F[j] != 0 :
                ans = (ans//F[k]-1)*F[k]
            ans += C[k]
        print(ans)