Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

x0, y0, h0 = map(int, input().split())
for i in range(N):
  xi, yi, hi = map(int, input().split())
  if xi-x0 == abs(xi-x0):
    hx = hi + (100 -xi)
  else:
    hx = hi +xi

  if yi-y0 == abs(yi-y0):
    hy = hx + (100 -yi)
  else:
    hy = hx +yi

print(hy)

Fixed submission:
# -*- coding: utf-8 -*-
# 整数の入力
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 = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
#arr.sort(key=lambda l:-l[2])
 
for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()

Fixed submission:
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort(key=lambda l:-l[2])
 
for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()

Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
# 整数の入力
N = int(input())

x0, y0, h0 = map(int, input().split())
for i in range(N):
  xi, yi, hi = map(int, input().split())
  if xi-x0 == abs(xi-x0):
    hx = hi + (100 -xi)
  else:
    hx = hi +xi

  if yi-y0 == abs(yi-y0):
    hy = hx + (100 -yi)
  else:
    hy = hx +yi

print(hy)

Fixed submission:
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort(key=lambda l:-l[2])
 
for cx in range(101):
  for cy in range(101):
    ch = None
    for x, y, h in arr:
      t = h + abs(cx-x) + abs(cy-y)
      if h > 0:
        if ch is not None and t != ch:
          break
        ch = t
      else:
        if t < ch:
          break
    else:
      print(cx, cy, ch)
      exit()
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
print ((a-1)*(b-1))

Fixed submission:
a, b = map(int, input().split())
print ((a-1)*(b-1))

Buggy python submission (verdict: Runtime Error):
(A-1)*(B-1)

Fixed submission:
a, b = map(int, input().split())
print ((a-1)*(b-1))
Buggy python submission (verdict: Runtime Error):
a = int(input())

b=0#約数の個数

for i in range(1,a+1, 2):#i:1~inputまで,奇数だけ
  #ある数Niについて約数を数える
	yakusuu_array = []

	for i in range(1,num):
	    if num % i == 0:
            yakusuu_array.append(i)
            
  	if len(yakusuu_array) == 8:
  		b += 1
print(b)

Fixed submission:
a = int(input())
 
b=0#約数の個数
 
for num in range(1,a+1):#i:1~inputまで,奇数だけ
  if num % 2 == 1:
  #ある数Niについて約数を数える
    yakusuu = 0
    for i in range(1,num):
      if num % i == 0:
        yakusuu += 1
    if yakusuu == 7:
      b += 1
print(b)

Buggy python submission (verdict: Runtime Error):
a = int(input())

b=0#約数の個数

for i in range(1,a+1, 2):#i:1~inputまで,奇数だけ
  #ある数Niについて約数を数える
    yakusuu_array = []

    for i in range(1,num):
        if num % i == 0:
    	    yakusuu_array.append(i)
            
    if len(yakusuu_array) == 8:
  	    b += 1
print(b)

Fixed submission:
a = int(input())
 
b=0#約数の個数
 
for num in range(1,a+1):#i:1~inputまで,奇数だけ
  if num % 2 == 1:
  #ある数Niについて約数を数える
    yakusuu = 0
    for i in range(1,num):
      if num % i == 0:
        yakusuu += 1
    if yakusuu == 7:
      b += 1
print(b)

Buggy python submission (verdict: Runtime Error):
a = int(input())

b=0#約数の個数

for i in range(1,a+1, 2):#i:1~inputまで,奇数だけ
  #ある数Niについて約数を数える
	yakusuu_array = []

	for i in range(1,num):
	    if num % i == 0:
    	    yakusuu_array.append(i)
            
  	if len(yakusuu_array) == 8:
  		b += 1
print(b)

Fixed submission:
a = int(input())
 
b=0#約数の個数
 
for num in range(1,a+1):#i:1~inputまで,奇数だけ
  if num % 2 == 1:
  #ある数Niについて約数を数える
    yakusuu = 0
    for i in range(1,num):
      if num % i == 0:
        yakusuu += 1
    if yakusuu == 7:
      b += 1
print(b)

Buggy python submission (verdict: Runtime Error):
a = int(input())

b=0#約数の個数

for i in range(1,a+1, 2):#i:1~inputまで,奇数だけ
  #ある数Niについて約数を数える
	yakusuu_array = []

	for i in range(1,num):
	    if num % i == 0:
    	    yakusuu_array.append(i)
            
  	if len(yakusuu_array) == 8:
  		b += 1
print(b)

Fixed submission:
a = int(input())
 
b=0#約数の個数
 
