qyliang/CodeNanoFix huggingface dataset:
Buggy code:
n = int(input())
csf = []
for i in range(n - 1):
    csf.append(list(map(int, input().split())))

for i in range(n):
    AnsSec = 0
    Now_Station = i
    while Now_Station < n - 1:
        if AnsSec > csf[Now_Station][1]:
            if csf[Now_Station][2] % AnsSec != 0:
                AnsSec += csf[Now_Station][2] - (AnsSec % csf[Now_Station][2] )
        else:
            AnsSec += csf[Now_Station][1] - AnsSec
        AnsSec += csf[Now_Station][0]
        Now_Station += 1
    print(AnsSec)


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

for i in range(n):
    AnsSec = 0
    Now_Station = i
    while Now_Station < n - 1:
        if AnsSec > csf[Now_Station][1]:
            if AnsSec % csf[Now_Station][2] != 0:
                AnsSec += csf[Now_Station][2] - (AnsSec % csf[Now_Station][2])
        else:
            AnsSec += csf[Now_Station][1] - AnsSec
        AnsSec += csf[Now_Station][0]
        Now_Station += 1
    print(AnsSec)
Buggy code:
n = int(input())

csf = []

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

ans = []
for i in range(n - 1):
    tmp = csf[i][0] + csf[i][1]
    for j in range(i + 1, n - 1):
        if tmp < csf[j][1]:
            tmp = csf[j][0] + csf[j][1]
        elif (tmp - csf[j][1]) % csf[j][2] == 0:
            tmp += csf[j][0]
        else:
            tmp += ((tmp // csf[j][2] + 1) * csf[j][2] + csf[j][0]
    ans.append(tmp)
ans.append(0)

print(*ans, sep="\n")

Fixed code:
n = int(input())

csf = []

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

ans = []
for i in range(n - 1):
    tmp = csf[i][0] + csf[i][1]
    for j in range(i + 1, n - 1):
        if tmp < csf[j][1]:
            tmp = csf[j][0] + csf[j][1]
        elif (tmp - csf[j][1]) % csf[j][2] == 0:
            tmp += csf[j][0]
        else:
            tmp = (tmp // csf[j][2] + 1) * csf[j][2] + csf[j][0]
    ans.append(tmp)
ans.append(0)

print(*ans, sep="\n")
Buggy code:
N = int(input())
lines = []

for i in range(N-1):
    lines.append(input())

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

for line in lines:
	c, s, f = line.split()
	C.append(int(c))
	S.append(int(s))
	F.append(int(f))

A = []

for i in range(N-1):
	a = C[i] + S[i]
	for j in range(i + 1, N - 1):
		n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
		n = F[j] - n if n != 0 else n
		# n = S[j] - a if a <= S[j] else a % F[j]
		a = a + C[j] + n
	A.append(a)

for a in A:
	print(a)
print(0)



Fixed code:
N = int(input())
Nminus1 = N - 1
# lines = []

C = [0 for _ in range(Nminus1)]
S = [0 for _ in range(Nminus1)]
F = [0 for _ in range(Nminus1)]

for i in range(Nminus1):
    c, s, f = input().split()

    C[i] = int(c)
    S[i] = int(s)
    F[i] = int(f)

# for line in lines:
#     c, s, f = line.split()
#     C.append(int(c))
#     S.append(int(s))
#     F.append(int(f))

for i in range(Nminus1):
    a = C[i] + S[i]
    for j in range(i + 1, Nminus1):
        if a <= S[j]:
            n = S[j] - a
        else:
            mod = a % F[j] 
            n = F[j] - mod if mod != 0 else 0
        a = a + C[j] + n
    print(a)

print(0)
Buggy code:
N = int(input())
lines = []

for i in range(N-1):
    lines.append(input())

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

for line in lines:
	c, s, f = line.split()
	C.append(int(c))
	S.append(int(s))
	F.append(int(f))

A = []

for i in range(N-1):
	a = C[i] + S[i]
	for j in range(i + 1, N - 1):
		# n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
		n = S[j] - a if a <= S[j] else F[j] - (a % F[j])
		a = a + C[j] + n
	A.append(a)

for a in A:
	print(a)
print(0)


Fixed code:
N = int(input())
lines = []

for i in range(N-1):
    lines.append(input())

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

for line in lines:
	c, s, f = line.split()
	C.append(int(c))
	S.append(int(s))
	F.append(int(f))

A = []

for i in range(N-1):
	a = C[i] + S[i]
	for j in range(i + 1, N - 1):
		n = S[j] - a if a <= S[j] else (a - S[j]) % F[j]
		n = F[j] - n if a > S[j] and n != 0 else n
		# n = S[j] - a if a <= S[j] else a % F[j]
		a = a + C[j] + n
	A.append(a)

for a in A:
	print(a)
print(0)
Buggy code:
if __name__ == "__main__":
    n = int(input())
    csf = list()
    for i in range(n-1):
        csf.append(list(map(int, input().split())))

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


Fixed code:
if __name__ == "__main__":
    n = int(input())
    csf = list()
    for i in range(n-1):
        csf.append(list(map(int, input().split())))

    for i in range(n):
        ans = 0
        for j in range(i, n-1):
            if ans <= csf[j][1]:
                ans = csf[j][1]
                ans += csf[j][0]
            else:
                tmp = (csf[j][2] - ans % csf[j][2]) % csf[j][2]
                ans += tmp
                ans += csf[j][0]
        print(ans)
Buggy code:
n = int(input())
t = 0
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, input().split())

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

Fixed code:
n = int(input())
t = 0
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, 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:
            t = t + f[j] - (t % f[j])
        t += c[j]
            
    print(t)
print(0)
Buggy code:
N = int(input())
csf = [list(map(int, input().split())) for i in range(N - 1)]

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


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

for i in range(N):
    ans = 0
    for c, s, f in csf[i::]:
        if ans <= s:
            ans = s
        else:
            if ans % f == 0:
                pass
            else:
                ans = (ans // f + 1) * f
        ans += c
    print(ans)
Buggy code:
def main():
    n = int(input())
    C, S, F = [], [], []
    for _ in range(n - 1):
        c, s, f = list(map(int, input().split()))
        C.append(c)
        S.append(s)
        F.append(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:
                t += F[j] - t % F[j]
            t += C[j]
        print(t)



if __name__ == '__main__':
    main()


Fixed code:
def main():
    n = int(input())
    C, S, F = [], [], []
    for _ in range(n - 1):
        c, s, f = list(map(int, input().split()))
        C.append(c)
        S.append(s)
        F.append(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:
                t += F[j] - t % F[j]
            t += C[j]
        print(t)



if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
ans = []
for i in range(len(l)):
    m = l[i][1]
    for j in range(i,len(l)):
        if m<l[j][1]:
            m = l[j][1]+l[j][0]
        elif m==l[j][1] or (m-l[j][1])%l[j][2]==0:
            m += l[j][0]
        else:
            m += (m-l[j][1])%l[j][2]+l[j][0]
    ans.append(m)
ans.append(0)
print(ans)

Fixed code:
n = int(input())
l = [list(map(int,input().split())) for _ in range(n-1)]
ans = []
for i in range(len(l)):
    m = l[i][1]
    for j in range(i,len(l)):
        if m<l[j][1]:
            m = l[j][1]+l[j][0]
        elif m==l[j][1] or (m-l[j][1])%l[j][2]==0:
            m += l[j][0]
        else:
            next = l[j][2]-m%l[j][2]
            m += next+l[j][0]
    ans.append(m)
ans.append(0)
for i in ans:
    print(i)
Buggy code:
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-1):
    tim=0
    for j in range(i,N-1):
        if(tim<=S[j]):
            tim+=S[j]+C[j]
        elif(tim%F[j]==0):
            tim+=C[j]
        elif(tim%F[j]!=0):
            tim+=F[j]-(tim%F[j])
    print(tim)
print(0)

Fixed code:
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-1):
    tim=0
    for j in range(i,N-1):
        if(tim<=S[j]):
            tim=S[j]+C[j]
        elif(tim%F[j]==0):
            tim+=C[j]
        elif(tim%F[j]!=0):
            tim+=C[j]+(F[j]-(tim%F[j]))
    print(tim)
print(0)
Buggy code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=arr[i][0]+arr[i][1]
  for j in range(i+1,n-1):
    if ans<=arr[j][1]:
      ans=arr[j][0]+arr[j][1]
    else:
      if (ans-arr[j][1])%ans[j][2]==0:
        ans+=arr[j][0]
      else:
        ans+=arr[j][0]+arr[j][2]-ans%arr[j][2]
  print(ans)
print(0)

Fixed code:
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=arr[i][0]+arr[i][1]
  for j in range(i+1,n-1):
    if ans<=arr[j][1]:
      ans=arr[j][0]+arr[j][1]
    else:
      if (ans-arr[j][1])%arr[j][2]==0:
        ans+=arr[j][0]
      else:
        ans+=arr[j][0]+arr[j][2]-ans%arr[j][2]
  print(ans)
print(0)
Buggy code:
def main():
    n=int(input())
    csf=[list(map(int,input().split())) for _ in range(n-1)]
    for i in range(n):
        if i == n-1:
            print(0)
        else:
            t=0
            for c,s,f in csf[i:]:
                t = max(s,t)
                t = math.ceil(t/f)*f+c
                #print("start:", i, t)
            print(t)

if __name__ == "__main__":
    main()

Fixed code:
import math
def main():
    n=int(input())
    csf=[list(map(int,input().split())) for _ in range(n-1)]
    for i in range(n):
        if i == n-1:
            print(0)
        else:
            t=0
            for c,s,f in csf[i:]:
                t = max(s,t)
                t = math.ceil(t/f)*f+c
                #print("start:", i, t)
            print(t)

if __name__ == "__main__":
    main()
Buggy code:
def main():
    N = int(input())
    csfs = [[int(i) for i in input().split()] for j in range(N-1)] + [[-1,0,0]]

    for i in range(N):
        state = i
        time = csfs[state][1]
        while state < N-1:
            if time % csfs[state][2] == 0:
                time += csfs[state][0]
                state += 1
            else:
                time += (csfs[state][2] - time%csfs[state][2])
        print(time)
if __name__ == '__main__':
    main()

Fixed code:
def main():
    N = int(input())
    csfs = [[int(i) for i in input().split()] for j in range(N-1)] + [[-1,0,0]]

    for i in range(N):
        state = i
        time = csfs[state][1]
        while state < N-1:
            if time % csfs[state][2] == 0 and csfs[state][1] <= time:
                time += csfs[state][0]
                state += 1
            else:
                time += (csfs[state][2] - time%csfs[state][2])
                if csfs[state][1] > time:
                    time = csfs[state][1]
        print(time)
if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
csf = [0]*(N-1)
for i in range(N-1):
    csf[i] = list(map(int,input().split()))

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


Fixed code:
N = int(input())
csf = [0]*(N-1)
for i in range(N-1):
    csf[i] = list(map(int,input().split()))

for i in range(N-1):
    ans = 0
    ans += csf[i][1] + csf[i][0]
    for j in range(i+1, N-1):
        if ans >= csf[j][1]:
            if ans % csf[j][2] == 0:
                ans += csf[j][0]
            else:
                ans += csf[j][2] - (ans % csf[j][2]) + csf[j][0]
        else:
            ans = csf[j][1] + csf[j][0]
    
    print(ans)
print(0)
Buggy code:
import math

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

ans = 0
for i in range(n - 1):
    sm = 0
    for j in range(i, n - 1):
        c = cL[j]
        s = sL[j]
        f = fL[j]
        if sm < s:
            sm = s
        sm += c + (f - ((sm - s) % f) % f)
    print(sm)
print(0)

Fixed code:
import math

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

ans = 0
for i in range(n - 1):
    sm = 0
    for j in range(i, n - 1):
        c = cL[j]
        s = sL[j]
        f = fL[j]
        if sm < s:
            sm = s + c
            continue
        df = f - (sm - s) % f
        if df == f:
            df = 0
        sm += c + df
    print(sm)
print(0)
Buggy code:
n = int(input())
route, ans = [], []
for i in range(n-1):
    a = list(map(int, input().split()))
    route.append(a)
print(route)
for i in range(n-1):
    c = route[i][0]+route[i][1]
    for j in range(i+1, n-1):
        print(j)
        if c < route[j][1]:
            c = route[j][0]+route[j][1]
        elif (c-route[j][1])%route[j][2] == 0:
            c += route[j][0]
        else:
            c += c-route[j][1]+(c-route[j][1])%route[j][2]
    ans.append(c)
ans.append(0)
for i in ans:
    print(i)


Fixed code:
n = int(input())
route, ans = [], []
for i in range(n-1):
    a = list(map(int, input().split()))
    route.append(a)

for i in range(n-1):
    c = route[i][0]+route[i][1]
    for j in range(i+1, n-1):
        if c < route[j][1]:
            c = route[j][0]+route[j][1]
        elif (c-route[j][1])%route[j][2] == 0:
            c += route[j][0]
        else:
            c += route[j][0]+route[j][2]-(c-route[j][1])%route[j][2]
    ans.append(c)
ans.append(0)
for i in ans:
    print(i)
Buggy code:
n = int(input())
sta = []
for i in range(n-1):
    c,s,f = map(int,input().split())
    sta.append([c,s,f])

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



print(0)

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

for i in range(n-1):
    t = 0
    for j in range(i,n-1):
        if t <= sta[j][1]:
            t += sta[j][1]-t
        else:
            if not (t-sta[j][1])%sta[j][2]==0:
                t += sta[j][2]-(t-sta[j][1])%sta[j][2]
        t += sta[j][0]
    print(t)



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

Fixed code:
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(0, N-1):
    t = 0
    for j in range(i, N-1):
        if t <= S[j]:
            t = S[j]
        elif t%F[j] != 0:
            t += F[j] - t%F[j]
        t += C[j]
    print(t)
print(0)
Buggy code:
n = int(input())
c = [0]*n
s = [0]*n
f = [0]*n
ans = [0]*n

for i in range(n-1):
  c[i], s[i], f[i] = map(int, input().split())
    
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] is 0:
      t = s[j] + f[j]
    else:
      t = t + f [j] - t % f [j];
    t += c[j];
  print(t)

Fixed code:
n = int(input())
c = [0]*n
s = [0]*n
f = [0]*n
ans = [0]*n

for i in range(n-1):
  c[i], s[i], f[i] = map(int, input().split())
    
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] is 0:
      t = t
    else:
      t = t + f [j] - t % f [j];
    t += c[j];
  print(t)
Buggy code:
def tcalc(station):
  time = 0
  for i in range(station-1,n-1):
    f = l[i][2]
    s = l[i][1]
    c = l[i][0]
    time = max(((time-1)//f+1)*f, s)+c
  return time
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n-1)]
for i in range(1,n):
  print(tcalc(i))

Fixed code:
def tcalc(station):
  time = 0
  for i in range(station-1,n-1):
    f = l[i][2]
    s = l[i][1]
    c = l[i][0]
    time = max(((time-1)//f+1)*f, s)+c
  return time
n = int(input())
l = [tuple(map(int, input().split())) for _ in range(n-1)]
for j in range(1,n+1):
  print(tcalc(j))
Buggy code:
N = int(input())-1
timeLine = [[0 for x in range(3)] for y in range(N)]
for i in range(N):
    tmp = input().split()
    timeLine[i][0],timeLine[i][1],timeLine[i][2] = int(tmp[0]),int(tmp[1]),int(tmp[2])
for j in range(N):
    total = timeLine[j][0] + timeLine[j][1]
    now = j+1
    while now <= (N-1):
        if timeLine[now][1] >= total:
            total = timeLine[now][1] + timeLine[now][0]
        else:
            if timeLine[now][1] + timeLine[now][2] >= total:
                total = timeLine[now][1] + timeLine[now][2]
            else:
                n = int((total-timeLine[now][1])/timeLine[now][2]) + 1
                total = timeLine[now][1] + timeLine[now][2] * n
        now +=1
    print(total)
print(0)

Fixed code:
N = int(input())-1
timeLine = [[0 for x in range(3)] for y in range(N)]
for i in range(N):
    tmp = input().split()
    timeLine[i][0],timeLine[i][1],timeLine[i][2] = int(tmp[0]),int(tmp[1]),int(tmp[2])
for j in range(N):
    total = timeLine[j][0] + timeLine[j][1]
    now = j+1
    while now <= (N-1):
        if timeLine[now][1] >= total:
            total = timeLine[now][1] + timeLine[now][0]
        else:
            if timeLine[now][1] + timeLine[now][2] >= total:
                total = timeLine[now][0] + timeLine[now][1] + timeLine[now][2]
            else:
                n = int((total-timeLine[now][1])/timeLine[now][2])
                if (total-timeLine[now][1]) % timeLine[now][2] > 0:
                    n += 1
                total = timeLine[now][0] + timeLine[now][1] + timeLine[now][2] * n
        now +=1
    print(total)
print(0)
Buggy code:
 = int(input())
C = []
S = []
F = []
for i in range(N-1):
    C_temp,S_temp,F_temp = map(int,input().split())
    C.append(C_temp)
    S.append(S_temp)
    F.append(F_temp)
ans = S[0]
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)


Fixed code:
N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    C_temp,S_temp,F_temp = map(int,input().split())
    C.append(C_temp)
    S.append(S_temp)
    F.append(F_temp)
ans = S[0]
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)
Buggy code:
url = "https://atcoder.jp/contests/abc087/tasks/arc090_a"
import copy
def main():
    n = int(input())
    t = [list(map(int, input().split())) for _ in range(n-1)]
    for i in range(len(t)):
        time = 0
        for j in range(i, len(t)):
            st = t[j]
            if time < st[1]:
                time = st[1]
            elif time < st[1] + st[2]:
                time = st[1] + st[2]
            else:
                print((time - st[1]) % (st[2]))
                time += (time - st[1]) % (st[2])
            time += st[0]
        print(time)
    print(0)



if __name__ == '__main__':
    main()




Fixed code:
url = "https://atcoder.jp/contests/abc087/tasks/arc090_a"
import copy
def main():
    n = int(input())
    t = [list(map(int, input().split())) for _ in range(n-1)]
    for i in range(len(t)):
        time = t[i][0] + t[i][1]
        for j in range(i+1, len(t)):
            st = t[j]
            if time <= st[1]:
                time = st[1]
            elif time % st[2] == 0:
                pass
            else:
                time += st[2] - (time % (st[2]))
            time += st[0]
        print(time)
    print(0)



if __name__ == '__main__':
    main()
Buggy code:
N = int(input())
C = [0 for _ in range(N-1)]
S = [0 for _ in range(N-1)]
F = [0 for _ in range(N-1)]
for i in range(N-1):
	C[i],S[i],F[i] = map(int,input().split())

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

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


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

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

for i in range(N):
	print(f(i))
Buggy code:
n = int(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,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]):
            t += f[j]-(t%f[j])
        t += c[j]
    print(t)

