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

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

AB = []

for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort()

ans = 0
cnt = 0

for ab in AB:
    for b in range(ab[1]):
        ans += ab[0]
        cnt += 1
        if cnt==M:
            break
    if cnt==M:
        break

print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N, M = map(int, input().split())
 
AB = []
 
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort(key=lambda x: x[0])
whole = [0]*sum([i[1] for i in AB])
cnt = 0
 
for ab in AB:
    for b in range(ab[1]):
        whole[cnt] = ab[0]
        cnt += 1

ans = list(accumulate(whole))

print(ans[M-1])

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
N, M = map(int, input().split())
 
AB = []
 
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a, b])

AB.sort(key=lambda x: x[0])
whole = [None]*sum([i[1] for i in AB])
cnt = 0
 
for ab in AB:
    for b in range(ab[1]):
        whole[cnt] = ab[0]
        cnt += 1

ans = list(accumulate(whole))

print(ans[M-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
N, M = map(int, input().split())

AB = np.zeros([N, 2], dtype=int)

for i in range(N):
    a, b = map(int, input().split())
    AB[i] = np.array([a, b])

AB = np.sort(AB, axis=0)

cnt = 0
whole = np.zeros(AB[:, 1].sum(), dtype=int)

for ab in AB:
    for b in range(ab[1]):
        whole[cnt] = ab[0]
        cnt += 1

whole = whole.cumsum()

print(int(whole[M-1]))
Problem p03106 (python)

Fixed submission:
a, b, k = map(int, input().split())

cnt = 0
for i in range(min(a, b), 0, -1):
    if a % i == 0 and b % i == 0:
        cnt += 1
    if cnt == k:
        break

print(i)

Buggy submission (verdict: Runtime Error):
a, b, k = map(int, input().split())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


a = set(make_divisors(a))
b = set(make_divisors(b))

ans = list(a & b)

print(ans[1])
Problem p03168 (python)

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

dp = [[0.0] * (n + 1) for _ in range(n + 1)]
dp[0][0] = 1.0

for i in range(n):
    for j in range(i + 1):
        dp[i + 1][j + 1] += dp[i][j] * arr[i]
        dp[i + 1][j] += dp[i][j] * (1 - arr[i])

dp = dp[-1]

print(sum(dp[-(n + 1) // 2:]))

Buggy submission (verdict: Runtime Error):
import numpy as np
n = int(input())
arr = list(map(float, input().split()))

dp = np.array([[0.0] * (n + 1) for _ in range(n + 1)])

dp[0, 0] = 1.0

for i in range(n):
    for j in range(i + 1):
        dp[i + 1, j + 1] += dp[i, j] * arr[i]
        dp[i + 1, j] += dp[i, j] * (1 - arr[i])

print(dp[-1, -(n + 1)//2:].sum())
Problem p03200 (python)

Fixed submission:
import numpy as np
S = np.array(list(map(str, input().rstrip())))

S[np.where(S=="W")] = 1
S[np.where(S=="B")] = 0
S = S.astype(int)
now = np.where(S==1)[0]
goal = np.arange(now.shape[0])

print((now - goal).sum())

Buggy submission (verdict: Runtime Error):
from functools import lru_cache
import numpy as np
S = np.array(list(map(str, input().rstrip())))

S[np.where(S=="W")] = 1
S[np.where(S=="B")] = 0
S = S.astype(int)

@lru_cache(maxsize=None)
def sum_n(n):
    if n<=1:
        return 1
    return (sum_n(n-1) + n)

goal = sum_n(S.sum())

now = (np.where(S==1)[0]+1).sum()

print(now - goal)
Problem p03212 (python)

Fixed submission:
def is_753(n):
    n = str(n)
    return(n.count("7") >= 1 and n.count("3") >= 1 and n.count("5") >= 1)


n = int(input())


v = [7, 5, 3]
li = []
prev = [7, 5, 3]

for i in range(9):
    tmp = []
    for j in v:
        for k in prev:
            tmp.append(k * 10 + j)
    prev = tmp
    li = li + prev

li = [x for x in li if is_753(x) and x <= n]

print(len(li))

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

N = int(input())
V = [3, 5, 7]

li = []


def rec(curr, use):
    if curr > N:
        return cnt
    if use == 0b111:
        li.append(curr)
    for i, b in enumerate(V):
        rec(curr * 10 + b, use | max(1, i * 2))


rec(0, 0)

print(len(li))
Problem p03238 (python)

Fixed submission:
n = int(input())

if n == 1:
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)

Buggy submission (verdict: Runtime Error):
n = int(input())

if n == 1:
    print("Hello World")
else:
    a, b = map(int, input().split())
    print(a + b)
Problem p03240 (python)

Fixed submission:
import sys
import numpy as np

n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]
xyh.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        tmp_h = abs(cy - y) + abs(cx - x) + h
        H = np.zeros(n, dtype=np.bool)
        for i, a in enumerate(xyh):
            H[i] = a[2] == max(tmp_h - abs(cx - a[0]) - abs(cy - a[1]), 0)
        if np.all(H):
            print(cx, cy, tmp_h)
            sys.exit()

Buggy submission (verdict: Runtime Error):
import sys

n = int(input())
xyh = [list(map(int, input().split())) for _ in range(n)]
xyh.sort(key=lambda x: x[2], reverse=True)

for cx in range(101):
    for cy in range(101):
        x, y, h = xyh[0]
        tmp_h = abs(cy - y) + abs(cx - x) + h
        H = np.zeros(n, dtype=np.bool)
        for i, a in enumerate(xyh):
            H[i] = a[2] == max(tmp_h - abs(cx - a[0]) - abs(cy - a[1]), 0)
        if np.all(H):
            print(cx, cy, tmp_h)
            sys.exit()
Problem p03244 (python)

Fixed submission:
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

v1 = v[0::2]
v2 = v[1::2]

c1 = Counter(v1)
c2 = Counter(v2)

c1 = c1.most_common()
c2 = c2.most_common()

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
else:
    if len(c2) > 1:
        choice_1 = c1[0][1] + c2[1][1]
    else:
        choice_1 = c1[0][1]
    if len(c1) > 1:
        choice_2 = c2[0][1] + c1[1][1]
    else:
        choice_2 = c2[0][1]
    ans = n - (max(choice_1, choice_2))

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

v1 = v[0::2]
v2 = v[1::2]

c1 = Counter(v1)
c2 = Counter(v2)

c1 = c1.most_common()
c2 = c2.most_common()

if c1[0][0] != c2[0][0]:
    ans = n - c1[0][1] - c2[0][1]
elif c1[0][1] + c2[1][1] >= c2[0][1] + c1[1][1]:
    ans = n - c1[0][1] - c2[1][1]
else:
    ans = n - c2[0][1] - c1[1][1]

print(ans)
Problem p03263 (python)

Fixed submission:
h, w = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(h)]

ans = []
for i in range(h):
    for j in range(w - 1):
        if arr[i][j] % 2 == 1:
            arr[i][j] -= 1
            arr[i][j + 1] += 1
            ans.append([i + 1, j + 1, i + 1, j + 2])

for i in range(h - 1):
    if arr[i][w - 1] % 2 == 1:
        arr[i][w - 1] -= 1
        arr[i + 1][w - 1] += 1
        ans.append([i + 1, w, i + 2, w])

print(len(ans))
for x in ans:
    print(*x)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(h)]

ans = []
for i in range(h):
    for j in range(w - 1):
        if arr[i][j] % 2 == 1:
            arr[i][j] -= 1
            arr[i][j + 1] += 1
            ans.append([i + 1, j + 1, i + 1, j + 2])

for i in range(h - 1):
    if arr[i][w - 1] % 2 == 1:
        arr[i][w - 1] -= 1
        arr[i + 1][w - 1] += 1
        ans.append([i + 1, j + 1, i + 2, j + 1])

print(len(ans))
for x in ans:
    print(*x)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(h)]
visited = [[False] * w for _ in range(h)]

dt = "right"
c = [0, 0]
cnt = 0
ans = []
while cnt < h * w:
    cnt += 1
    visited[c[0]][c[1]] = True
    if dt == "right":
        if arr[c[0]][c[1]] % 2 == 1:
            arr[c[0]][c[1]] -= 1
            arr[c[0]][c[1] + 1] += 1
            ans.append([c[0] + 1, c[1] + 1, c[0] + 1, c[1] + 2])
        if c[1] + 1 == w - 1 or visited[c[0]][c[1] + 1]:
            dt = "down"
        c = [c[0], c[1] + 1]
        continue
    if dt == "down":
        if arr[c[0]][c[1]] % 2 == 1:
            arr[c[0]][c[1]] -= 1
            arr[c[0] + 1][c[1]] += 1
            ans.append([c[0] + 1, c[1] + 1, c[0] + 2, c[1] + 1])
        if c[0] + 1 == h - 1 or visited[c[0] + 1][c[1]]:
            dt = "left"
        c = [c[0] + 1, c[1]]
        continue
    if dt == "left":
        if arr[c[0]][c[1]] % 2 == 1:
            arr[c[0]][c[1]] -= 1
            arr[c[0]][c[1] - 1] += 1
            ans.append([c[0] + 1, c[1] + 1, c[0] + 1, c[1]])
        if c[1] - 1 == 0 or visited[c[0]][c[1] - 1]:
            dt = "up"
        c = [c[0], c[1] - 1]
        continue
    if dt == "up":
        if arr[c[0]][c[1]] % 2 == 1:
            arr[c[0]][c[1]] -= 1
            arr[c[0] - 1][c[1]] += 1
            ans.append([c[0] + 1, c[1] + 1, c[0], c[1] + 1])
        if c[0] - 1 == 0 or visited[c[0] - 1][c[1]]:
            dt = "right"
        c = [c[0] - 1, c[1]]
        continue

print(len(ans))
for x in ans:
    print(*x)
Problem p03273 (python)

Fixed submission:
H, W = map(int, input().split())

a = []

# 必要な行だけ読み込む
for i in range(H):
    tmp = list(input())
    if "#" not in tmp:
        continue
    else:
        a.append(tmp)

# 転置して削って転置
a = list(zip(*a))
a = [x for x in a if "#" in x]
a = list(zip(*a))

for i in a:
    print("".join(i))

Buggy submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split())

ans = []

judge_h = []

for i in range(H):
    tmp = list(map(str, input().rstrip()))
    ans.append(tmp)
    if tmp.count("#")==0:
        judge_h.append(False)
    else:
        judge_h.append(True)

ans = np.array(ans)

judge_w = []

for i in range(W):
    if np.where(ans[:, i]=="#")[0].shape[0]==0:
        judge_w.append(False)
    else:
        judge_w.append(True)

ans = ans[judge_h, :]
ans = ans[:, judge_w]
ans = [list(i) for i in ans]

for i in range(len(ans)):
    print("".join(ans[i]))

Buggy submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split())