for num in range(1,a+1):#i:1~inputまで,奇数だけ
  if num % 2 == 1:
  #ある数Niについて約数を数える
    yakusuu = 0
    for i in range(1,num):
      if num % i == 0:
        yakusuu += 1
    if yakusuu == 7:
      b += 1
print(b)
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
print min(0,a-b)

Fixed submission:
a, b = map(int, input().split())
print (a-b) if a-b>0 else print (0)
Buggy python submission (verdict: Runtime Error):
x,y = map(int, input().split())
ans='No'
if x,y in [2]:
  if y in [2]:
    ans='Yes'
if x in [4,6,9,11]:
  if y in [4,6,9,11]:
    ans='Yes'
if x in [1,3,5,7,8,10,12]:
  if y in [1,3,5,7,8,10,12]:
    ans='Yes'
print(ans)

Fixed submission:
x,y = map(int, input().split())
ans='No'
if x in [2]:
  if y in [2]:
    ans='Yes'
if x in [4,6,9,11]:
  if y in [4,6,9,11]:
    ans='Yes'
if x in [1,3,5,7,8,10,12]:
  if y in [1,3,5,7,8,10,12]:
    ans='Yes'
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

h, n = ril()
ls = rils(n)
dp = [float('inf')] * (h + 1)
dp[0] = 0
for i, (a, b) in enumerate(ls):
    for j in range(h + 1):
        dp[min(j + a, h)] = min(dp[min(j + a, h)], dp[j] + b)
print(dp[-1])

Fixed submission:
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

h, n = ril()
ls = rils(n)
dp = [float('inf')] * (h + 1)
dp[0] = 0
for i, (a, b) in enumerate(ls):
    for j in range(h + 1):
        dp[min(j + a, h)] = min(dp[min(j + a, h)], dp[j] + b)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

MOD = 10**9 + 7

n = ri()
ls = ril()
counter = collections.defaultdict(int)
for a in ls:
    i = 0
    while a > 0:
        if a % 2 == 1:
            counter[i] += 1
        a //= 2
        i += 1
res = 0
for k, v in counter.items():
    res += (n - v) * v * 2**k % MOD
    res %= MOD
print(res)

Fixed submission:
import collections
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

MOD = 10**9 + 7

n = ri()
ls = ril()
counter = collections.defaultdict(int)
for a in ls:
    i = 0
    while a > 0:
        if a % 2 == 1:
            counter[i] += 1
        a //= 2
        i += 1
res = 0
for k, v in counter.items():
    res += (n - v) * v * 2**k % MOD
    res %= MOD
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


def check(m, k, vs):
    s = 0
    for x, y, v in vs:
        if v >= m:
            s += (v - m + y - 1) // y
    return s <= k


n, k = read_i()
ls0 = sorted(read_i())
ls1 = sorted(read_i(), reverse=True)
if sum(ls0) <= k:
    print(0)
    exit()

vs = [(x, y, x * y) for x, y in zip(ls0, ls1)]

lo = 0
hi = sum(v for _, _, v in vs)
while hi - lo > 1:
    mid = (lo + hi) // 2
    if check(mid, k, vs):
        hi = mid
    else:
        lo = mid
print(hi)

Fixed submission:
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


def check(m, k, vs):
    s = 0
    for x, y, v in vs:
        if v >= m:
            s += (v - m + y - 1) // y
    return s <= k


n, k = read_i()
ls0 = sorted(read_i())
ls1 = sorted(read_i(), reverse=True)
if sum(ls0) <= k:
    print(0)
    exit()

vs = [(x, y, x * y) for x, y in zip(ls0, ls1)]

lo = 0
hi = sum(v for _, _, v in vs)
while hi - lo > 1:
    mid = (lo + hi) // 2
    if check(mid, k, vs):
        hi = mid
    else:
        lo = mid
print(hi)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


n = int(input())
ls = sorted(read_i())
ls2 = ls[::-1]
res = 0
for i, x in enumerate(ls2):
    for j, y in enumerate(ls2[i + 1:], i + 1):
        res += n - j - 1 - bisect.bisect(ls[:-(j + 1)], x - y)
print(res)

Fixed submission:
import bisect
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


n = int(input())
ls = sorted(read_i())
ls2 = ls[::-1]
res = 0
for i, x in enumerate(ls2):
    for j, y in enumerate(ls2[i + 1:], i + 1):
        if 2 * y < x:
            break
        res += n - j - 1 - bisect.bisect(ls[:-(j + 1)], x - y)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