Fixed code:
n = int(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,input().split())
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 += f[j]-(t%f[j])
        t += c[j]
    print(t)
Buggy code:
N=~-int(input())
C=[list(map(int,input().split())) for _ in range(N)]

for i in range(N):
 p,q,r=C[i]
 A=q+p
 for j in range(i+1,N):
  c,s,f=C[j]
  m=(A-s)%f
  if A<s:A=s
  if m!=0:A+=f-m
  A+=c
 print(A)
print(0)

Fixed code:
N=~-int(input())
C=[list(map(int,input().split())) for _ in range(N)]

for i in range(N):
 p,q,r=C[i]
 A=q+p
 for j in range(i+1,N):
  c,s,f=C[j]
  if A<s:A=s
  m=(A-s)%f
  if m!=0:A+=f-m
  A+=c
 print(A)
print(0)
Buggy code:
n, *CSF = map(int, open(0).read().split())
A = []
for i in range(0, 3*(n-1), 3):
    t = 0
    for c, s, f in zip(CSF[i::3], CSF[i+1::3], CSF[i+2::3]):
        if t <= s:
            t = s + c
        else:
            t = ceil((t-s) / f) * f + s + c
    A.append(t)
A.append(0)
print(*A, sep='\n')

Fixed code:
from math import ceil
n, *CSF = map(int, open(0).read().split())
A = []
for i in range(0, 3*(n-1), 3):
    t = 0
    for c, s, f in zip(CSF[i::3], CSF[i+1::3], CSF[i+2::3]):
        if t <= s:
            t = s + c
        else:
            t = ceil((t-s) / f) * f + s + c
    A.append(t)
A.append(0)
print(*A, sep='\n')
Buggy code:
n=int(input())
csf=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    ans=0
    for j in range(i,n-1):
        c = csf[j][0]
        s = csf[j][1]
        f = csf[j][2]
        if j==i:
            ans+=s+c
        else:
            if ans<s:
                ans=s+c
            else:
                ans+=(f-(ans-s)%f)+c
    print(ans)
print(0)

Fixed code:
n=int(input())
csf=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
    ans=0
    for j in range(i,n-1):
        c = csf[j][0]
        s = csf[j][1]
        f = csf[j][2]
        if j==i:
            ans+=s+c
        else:
            if ans<s:
                ans=s+c
            else:
                ans+=(f-(ans-s)%f)%f+c
    print(ans)
print(0)