ans = []

judge_h = []

for i in range(H):
    tmp = list(map(str, input().rstrip()))
    ans.append(tmp)
    if tmp.count("#")==0:
        judge_h.append(False)
    else:
        judge_h.append(True)

ans = np.array(ans)

judge_w = []

for i in range(W):
    if np.where(ans[:, i]=="#")[0].shape[0]==0:
        judge_w.append(False)
    else:
        judge_w.append(True)

ans = ans[judge_h, :]
ans = ans[:, judge_w]

for i in range(ans.shape[0]):
    print("".join(ans[i]))

Buggy submission (verdict: Runtime Error):
import numpy as np

H, W = map(int, input().split())

ans = []

for i in range(H):
    tmp = list(map(str, input().rstrip()))
    if tmp.count("#")==0:
        continue
    else:
        ans.append(tmp)

ans = np.array(ans)

judge = []

for i in range(W):
    if np.where(ans[:, i]=="#")[0].shape[0]==0:
        judge.append(False)
    else:
        judge.append(True)

ans = ans[:, judge]

for i in range(ans.shape[0]):
    print("".join(ans[i]))
Problem p03274 (python)

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

ans = []
for i in range(n - k + 1):
    left = x[i]
    right = x[i + k - 1]
    ans.append(min(abs(left) + abs(right - left),
                   abs(right) + abs(left - right)))