n = int(input())
ls = sorted(read_i(), reverse=True)
res = 0
for i, x in enumerate(ls):
    for j, y in enumerate(ls[i + 1:], i + 1):
        if 2 * y < x:
            break
        res += n - j - 1 - bisect.bisect(ls[j + 1:][::-1], x - y)
print(res)

Fixed submission:
import bisect
import sys

input = sys.stdin.readline


def read_i():
    return list(map(int, input().split()))


n = int(input())
ls = sorted(read_i())
ls2 = ls[::-1]
res = 0
for i, x in enumerate(ls2):
    for j, y in enumerate(ls2[i + 1:], i + 1):
        if 2 * y < x:
            break
        res += n - j - 1 - bisect.bisect(ls[:-(j + 1)], x - y)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ps = [float('inf')] * 2**n
for _ in range(m):
    a, b = map(int, input().split())
    s = sum([2**(i - 1) for i in map(int, input().split())])
    ps[s] = min(ps[s], a)
    for i in range(2**n):
        if i == s:
            ps[i] = min(ps[i], ps[s])
        elif i & s == i:
            ps[i] = min(ps[i], ps[s])
        elif i & s == s:
            ps[s] = min(ps[i], ps[s])
        else:
            ps[i | s] = min(ps[i | s], ps[i] + ps[s])
if ps[2**n - 1] == float('inf'):
    print(-1)
else:
    print(ps[2**n - 1])

Fixed submission:
n, m = map(int, input().split())
ps = [float('inf')] * 2**n
for _ in range(m):
    a, b = map(int, input().split())
    s = sum([2**(i - 1) for i in map(int, input().split())])
    ps[s] = min(ps[s], a)
    for i in range(2**n):
        if i == s:
            ps[i] = min(ps[i], ps[s])
        elif i & s == i:
            ps[i] = min(ps[i], ps[s])
        elif i & s == s:
            ps[s] = min(ps[i], ps[s])
        else:
            ps[i | s] = min(ps[i | s], ps[i] + ps[s])
if ps[2**n - 1] == float('inf'):
    print(-1)
else:
    print(ps[2**n - 1])
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ps = list(map(int, input().split()))
s = sum(ps)
ls = []
for p in ps:
    prev = p
    while p > 0:
        p //= 2
        ls.append(prev - p)
        prev = p
ls.sort(reverse=True)
print(s - sum(ls[:m]))

Fixed submission:
n, m = map(int, input().split())
ps = list(map(int, input().split()))
s = sum(ps)
ls = []
for p in ps:
    prev = p
    while p > 0:
        p //= 2
        ls.append(prev - p)
        prev = p
ls.sort(reverse=True)
print(s - sum(ls[:m]))
Buggy python submission (verdict: Runtime Error):
if int(input()) < 3200:
    return 'red'
else:
    return input()

Fixed submission:
a = int(input())
s =input()
if a < 3200:
    print('red')
else:
    print(s)

Buggy python submission (verdict: Runtime Error):
a = int(input())
s =input()
if a < 3200:
    return 'red'
else:
    return s

Fixed submission:
a = int(input())
s =input()
if a < 3200:
    print('red')
