Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
from collections import deque

N, Q = map(int, input().split())
nodes = np.array([0]*(N+1))
subtree_flag = [False]*(N+1)
subtree = np.array([[0]*(N+1) for i in range(N+1)])
tree = [set() for _ in range(N+1)]

for i in range(1, N):
  a, b = map(int, input().split())
  tree[a].add(b)

def add(p, x):
  dq = deque()
  dq.append(p)
  subtree[p][p] = 1
  while len(dq) > 0:
    tp = dq.popleft()
    nodes[tp] += x
    subtree[p][tp] = 1
    for np in tree[tp]:
      dq.append(np)

for i in range(Q):
  p, x = map(int, input().split())
  if subtree_flag[p]:
     nodes += subtree[p] * x
  else:
    add(p, x)
    subtree_flag[p]=True
print(" ".join([str(i) for i in nodes[1:]]))

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

for i in range(N-1):
  a, b = map(int, input().split())
  tree[a-1].extend([b])

nodes = [0]*N
for _ in range(Q):
  p, x = map(int, input().split())
  nodes[p-1]+=x

for i in range(N-1):
  for j in tree[i]:
    nodes[j-1]+=nodes[i]
print(" ".join(list(map(str, nodes))))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, Q = map(int, input().split())
nodes = [0]*(N+1)
tree = [set() for _ in range(N+1)]
subtree = [set() for _ in range(N+1)]

for i in range(1, N):
  a, b = map(int, input().split())
  tree[a].add(b)

def add(p, x):
  dq = deque()
  dq.append(p)
  subtree[p] = {p}
  while len(dq) > 0:
    tp = dq.popleft()
    nodes[tp] += x
    for np in tree[tp]:
      dq.append(np)
      subtree[p].add(np)

for i in range(Q):
  p, x = map(int, input().split())
  if subtree[p]:
    for j in subtree[p]:
      nodes[j] += x
  else:
    add(p, x)
print(" ".join([str(i) for i in nodes[1:]]))

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

for i in range(N-1):
  a, b = map(int, input().split())
  tree[a-1].extend([b])

nodes = [0]*N
for _ in range(Q):
  p, x = map(int, input().split())
  nodes[p-1]+=x

for i in range(N-1):
  for j in tree[i]:
    nodes[j-1]+=nodes[i]
print(" ".join(list(map(str, nodes))))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
N, Q = map(int, input().split())
nodes = [0]*(N+1)
tree = [set() for _ in range(N+1)]
for i in range(1, N):
  a, b = map(int, input().split())
  tree[a].add(b)

def add(p, x):
  dq = deque()
  dq.append(p)
  while len(dq) > 0:
    p = dq.popleft()
    nodes[p] += x
    for np in tree[p]:
      dq.append(np)

for i in range(Q):
  p, x = map(int, input().split())
  add(p, x)
print(" ".join([str(i) for i in nodes[1:]]))

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

for i in range(N-1):
  a, b = map(int, input().split())
  tree[a-1].extend([b])

nodes = [0]*N
for _ in range(Q):
  p, x = map(int, input().split())
  nodes[p-1]+=x

for i in range(N-1):
  for j in tree[i]:
    nodes[j-1]+=nodes[i]
print(" ".join(list(map(str, nodes))))
Buggy python submission (verdict: Runtime Error):
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += cmb(v, 2)
      # count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

Fixed submission:
N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
# from math import factorial

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += len(list(itertools.combinations(range(v), 2)))
      # count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

Fixed submission:
N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)

Buggy python submission (verdict: Runtime Error):
from math import factorial

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

Fixed submission:
N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
words_list = []
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  words_list.append(''.join(ss))
count = 0
for i in range(len(words_list)):
  for j in range(i+1, len(words_list)):
    if words_list[i] == words_list[j]:
      count += 1
print(count)

Fixed submission:
N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
date = []
salary = []
for _ in range(N):
  a, b = map(int, input().split())
  date.append(a)
  salary.append(b)