print(min(ans))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = []
for i in range(n - k + 1):
    left = x[i]
    right = x[i + k - 1]
    elif abs(left) > abs(right):
        ans.append(abs(right) + abs(left - right))
    else:
        ans.append(abs(left) + abs(right - left))

print(min(ans))
Problem p03281 (python)

Fixed submission:
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


n = int(input())

ans = 0
for i in [2 * x + 1 for x in range((n + 1) // 2)]:
    if len(make_divisors(i)) == 8:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import sympy

n = int(input())

ans = 0
for i in range(1, n + 1, 2):
    if len(sympy.divisors(i)) == 8:
        ans += 1

print(ans)
Problem p03282 (python)

Fixed submission:
import numpy as np
S = np.array(list(map(str, input().rstrip())))
K = int(input())

cnt = 0
ans = 1

for i, s in enumerate(S):
    if s != "1":
        cnt = i+1
        ans = s
        break

if cnt > K:
    print(1)
else:
    print(int(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
S = np.array(list(map(str, input().rstrip())))
K = int(input())

cnt = 0

for i, s in enumerate(S):
    if s != "1":
        cnt = i+1
        ans = s
        break

if cnt > K:
    print(1)
else:
    print(int(ans))

Buggy submission (verdict: Runtime Error):
import numpy as np
S = np.array(list(map(str, input().rstrip())))
K = int(input())

for i, s in enumerate(S):
    if s != "1":
        cnt = i+1
        ans = s
        break

if cnt > K:
    print(1)
else:
    print(int(s))
Problem p03311 (python)

Fixed submission:
import sys
import numpy as np
n = int(input())
arr = np.array(list(map(int, input().split())))

comp = np.arange(n) + 1
diff = arr - comp

diff.sort()

diff = diff - np.median(diff)

print(int(np.abs(diff).sum()))

Buggy submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))

arr = np.arange(n) + 1
diff = a - arr

diff.sort()

diff -= np.median(diff)

print(int(np.abs(diff).sum()))
Problem p03324 (python)

Fixed submission:
import numpy as np
D, N = map(int, input().split())

def cnt(n):
    tmp = 0
    n = n*1.0
    while n.is_integer():
        if (n/100.0).is_integer():
            tmp += 1
            n = n / 100.0
        else:
            break
            
    return tmp

coef = 100**D
whole = np.array([i*coef for i in range(1, 150)])
result = np.array(list(map(cnt, whole)))

print(whole[np.where(result==D)][N-1])

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

def cnt(n):
    tmp = 0
    n = n*1.0
    while n.is_integer():
        if (n/100.0).is_integer():
            tmp += 1
            n = n / 100.0
        else:
            break
            
    return tmp

coef = 100**D
whole = np.array([i*coef for i in range(1, 150)])
result = np.array(list(map(cnt, whole)))

print(whole[np.where(result==D)][N-1])
Problem p03356 (python)

Fixed submission:
class UnionFind:
    def __init__(self, n):
        self.root = list(range(n + 1))
        self.size = [1] * (n + 1)

    def find(self, x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        sx, sy = self.size[x], self.size[y]
        if sx < sy:
            self.root[x] = y
            self.size[y] += sx
        else:
            self.root[y] = x
            self.size[x] += sy


n, m = map(int, input().split())
p = list(map(int, input().split()))


uf = UnionFind(n)
union = uf.union
find = uf.find


for _ in range(m):
    x, y = map(int, input().split())
    union(x - 1, y - 1)

ans = 0
for i, x in enumerate(p):
    if find(i) == find(x - 1):
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
class UnionFind:
    def __init__(self, n):
        self.root = list(range(n + 1))
        self.size = [1] * (n + 1)

    def find(self, x):
        root = self.root
        while root[x] != x:
            root[x] = root[root[x]]
            x = root[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        sx, sy = self.size[x], self.size[y]
        if sx < sy:
            self.root[x] = y
            self.size[y] += sx
        else:
            self.root[y] = x
            self.size[x] += sy


n, m = map(int, input().split())
p = np.array(list(map(int, input().split())))


uf = UnionFind(n)
union = uf.union
find = uf.find


for _ in range(m):
    x, y = map(int, input().split())
    union(x - 1, y - 1)

ans = 0
for i, x in enumerate(p):
    if find(i) == find(x - 1):
        ans += 1

print(ans)
Problem p03393 (python)

Fixed submission:
import sys
from collections import deque
s = deque(map(str, input().rstrip()))

if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    s = s[::-1]
    prev = s[0]
    add.append(prev)

    if prev == 122:
        s[1] = 122
        s = s[::-1]
        s = s[:-1]

    else:
        for i in range(1, len(s)):
            if prev > s[i]:
                add = [x for x in add if x > s[i]]
                s[i] = (min(add))
                s = s[::-1]
                s = s[:-i]
                break
            prev = s[i]
            add.append(prev)

s = [chr(x) for x in s]

print("".join(s))

Buggy submission (verdict: Runtime Error):
import sys
s = deque(map(str, input().rstrip()))

if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    cnt = 0
    while s:
        cnt += 1
        q = s.pop()
        add.append(q)
        if q == 122:
            break
    add = [x for x in add if x > s[-1]]
    
    if cnt != 1:
        s[-1] = min(add)

s = [chr(x) for x in s]

print("".join(s))

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
from collections import Counter
s = deque(map(str, input().rstrip()))

if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()

s = [ord(x) for x in s]

if len(s) < 26:
    can_use = set(range(97, 123)) - set(s)
    s = s + [min(can_use)]

else:
    add = []
    while s:
        q = s.pop()
        if q == 122:
            break
        else:
            add.append(q)

    s[-1] = min(add)

s = [chr(x) for x in s]

print("".join(s))

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
from collections import Counter
s = deque(map(str, input().rstrip()))

if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()

s = [ord(x) for x in s]

if len(s) == 26:
    maxlen = True
    s = s[::-1]
    x = s[0]
    for i, w in enumerate(s):
        if x > w:
            break

    s = s[::-1]
    s = s[:-i - 1]

can_use = set(range(97, 123)) - set(s)
if maxlen:
    can_use = can_use - {min(can_use)}
s = s + [min(can_use)]

s = [chr(x) for x in s]

print("".join(s))

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
from collections import Counter
s = deque(map(str, input().rstrip()))

if "".join(s) == "zyxwvutsrqponmlkjihgfedcba":
    print(-1)
    sys.exit()

s = [ord(x) for x in s]

if len(s) == 26:
    maxlen = True
    s = s[::-1]
    x = s[0]
    for i, w in enumerate(s):
        if x > w:
            break

    s = s[::-1]
    s = s[:-i - 1]

can_use = set(range(97, 123)) - set(s)
if maxlen:
    s = s + [min(can_use) + 1]
else:
    s = s + [min(can_use)]

s = [chr(x) for x in s]

print("".join(s))
Problem p03403 (python)

Fixed submission:
import numpy as np
n = int(input())
a = np.array([0] + list(map(int, input().split())) + [0])

whole = np.abs((np.diff(a))).sum()

for i in range(n):
    print(whole - abs(a[i + 1] - a[i]) -
          abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = np.array([0] + list(map(int, input().split())) + [0])

whole = np.abs((np.diff(a))).sum()

for i in range(n):
    print(whole - abs(a[i + 1] - a[i]) -
          abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]))
Problem p03423 (python)

Fixed submission:
n = int(input())
print(n // 3)

Buggy submission (verdict: Runtime Error):
h, w, d = map(int, input().split())
arr = [0] * (h * w + 1)

a = [list(map(int, input().split())) for _ in range(h)]

for i in range(h):
    for j in range(w):
        s = a[i][j]
        arr[s] = (i, j)

q = int(input())
lr = [list(map(int, input().split())) for _ in range(q)]

cnt = h * w
result = [[0] for _ in range(d)]
for i in range(d):
    l = i
    score = 0
    while l + d <= cnt:
        if l == 0:
            result[i].append(score)
            l += d
            continue
        (ux, uy) = arr[l]
        (vx, vy) = arr[l + d]
        score += (abs(vx - ux) + abs(vy - uy))
        result[i].append(score)
        l += d


for l, r in lr:
    ans = result[l % d]
    print(ans[r // d] - ans[l // d])
Problem p03475 (python)

Fixed submission:
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 submission (verdict: Runtime Error):
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 submission (verdict: Runtime Error):
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")