else:
    print(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = list(map(input().split(' '), lambda x: 1 / int(x)))
print(1 / sum(nums))

Fixed submission:
n = int(input())
nums = map(lambda x: 1 / int(x), input().split(' '))
print(1 / sum(nums))

Buggy python submission (verdict: Runtime Error):
n = int(input())
num = 0
for _ in range(n):
    num += 1 / int(input())
print(1 / num)

Fixed submission:
n = int(input())
nums = map(lambda x: 1 / int(x), input().split(' '))
print(1 / sum(nums))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
list_s = [''.join(sorted(input())) for _ in range(n)]
res = 0
for i in range(n):
    for j in range(i + 1, n):
        if list_s[i] == list_s[j]:
            res += 1
print(res)

Fixed submission:
import collections

n = int(input())

counter = collections.Counter()
for _ in range(n):
    s = ''.join(sorted(input()))
    counter[s] += 1

res = 0
for value in counter.values():
    if value > 1:
        res += value * (value - 1) // 2

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
ls.sort(key=lambda x: x[0])
la = [x[0] for x in ls]
lb = [x[1] for x in ls]

selected = []
res = 0
for i in range(1, m + 1):
    k = bisect.bisect(la, i)
    bs = lb[:k]
    index = -1
    temp = 0
    for j, b in enumerate(bs):
        if j in selected:
            continue
        if temp < b:
            index = j
            temp = b
    if index >= 0:
        selected.append(index)
        res += temp

print(res)

Fixed submission:
import heapq

n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
ls.sort(key=lambda x: x[0])

q = []
res = 0
index = 0
for i in range(1, m + 1):
    while index < n and ls[index][0] <= i:
        heapq.heappush(q, -ls[index][1])
        index += 1
    if len(q) > 0:
        res += -heapq.heappop(q)
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
ls.sort(key=lambda x: x[0])
la = [x[0] for x in ls]
lb = [x[1] for x in ls]

selected = []
res = 0
for i in range(1, m + 1):
    k = bisect.bisect(la, i)
    bs = lb[:k]
    index = -1
    temp = 0
    for j, b in enumerate(bs):
        if j in selected:
            continue
        if temp < b:
            index = j
            temp = b
    if index >= 0:
        selected.append(index)
        res += temp

print(res)

Fixed submission:
import heapq

n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
ls.sort(key=lambda x: x[0])

q = []
res = 0
index = 0
for i in range(1, m + 1):
    while index < n and ls[index][0] <= i:
        heapq.heappush(q, -ls[index][1])
        index += 1
    if len(q) > 0:
        res += -heapq.heappop(q)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
hs = list(map(int, input().split()))

ok = True
for i in range(n - 1):
    for j in range(i + 1, n):
        if hs[i] - hs[j] > 1:
            ok = False
            break
    if not ok:
        break
if ok:
    print('Yes')
else:
    print('No')

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

ok = True
threshold = hs[0] - 1
for i in range(1, n):
    if hs[i] < threshold:
        ok = False
        break
    threshold = max(threshold, hs[i] - 1)
if ok:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input().split()))

bs = nums.copy()
res = []