sum_salary = 0
for i in range(1, M+1):
  max_salary = 0
  index = -1
  for j in range(len(date)):
      if date[j] <= i:
        if max_salary < salary[j]:
          max_salary = salary[j]
          index = j
  sum_salary += max_salary
  if index >= 0:
    date.pop(index)
    salary.pop(index)
print(sum_salary)

Fixed submission:
import heapq

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

for i in range(N):
  a, b = map(int, input().split())
  if a > M:
    continue
  jobs[M-a].append(b)
sum_salary = 0
h=[]
for i in range(M-1, -1, -1):
  for b in jobs[i]:
    heapq.heappush(h,-b)
  if(len(h)!=0):
    a = -heapq.heappop(h)
    sum_salary += a
print(sum_salary)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int, input().split()))
index_list = []
value_list = []
for i in range(1, n+1):
  if i != p[i-1]:
    index_list.append(i)
    value_list.append(p[i-1])
if len(index_list) == 0:
  print("YES")
elif len(index_list) == 2 and value_list[0] == index_list[1] and value_list[1] == index_list[0]:
  print("YES")
else:
  print("NO"

Fixed submission:
n = int(input())
p = list(map(int, input().split()))
index_list = []
value_list = []
for i in range(1, n+1):
  if i != p[i-1]:
    index_list.append(i)
    value_list.append(p[i-1])
if len(index_list) == 0:
  print("YES")
elif len(index_list) == 2 and value_list[0] == index_list[1] and value_list[1] == index_list[0]:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
N, A, B = map(int, input().split())
if N*A > B:
  print(B)
else:
  print(N*A

Fixed submission:
N, A, B = map(int, input().split())
if N*A > B:
  print(B)
else:
  print(N*A)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
L, R = list(map(int, input().split()))

min_val = 2019
for i in range(L, R):
  for j in range(i+1, R+1):
    val = (i*j)%2019
    if min_val > val:
      min_val = val
      if min_val == 0:
        break
print(min_val)

Fixed submission:
import numpy as np
L, R = list(map(int, input().split()))

min_val = 2019
for i in range(L, R):
  for j in range(i+1, R+1):
    val = (i*j)%2019
    if min_val > val:
      min_val = val
      if min_val == 0:
        break
  if min_val == 0:
    break
print(min_val)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
L, R = map(int, input().split())

min_val = 2019
for i in range(L, R):
  for j in range(i+1, R+1):
    val = np.mod(i*j, 2019)
    if min_val > val:
      min_val = val
print(min_val)

Fixed submission:
import numpy as np
L, R = list(map(int, input().split()))

min_val = 2019
for i in range(L, R):
  for j in range(i+1, R+1):
    val = (i*j)%2019
    if min_val > val:
      min_val = val
      if min_val == 0:
        break
  if min_val == 0:
    break
print(min_val)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
tmp = A[0]
for i in range(1, N):
  if i % 2 == 0:
    tmp = tmp + A[i]
  else:
    tmp = tmp - A[i]
X = [tmp]*N
print_str = str(tmp)
for i in range(0, N-1):
  X[i+1] = (A[i] - X[i] // 2) * 2
  print_str = print_str + " " + str(X[i+1])
print(print_str)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
tmp = A[0]

for i in range(1, N):
  if i % 2 == 0:
    tmp = tmp + A[i]
  else:
    tmp = tmp - A[i]
X = [tmp]*N
for i in range(0, N-1):
  X[i+1] = (A[i] - X[i] // 2) * 2
print(" ".join(list(map(str, X))))
Buggy python submission (verdict: Runtime Error):
import math

N, K = map(int, input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

for i in range(1, K+1):
  print((combinations_count(N-K+1, i) * combinations_count(K-1, i-1)) % (10**9 + 7))

Fixed submission:
import math

N, K = map(int, input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

for i in range(1, K+1):
  if N - K + 1 < i:
    print(0)
  else:
    print((combinations_count(N-K+1, i) * combinations_count(K-1, i-1)) % (10**9 + 7))

Buggy python submission (verdict: Runtime Error):
import math

N, K = map(int, input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

print(combinations_count(N-K+1, 1))
for i in range(2, K):
  print(combinations_count(N-K+1, 1) * permutations_count(N-K, i-1) % (10**9 + 7))
print(combinations_count(N-K+1, K) % (10**9 + 7))

Fixed submission:
import math

N, K = map(int, input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

for i in range(1, K+1):
  if N - K + 1 < i:
    print(0)
  else:
    print((combinations_count(N-K+1, i) * combinations_count(K-1, i-1)) % (10**9 + 7))
Buggy python submission (verdict: Runtime Error):
str_dict = [0, 0, 0] 
val1 = 0
for i in range(int(input())):
  line = input()
  val1 += line.count('AB')
  if line[0] == 'B' and line[-1] == 'A':
    str_dict[2] += 1
  elif line[0] == 'B':
    str_dict[0] += 1
  elif line[-1] == 'A':
    str_dict[1] += 1
# if str_dict[2] == 0:
#   print(val1+min(str_dict[0], str_dict[1]))
# else:
#   if str_dict[0]+str_dict[1] > 0:
#     print(val1+str_dict[2]+min(str_dict[0], str_dict[1]))
#   else:
#     print(val1+str_dict[2]-1)
val2 = min(str_dict[0], str_dict[1])
tmp = max(str_dict[0]-val2, str_dict[1]-val2)
val3 = min(tmp, str_dict[2])
val4 = str_dict[2]-val3
if val3 == 0:
  val4 -= 1
print(val1+val2+val3+val4)

Fixed submission:
R, G, B, N = map(int, input().split())
count = 0
for r in range(0, N+1, R):
  for g in range(0, N+1-r, G):
    val = (N - r - g)
    if val % B == 0 and val >= 0:
      count += 1
print(count)

Buggy python submission (verdict: Runtime Error):
R, G, B, N = map(int, input().split())
count = 0
for r in range(0, N+1, R):
  for g in range(0, N+1 - r, G):
    val = (N - r - g)
    if val % B == 0 and val >= 0:
      count += 1
print(count

Fixed submission:
R, G, B, N = map(int, input().split())
count = 0
for r in range(0, N+1, R):
  for g in range(0, N+1-r, G):
    val = (N - r - g)
    if val % B == 0 and val >= 0:
      count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())
count = 0
for r in range(0, N+1, R):
  for g in range(0, N+1, G):
    val = (N - r - g)
    if val % B == 0 and val >= 0:
      count += 1
print(count)

Fixed submission:
R, G, B, N = map(int, input().split())
count = 0
for r in range(0, N+1, R):
  for g in range(0, N+1-r, G):
    val = (N - r - g)
    if val % B == 0 and val >= 0:
      count += 1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
r, g, b, n = map(int, input().split())
count = 0
for ri in range(0, n+1, r):
  for gi in range(0, n+1, g):
    val = (n - ri - gi) / b
    if val.is_integer() and val >= 0:
      count += 1
print(count)

Fixed submission:
R, G, B, N = map(int, input().split())
count = 0
for r in range(0, N+1, R):
  for g in range(0, N+1-r, G):
    val = (N - r - g)
    if val % B == 0 and val >= 0:
      count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
str_dict = [0, 0, 0] 
val1 = 0
for i in range(int(input())):
  line = input()
  val1 += line.count('AB')
  if line[0] == 'B' and line[-1] == 'A':
    str_dict[2] += 1
  elif line[0] == 'B':
    str_dict[0] += 1
  elif line[-1] == 'A':
    str_dict[1] += 1
val2 = min(str_dict[0], str_dict[1])
tmp = max(str_dict[0]-val2, str_dict[1]-val2)
val3 = min(tmp, str_dict[2])
val4 = str_dict[2]-val3
if val4 % 2 == 1:
  val4 -= 1
print(val1+val2+val3+val4

Fixed submission:
str_dict = [0, 0, 0] 
val1 = 0
for i in range(int(input())):
  line = input()
  val1 += line.count('AB')
  if line[0] == 'B' and line[-1] == 'A':
    str_dict[2] += 1
  elif line[0] == 'B':
    str_dict[0] += 1
  elif line[-1] == 'A':
    str_dict[1] += 1
if str_dict[2] == 0:
  print(val1+min(str_dict[0], str_dict[1]))
else:
  if str_dict[0]+str_dict[1] > 0:
    print(val1+str_dict[2]+min(str_dict[0], str_dict[1]))
  else:
    print(val1+str_dict[2]-1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
v = map(int, input().split())
c = map(int, input().split())
max_val = 0
for _v, _c in zip(v, c):
  if _v - _c > 0:
    max_val += _v - _c
print(max_val

Fixed submission:
n = int(input())
v = map(int, input().split())
c = map(int, input().split())
max_val = 0
for _v, _c in zip(v, c):
  if _v - _c > 0:
    max_val += _v - _c
print(max_val)
Buggy python submission (verdict: Runtime Error):
import sys

inf = sys.maxsize
N, K = map(int, input().split())
heights = list(map(int, input().split()))

dp = [inf]*N
dp[0] = 0


def chmin(a, b, diff):
    if dp[a] > dp[b] + diff:
        dp[a] = dp[b] + diff
    return


for i in range(N):
    for j in range(1, K+1):
        if i-j >= 0:
            chmin(i, i-j, abs(heights[i]-heights[i-j]))

print(dp[N-1])

Fixed submission:
import sys

inf = sys.maxsize

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

# DPテーブルの初期化(最小問題なのでINFで初期化
dp = [inf] * N

# 初期条件
dp[0] = 0


def chmin(a, b, diff):
    if dp[a] > dp[b]+diff:
        dp[a] = dp[b]+diff
        return True
    return False

# 普通のDP
for i in range(1, N):
    chmin(i, i-1, abs(heights[i]-heights[i-1]))
    if i > 1:
        chmin(i, i-2, abs(heights[i]-heights[i-2]))
print(dp[N-1])


# # メモ化再帰
# def chmin(a, b):
#     if a > b:
#         a = b
#     return a
#
#
# def rec(i):
#     if dp[i] < inf:
#         return dp[i]
#     if i == 0:
#         return 0
#     res = inf
#     res = chmin(res, rec(i-1)+abs(heights[i]-heights[i-1]))
#     if i > 1:
#         res = chmin(res, rec(i-2)+abs(heights[i]-heights[i-2]))
#     dp[i] = res
#     return dp[i]
#
#
# print(rec(N-1))

Buggy python submission (verdict: Runtime Error):
import sys

inf = sys.maxsize

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

# DPテーブルの初期化(最小問題なのでINFで初期化
dp = [inf] * N

# 初期条件
dp[0] = 0


# def chmin(a, b, diff):
#     if dp[a] > dp[b]+diff:
#         dp[a] = dp[b]+diff
#         return True
#     return False

# # 普通のDP
# for i in range(1, N):
#     chmin(i, i-1, abs(heights[i]-heights[i-1]))
#     if i > 1:
#         chmin(i, i-2, abs(heights[i]-heights[i-2]))
# print(dp[N-1])


# メモ化再帰
def chmin(a, b):
    if a > b:
        a = b
    return a


def rec(i):
    if dp[i] < inf:
        return dp[i]
    if i == 0:
        return 0
    res = inf
    res = chmin(res, rec(i-1)+abs(heights[i]-heights[i-1]))
    if i > 1:
        res = chmin(res, rec(i-2)+abs(heights[i]-heights[i-2]))
    dp[i] = res
    return dp[i]


print(rec(N-1))

Fixed submission:
import sys

inf = sys.maxsize

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

# DPテーブルの初期化(最小問題なのでINFで初期化
dp = [inf] * N

# 初期条件
dp[0] = 0


def chmin(a, b, diff):
    if dp[a] > dp[b]+diff:
        dp[a] = dp[b]+diff
        return True
    return False

# 普通のDP
for i in range(1, N):
    chmin(i, i-1, abs(heights[i]-heights[i-1]))
    if i > 1:
        chmin(i, i-2, abs(heights[i]-heights[i-2]))
print(dp[N-1])


# # メモ化再帰
# def chmin(a, b):
#     if a > b:
#         a = b
#     return a
#
#
# def rec(i):
#     if dp[i] < inf:
#         return dp[i]
#     if i == 0:
#         return 0
#     res = inf
#     res = chmin(res, rec(i-1)+abs(heights[i]-heights[i-1]))
#     if i > 1:
#         res = chmin(res, rec(i-2)+abs(heights[i]-heights[i-2]))
#     dp[i] = res
#     return dp[i]
#
#
# print(rec(N-1))
Buggy python submission (verdict: Time Limit Exceeded):
import sys

inf = sys.maxsize
N, K = map(int, input().split())
heights = list(map(int, input().split()))

dp = [inf]*N
dp[0] = 0


def chmin(a, b, diff):
    if dp[a] > dp[b] + diff:
        dp[a] = dp[b] + diff
    return


for i in range(N):
    for j in range(1, K+1):
        if i-j >= 0:
            chmin(i, i-j, abs(heights[i]-heights[i-j]))

print(dp[N-1])

Fixed submission:
import sys

inf = sys.maxsize
N, K = map(int, input().split())
heights = list(map(int, input().split()))

dp = [inf]*N
dp[0] = 0


def chmin(a, b, diff):
    if dp[a] > dp[b] + diff:
        dp[a] = dp[b] + diff
    return


for i in range(N):
    for j in range(1, K+1):
        if i-j >= 0:
            chmin(i, i-j, abs(heights[i]-heights[i-j]))

print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
import copy

N, M = map(int, input().split())
reqs = []
for _ in range(M):
    a, b = map(int, input().split())
    reqs.append((a, b))

count = 0
while len(reqs) > 0:
    copied_req = copy.deepcopy(reqs)
    _, idx = map(min, zip(*copied_req))
    for req in reqs:
        if req[0] < idx:
            copied_req.remove(req)
    count += 1
    reqs = copied_req
print(count)

Fixed submission:
N, M = map(int, input().split())
reqs = []
ans = 0
B = 0
for _ in range(M):
    a, b = map(int, input().split())
    reqs.append((a, b))
reqs = sorted(reqs, key=lambda x: x[1])
for i in range(M):
    a, b = reqs[i]
    if a >= B:
        B = b
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from collections import deque
import copy

H, W = map(int, input().split())
s=(0,0)
g=(H-1,W-1)
maze = [list(input()) for line in range(H)]
copied_maze = copy.deepcopy(maze)

def search(x, y):
  dq = deque()
  dq.append([x, y])
  copied_maze[x][y] = 0
  while len(dq) > 0:
    x,y = dq.popleft()
    if x==g[0] and y==g[1]:
      break
    for dx, dy in [[1,0], [0,1], [-1,0], [0,-1]]:
      nx,ny=[x+dx,y+dy]
      if 0 <= nx < H and 0 <= ny < W and copied_maze[nx][ny] != '#' and type(copied_maze[nx][ny]) is str:
        dq.append([nx,ny])
        copied_maze[nx][ny] = copied_maze[x][y]+1
search(s[0],s[1])
x,y=g
cost = copied_maze[g[0]][g[1]]
path = {s, g}
for i in range(copied_maze[g[0]][g[1]]):
  for dx, dy in [[1,0], [0,1], [-1,0], [0,-1]]:
    nx,ny=[x+dx,y+dy]
    if 0 <= nx < H and 0 <= ny < W and copied_maze[nx][ny] == cost - 1:
      path.add((nx,ny))
      x,y=nx,ny
      cost -= 1
      break
count = 0
for i in range(H):
  for j in range(W):
    if maze[i][j] == '.' and (i, j) not in path:
      count += 1
print(count)

Fixed submission:
from collections import deque
import copy

H, W = map(int, input().split())
s=(0,0)
g=(H-1,W-1)
maze = [list(input()) for line in range(H)]
copied_maze = copy.deepcopy(maze)

def search(x, y):
  dq = deque()
  dq.append([x, y])
  copied_maze[x][y] = 0
  while len(dq) > 0:
    x,y = dq.popleft()
    if x==g[0] and y==g[1]:
      break
    for dx, dy in [[1,0], [0,1], [-1,0], [0,-1]]:
      nx,ny=[x+dx,y+dy]
      if 0 <= nx < H and 0 <= ny < W and copied_maze[nx][ny] != '#' and type(copied_maze[nx][ny]) is str:
        dq.append([nx,ny])
        copied_maze[nx][ny] = copied_maze[x][y]+1
search(s[0],s[1])
x,y=g
cost = copied_maze[g[0]][g[1]]
if type(cost) is str:
  print(-1)
  exit()
path = {s, g}
for i in range(copied_maze[g[0]][g[1]]):
  for dx, dy in [[1,0], [0,1], [-1,0], [0,-1]]:
    nx,ny=[x+dx,y+dy]
    if 0 <= nx < H and 0 <= ny < W and copied_maze[nx][ny] == cost - 1:
      path.add((nx,ny))
      x,y=nx,ny
      cost -= 1
      break
count = 0
for i in range(H):
  for j in range(W):
    if maze[i][j] == '.' and (i, j) not in path:
      count += 1
print(count)
Buggy python submission (verdict: Runtime Error):
N, Y = map(int, input().split())
out_x = out_y = out_z = -1
for x in range(N+1):
  for y in range(N+1):
    price = x * 10000 + y * 5000
    if price > Y:
      break
    price = price + (N-x-y) * 1000
    if price == Y:
      out_x = x
      out_y = y
      out_z = N-x-y
      break
  if out_x != -1:
    break
print(f"{out_x} {out_y} {out_z}")

Fixed submission:
n, y = map(int, input().split())
found = False
for i in range(n+1):
  for j in range(n+1-i):
    if i + j+ (n-i-j) == n and 10000*i+5000*j+1000*(n-i-j) == y:
        print(i, j, n-i-j)
        found = True
        break
  else:
    continue
  break 
if not found:
  print("-1 -1 -1")

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
n, y = map(int, input().split())
found = False
for i in product(range(n+1),repeat=3):
  if sum(i) == n and 10000*i[0]+5000*i[1]+1000*i[2] == y:
    print(i[0], i[1], i[2])
    found = True
    break
if not found:
  print("-1 -1 -1")

Fixed submission:
n, y = map(int, input().split())
found = False
for i in range(n+1):
  for j in range(n+1-i):
    if i + j+ (n-i-j) == n and 10000*i+5000*j+1000*(n-i-j) == y:
        print(i, j, n-i-j)
        found = True
        break
  else:
    continue
  break 
if not found:
  print("-1 -1 -1")
Buggy python submission (verdict: Runtime Error):
n=int(input())
data=list(map(int, input().split()))
count = 0
while(True):
  data = list(filter(lambda x: x%2==0, data))
  if len(data) < n:
    print(count)
    break
  else:
    count+=1

Fixed submission:
ret = list(filter(lambda x: x==1, map(int, list(input()))))
print(len(ret))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
data=list(map(int, input().split()))
count = 0
while(True):
  data = list(filter(lambda x: x%2==0, data))
  if len(data) < n:
    print(count)
    break
  else:
    count+=1

Fixed submission:
n=int(input())
data=list(map(int, input().split()))
for i in range( max(data)):
  even_data = list(filter(lambda x: x%2==0, data))
  if len(even_data) < n:
    print(i)
    break
  data = list(map( lambda x: x / 2,  data))