for i in range(n // 2, 0, -1):
    bs[i] = 0
    for j in range(1, n // i):
        bs[i] += bs[i * j]
    bs[i] %= 2
for i in range(n):
    if bs[i] > 0:
        res.append(i + 1)
m = sum(bs)
print(m)
if m > 0:
    print(' '.join(map(str, res)))



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

bs = nums.copy()
res = []

for i in range(n // 2, 0, -1):
    val = 0
    for j in range(1, n // i + 1):
        if i * j <= n:
            val += bs[i * j - 1]
    bs[i - 1] = val % 2
for i in range(n):
    if bs[i] > 0:
        res.append(i + 1)
m = sum(bs)
print(m)
if m > 0:
    print(' '.join(map(str, res)))

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

res = nums.copy()

for i in range(n // 2, 0, -1):
    res[i] = 0
    for j in range(1, n // i + 1):
        res[i] += res[i * j]
    res[i] %= 2
for elem in res:
    print(elem)


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

bs = nums.copy()
res = []

for i in range(n // 2, 0, -1):
    val = 0
    for j in range(1, n // i + 1):
        if i * j <= n:
            val += bs[i * j - 1]
    bs[i - 1] = val % 2
for i in range(n):
    if bs[i] > 0:
        res.append(i + 1)
m = sum(bs)
print(m)
if m > 0:
    print(' '.join(map(str, res)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = [int(input()) for _ in range(n)]

count = 0
selected = [False for _ in range(n)]
for i in range(n):
    if not selected[i]:
        selected[i] = True
        count += 1

        m = nums[i]
        for j in range(i + 1, n):
            if not selected[j]:
                num = nums[j]
                if num > m:
                    m = num
                    selected[j] = True
print(count)

Fixed submission:
import bisect
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n = ri()
ls = ris(n)
ls = [-x for x in ls]

dp = [float('inf')] * n
for x in ls:
    dp[bisect.bisect_right(dp, x)] = x
print(bisect.bisect_left(dp, float('inf')))
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
nums = [int(input()) for _ in range(m)]

NUM = int(10**9 + 7)

split = [[0, nums[0] - 1]]
for i in range(1, m):
    split.append([nums[i - 1] + 1, nums[i] - 1])
split.append([nums[-1] + 1, n])

n_steps = [h - l for l, h in split]

counts = [1, 1, 2]
for _ in range(max(n_steps) - 2):
    c = counts[-1] + counts[-2]
    counts.append(c)

if min(n_steps) < 0:
    print(0)
else:
    res = 1
    for s in n_steps:
        res *= counts[s]
        res %= NUM
    print(res)

Fixed submission:
NUM = int(10**9 + 7)

n, m = map(int, input().split())
nums = [int(input()) for _ in range(m)]

if m > 0:
    split = [[0, nums[0] - 1]]
    for i in range(1, m):
        split.append([nums[i - 1] + 1, nums[i] - 1])
    split.append([nums[-1] + 1, n])
else:
    split = [[0, n]]

n_steps = [h - l for l, h in split]

counts = [1, 1]
for _ in range(max(n_steps) - 1):
    c = counts[-1] + counts[-2]
    counts.append(c)

if min(n_steps) < 0:
    print(0)
else:
    res = 1
    for s in n_steps:
        res *= counts[s]
        res %= NUM
    print(res)

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
nums = [int(input()) for _ in range(m)]

NUM = int(10**9 + 7)

split = [[0, nums[0] - 1]]
for i in range(1, m):
    split.append([nums[i - 1] + 1, nums[i] - 1])
split.append([nums[-1] + 1, n])

n_steps = [h - l for l, h in split]

counts = [1, 1, 2]
for _ in range(max(n_steps) - 2):
    c = counts[-1] + counts[-2]
    counts.append(c)

if min(n_steps) < 0:
    print(0)
else:
    res = 1
    for s in n_steps:
        res *= counts[s]
        res %= NUM
    print(res)

Fixed submission:
NUM = int(10**9 + 7)

n, m = map(int, input().split())
nums = [int(input()) for _ in range(m)]

if m > 0:
    split = [[0, nums[0] - 1]]
    for i in range(1, m):
        split.append([nums[i - 1] + 1, nums[i] - 1])
    split.append([nums[-1] + 1, n])
else:
    split = [[0, n]]

n_steps = [h - l for l, h in split]

counts = [1, 1]
for _ in range(max(n_steps) - 1):
    c = counts[-1] + counts[-2]
    counts.append(c)

if min(n_steps) < 0:
    print(0)
else:
    res = 1
    for s in n_steps:
        res *= counts[s]
        res %= NUM
    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
visited = [[False] * w for _ in range(h)]
pts = []
for i in range(h):
    s = input().rstrip()
    for j in range(w):
        if s[j] == '#':
            visited[i][j] = True
            pts.append((i, j))
res = 0
ds = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while True:
    new_pts = []
    for i, j in pts:
        for dx, dy in ds:
            new_i = i + dy
            new_j = j + dx
            if 0 <= new_i < h and 0 <= new_j < w and not visited[new_i][new_j]:
                visited[new_i][new_j] = True
                new_pts.append((new_i, new_j))
    if len(new_pts) > 0:
        res += 1
        pts = new_pts
    else:
        break
print(res)

Fixed submission:
h, w = map(int, input().split())
visited = [[False] * w for _ in range(h)]
pts = []
for i in range(h):
    s = input().rstrip()
    for j in range(w):
        if s[j] == '#':
            visited[i][j] = True
            pts.append((i, j))
res = 0
ds = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while True:
    new_pts = []
    for i, j in pts:
        for dx, dy in ds:
            new_i = i + dy
            new_j = j + dx
            if 0 <= new_i < h and 0 <= new_j < w and not visited[new_i][new_j]:
                visited[new_i][new_j] = True
                new_pts.append((new_i, new_j))
    if len(new_pts) > 0:
        res += 1
        pts = new_pts
    else:
        break
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]
nodes = [[i, [i], 1] for i in range(n + 1)]
res = [n * (n - 1) // 2]
for a, b in reversed(ls):
    x = nodes[a][0]
    y = nodes[b][0]
    if x == y:
        res.append(res[-1])
    else:
        if x > y:
            x, y = y, x
        res.append(res[-1] - nodes[x][2] * nodes[y][2])
        nodes[x][1] += nodes[y][1]
        nodes[x][2] += nodes[y][2]
        for z in nodes[x][1]:
            nodes[z][0] = x
print(*reversed(res[:-1]), sep='\n')

Fixed submission:
n, m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(m)]

parents = list(range(n + 1))
ranks = [0 for _ in range(n + 1)]


def find(x):
    if parents[x] == x:
        return x
    parents[x] = find(parents[x])
    return parents[x]


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    if ranks[x] < ranks[y]:
        parents[x] = y
    else:
        parents[y] = x
        if ranks[x] == ranks[y]:
            ranks[x] += 1


res = [n * (n - 1) // 2]
nums = [1 for _ in range(n + 1)]
for a, b in reversed(ls):
    aa = find(a)
    bb = find(b)
    if aa == bb:
        res.append(res[-1])
    else:
        res.append(res[-1] - nums[aa] * nums[bb])
        nums[aa] = nums[bb] = nums[aa] + nums[bb]
        unite(aa, bb)
print(*reversed(res[:-1]), sep='\n')