Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [0] * N
for _ in range(M):
    a = int(input())
    dp[a-1] = -1

k = 1000000007


for i in range(N):
    if dp[i] == -1:
        dp[i] = 0
        continue
    if i == 0:
        dp[i] = 1
        continue
    if i == 1:
        dp[i] = dp[i-1] + 1
        continue

    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= k



print(n)


Fixed submission:
N, M = map(int, input().split())
dp = [0] * N
for _ in range(M):
    a = int(input())
    dp[a-1] = -1

k = 1000000007


for i in range(N):
    if dp[i] == -1:
        dp[i] = 0
        continue
    if i == 0:
        dp[i] = 1
        continue
    if i == 1:
        dp[i] = dp[i-1] + 1
        continue

    dp[i] = dp[i-1] + dp[i-2]

n = dp[-1] % k

print(n)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [0] * N
for _ in range(M):
    a = int(input())
    dp[a-1] = -1

k = 1000000007


for i in range(N):
    if dp[i] == -1:
        dp[i] = 0
        continue
    if i == 0:
        dp[i] = 1
        continue
    if i == 1:
        dp[i] = dp[i-1] + 1
        continue

    dp[i] = dp[i-1] + dp[i-2]
    dp[i] /= k



print(n)


Fixed submission:
N, M = map(int, input().split())
dp = [0] * N
for _ in range(M):
    a = int(input())
    dp[a-1] = -1

k = 1000000007


for i in range(N):
    if dp[i] == -1:
        dp[i] = 0
        continue
    if i == 0:
        dp[i] = 1
        continue
    if i == 1:
        dp[i] = dp[i-1] + 1
        continue

    dp[i] = dp[i-1] + dp[i-2]

n = dp[-1] % k

print(n)

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
dp = [0] * N
for _ in range(M):
    a = int(input())
    dp[a-1] = -1

k = 1000000007

if dp[0] == 0 and dp[1] == 0:
    dp[0] = 1
    dp[1] = 2

if dp[0] == -1 and dp[1] == 0:
    dp[0] = 0
    dp[1] = 1


if dp[0] == 0 and dp[1] == -1:
    dp[0] = 1
    dp[1] = 0


if dp[0] == -1 and dp[1] == -1:
    dp[0] = 0
    dp[1] = 0


for i in range(2, N):
    if dp[i] == -1:
        dp[i] = 0
        continue
    dp[i] = dp[i-1] + dp[i-2]

n = dp[-1] % k

print(n)


Fixed submission:
N, M = map(int, input().split())
dp = [0] * N
for _ in range(M):
    a = int(input())
    dp[a-1] = -1

k = 1000000007


for i in range(N):
    if dp[i] == -1:
        dp[i] = 0
        continue
    if i == 0:
        dp[i] = 1
        continue
    if i == 1:
        dp[i] = dp[i-1] + 1
        continue

    dp[i] = dp[i-1] + dp[i-2]

n = dp[-1] % k

print(n)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

P, Y = [], []
dic = {}
for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)
    if p in dic:
        dic[p].append(y)
    else:
        dic[p] = [y]

result = []
for n in range(M):
    result.append(1)
    if not P[n] in dic:
        continue
    for i in range(n):
        if P[n] == P[i]:
            if Y[n] > Y[i]:
                result[n] += 1
            else:
                result[i] += 1


for x, y in zip(P, result):
    x, y = str(x), str(y)
    print('0'*(6-len(x))+x+'0'*(6-len(y))+y)


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

P, Y = [], []
for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)

result = [1] * M
citys = [[] for _ in range(N)]

for i, n in enumerate(P):
    citys[n-1].append([Y[i], i])

for c in citys:
    
    c.sort()
    for i, k in enumerate(c):
        result[k[1]] += i



for x, y in zip(P, result):
    x, y = str(x), str(y)
    print('0'*(6-len(x))+x+'0'*(6-len(y))+y)

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())

P, Y = [], []
for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)

result = []
for n in range(M):
    result.append(1)
    for i in range(n):
        if P[n] == P[i]:
            if Y[n] > Y[i]:
                result[n] += 1
            else:
                result[i] += 1


for x, y in zip(P, result):
    x, y = str(x), str(y)
    print('0'*(6-len(x))+x+'0'*(6-len(y))+y)


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

P, Y = [], []
for _ in range(M):
    p, y = map(int, input().split())
    P.append(p)
    Y.append(y)

result = [1] * M
citys = [[] for _ in range(N)]

for i, n in enumerate(P):
    citys[n-1].append([Y[i], i])

for c in citys:
    
    c.sort()
    for i, k in enumerate(c):
        result[k[1]] += i



for x, y in zip(P, result):
    x, y = str(x), str(y)
    print('0'*(6-len(x))+x+'0'*(6-len(y))+y)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]
if 0 in A:
	print("-1")
	exit(0)
ans = 1
lim = 10**18
for a in A:
	ans *= a
    if ans > lim:
      print("-1")
      exit(0)
print(ans)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]
if 0 in A:
  print("0")
  exit(0)
ans = 1
lim = 10**18
for a in A:
  ans *= a
  if ans > lim:
    print("-1")
    exit(0)
print(ans)
Buggy python submission (verdict: Runtime Error):
from copy import copy
from functool import reduce

class Sunkune:
	def __init__(self):
  		self.has_snack = False

n_sunuke, n_v_snacks = [int(s) for s in input().split(2)]

all_sunuke = [copy(Sunuke()) for i in range(n_sunuke)]

for snack_id in n_v_snacks:
  	n_snacks = int(input())
    for sunuke_id in (int(s) for s in input().split()):
    	all_sunuke[s - 1].has_snack = True

print(reduce(lambda n,s: n + (0 if s.has_snack else 1), all_sunuke, 0)

Fixed submission:
from copy import copy
from functools import reduce
    
class Sunuke:
    def __init__(self):
        self.has_snack = False
    
n_sunuke, n_v_snacks = [int(s) for s in input().split()]
    
all_sunuke = [copy(Sunuke()) for i in range(n_sunuke)]
    
for snack_id in range(n_v_snacks):
    n_snacks = int(input())
    for sunuke_id in (int(s) for s in input().split()):
        all_sunuke[sunuke_id - 1].has_snack = True
    
print(reduce(lambda n,s: n + (0 if s.has_snack else 1), all_sunuke, 0))
Buggy python submission (verdict: Runtime Error):
n = int(input())
top_val = 0
top_idx = set()
semi_top = 0

for i in range(n):
  a = int(input())
  if a > top_val:
    semi_top = top_val
    top_val = a
    top_idx.clear()
    top_idx.add(i)
  elif a == top_val:
    top_idx.add(i)

if len(top_idx) > 1:
  semi_top = top_val

print("\n".join([semi_top if i in top_idx else top_val for i in range(n)]))

Fixed submission:
n = int(input())
top_val = 0
top_idx = set()
semi_top = 0

for i in range(n):
  a = int(input())
  if a > top_val:
    semi_top = top_val
    top_val = a
    top_idx.clear()
    top_idx.add(i)
  elif a == top_val:
    top_idx.add(i)
  elif a > semi_top:
    semi_top = a

if len(top_idx) > 1:
  semi_top = top_val

semi_top = str(semi_top)
top_val = str(top_val)

print("\n".join([semi_top if i in top_idx else top_val for i in range(n)]))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
g = [set() for i in range(n)]
visited = [False] * n
group = []

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

for i in range(n):
    if visited[i]:
        continue
    s = set()
    q = [i]
    while len(q) > 0:
        p = q.pop()
        visited[p] = True
        s.add(p)
        for x in g[p]:
            if visited[x]:
                continue
            q.append(x)
    group.append(s)

ans = 0
for x in group:
    ans = max(ans, len(x))
print(ans)

Fixed submission:
n,m = map(int,input().split())
g = [set() for i in range(n)]
visited = [False] * n
group = []

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

for i in range(n):
    if visited[i]:
        continue
    s = set()
    q = [i]
    while len(q) > 0:
        p = q.pop()
        visited[p] = True
        s.add(p)
        for x in g[p]:
            if visited[x]:
                continue
            q.append(x)
    group.append(s)

ans = 0
for x in group:
    ans = max(ans, len(x))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
p = list(map(int,input().split()))
for i in range(n):
    p[i] -= 1
c = list(map(int,input().split()))
if max(c) <= 0:
    print(max(c))
    exit()
ans = 0
for begin in range(n):
    i = p[begin]
    s = c[i]
    round = 1
    score = 0
    kk = 0
    while i != begin:
        i = p[i]
        s += c[i]
        round += 1
    if k < round:
        kk = k
    else:
        if s > 0:
            score += s * (k // round)
            kk = k % round
        else:
            kk = round
    smax = 0
    now = 0
    i = begin
    while kk > 0:
        i = p[i]
        now += c[i]
        smax = max(now, smax)
        kk -= 1
    roundmax = 0
    if k // round >= 1 and s > 0:
        kk = round
        now = 0
        i = begin
        while kk > 0:
            i = p[i]
            now += c[i]
            roundmax = max(now, roundmax)
            kk -= 1
        ans = max(ans, score-s+roundmax, score+smax)
    else:
        ans = max(ans, score + smax)

print(ans)

Fixed submission:
n,k = map(int,input().split())
p = list(map(int,input().split()))
for i in range(n):
    p[i] -= 1
c = list(map(int,input().split()))
if max(c) <= 0:
    print(max(c))
    exit()
ans = 0
for begin in range(n):
    i = p[begin]
    s = c[i]
    round = 1
    score = 0
    kk = 0
    while i != begin:
        i = p[i]
        s += c[i]
        round += 1
    if k < round:
        kk = k
    else:
        if s > 0:
            score += s * (k // round)
            kk = k % round
        else:
            kk = round
    smax = 0
    now = 0
    i = begin
    while kk > 0:
        i = p[i]
        now += c[i]
        smax = max(now, smax)
        kk -= 1
    roundmax = 0
    if k // round >= 1 and s > 0:
        kk = round
        now = 0
        i = begin
        while kk > 0:
            i = p[i]
            now += c[i]
            roundmax = max(now, roundmax)
            kk -= 1
        ans = max(ans, score-s+roundmax, score+smax)
    else:
        ans = max(ans, score + smax)

print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
print(10 - n // 200)

Fixed submission:
n = int(input())
print(10 - n // 200)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
s = input()
sur = []
n = len(s)
p = 2019
ans = 0
for i in range(n-1, -1, -1):
    sur += [int(s[i:]) % p]

d = defaultdict(int)
for x in sur:
    d[x] += 1

for k,v in d.items():
    if k == 0:
        ans += v * (v+1) // 2
    else:
        ans += v * (v-1) // 2
print(ans)

Fixed submission:
from collections import defaultdict
s = input()
n = len(s)
p = 2019
sur1 = [int(s[0]) % p]
sur2 = [int(s[-1]) % p]
sur10 = [1 % p]
for i in range(n - 1):
    sur1 += [(sur1[i] * 10 + int(s[i + 1])) % p]
    sur10 += [(sur10[i] * 10) % p]
    sur2 += [(sur2[i] + sur10[i + 1] * int(s[-i - 2])) % p]

ans = 0
d = defaultdict(int)
for x in sur2:
    d[x] += 1

for k, v in d.items():
    if k == 0:
        ans += v * (v + 1) // 2
    else:
        ans += v * (v - 1) // 2
print(ans)
Buggy python submission (verdict: Runtime Error):
n, x, y = map(int,input().split())
dist = [0] * (n-1)
x -= 1
y -= 1
for i in range(n):
  for j in range(i+1, n):
    if (i <= x and j <= x) or (x <= i <= y and x <= j <= y) or (y <= i and y <= j):
      dist[j-i] += 1
    elif i <= x and y <= j:
      dist[j-i-(y-x)+1] += 1
    elif i <= x and x <= j <= y:
      dist[x-i + min(j-x, y-j+1)] += 1
    else:
      dist[j-y + min(y-j, j-x+1)] += 1
for d in dist:
  print(d)

Fixed submission:
n, x, y = map(int,input().split())
dist = [0] * n
x -= 1
y -= 1
for i in range(n):
  for j in range(i+1, n):
    dist[min(j-i, abs(x-i)+abs(y-j)+1, abs(y-i)+abs(x-j)+1)] += 1
for d in dist[1:]:
  print(d)
Buggy python submission (verdict: Time Limit Exceeded):
x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())), reverse=True)
q = sorted(list(map(int,input().split())), reverse=True)
r = sorted(list(map(int,input().split())), reverse=True)
pq = sorted(p[:x] + q[:y])
ans = sum(pq)
i = 0
while i < min(a+b, c):
  if r[i] <= pq[i]:
    break
  ans += r[i] - pq[i]
print(ans)

Fixed submission:
x,y,a,b,c = map(int,input().split())
p = sorted(list(map(int,input().split())), reverse=True)
q = sorted(list(map(int,input().split())), reverse=True)
r = sorted(list(map(int,input().split())), reverse=True)
pq = sorted(p[:x] + q[:y])
ans = sum(pq)
i = 0
while i < min(a+b, c):
  if r[i] <= pq[i]:
    break
  ans += r[i] - pq[i]
  i += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
print(pow(int(input) / 3, 3))

Fixed submission:
print(pow(int(input()) / 3, 3))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
for x in a:
  c = d[x] - 1
  print(c * (c-1) // 2)a

Fixed submission:
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
d = defaultdict(int)
for x in a:
  d[x] += 1
  
s = 0
for k,v in d.items():
  s += v * (v-1) // 2
for x in a:
  c = d[x] - 1
  print(s - c)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
n,p = map(int,input().split())
s = input()

ans = 0
if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
    exit()

sur = []
for i in range(n-1, -1, -1):
    sur += [int(s[i:]) % p]

d = defaultdict(int)
for x in sur:
    d[x] += 1

for k,v in d.items():
    if k == 0:
        ans += v * (v+1) // 2
    else:
        ans += v * (v-1) // 2
print(ans)

Fixed submission:
from collections import defaultdict
n,p = map(int,input().split())
s = input()

sur1 = [int(s[0]) % p]
sur2 = [int(s[-1]) % p]
sur10 = [1 % p]
for i in range(n-1):
    sur1 += [(sur1[i] * 10 + int(s[i+1])) % p]
    sur10 += [(sur10[i] * 10) % p]
    sur2 += [(sur2[i] + sur10[i+1] * int(s[-i-2])) % p]

ans = 0
if p == 2:
    for i in range(n):
        if int(s[i]) % 2 == 0:
            ans += i + 1
    print(ans)
    exit()

if p == 5:
    for i in range(n):
        if int(s[i]) % 5 == 0:
            ans += i + 1
    print(ans)
    exit()

d = defaultdict(int)
for x in sur2:
    d[x] += 1

for k,v in d.items():
    if k == 0:
        ans += v * (v+1) // 2
    else:
        ans += v * (v-1) // 2
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,p = map(int,input().split())
s = input()

sur1 = [int(s[0]) % p]
sur2 = [int(s[-1]) % p]
sur10 = [1 % p]
for i in range(n-1):
    sur1 += [(sur1[i] * 10 + int(s[i+1])) % p]
    sur10 += [(sur10[i] * 10) % p]
    sur2 += [(sur2[i] + sur10[i+1] * int(s[-i-2])) % p]

ans = 0
for i in range(n):
    for j in range(i,n):
        if i == 0:
            if sur1[j] == 0:
                ans += 1
        elif j == n-1:
            if sur2[n-i-1] == 0:
                ans += 1
        elif (sur1[j] - sur10[j-i+1] * sur1[i-1]) % p == 0:
            ans += 1
print(ans)

Fixed submission:
from collections import defaultdict
n,p = map(int,input().split())
s = input()

sur1 = [int(s[0]) % p]
sur2 = [int(s[-1]) % p]
sur10 = [1 % p]
for i in range(n-1):
    sur1 += [(sur1[i] * 10 + int(s[i+1])) % p]
    sur10 += [(sur10[i] * 10) % p]
    sur2 += [(sur2[i] + sur10[i+1] * int(s[-i-2])) % p]

ans = 0
if p == 2:
    for i in range(n):
        if int(s[i]) % 2 == 0:
            ans += i + 1
    print(ans)
    exit()

if p == 5:
    for i in range(n):
        if int(s[i]) % 5 == 0:
            ans += i + 1
    print(ans)
    exit()

d = defaultdict(int)
for x in sur2:
    d[x] += 1

for k,v in d.items():
    if k == 0:
        ans += v * (v+1) // 2
    else:
        ans += v * (v-1) // 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b = map(int,input().split())
mod = 10**9 + 7
ans = pow(2,n,mod) - 1
fact = [1]
finv = [1]
for i in range(1, n+1):
    fact += [(fact[i-1] * i) % mod]
    finv += [pow(fact[i], mod-2, mod)]
print((ans - (fact[n]*finv[n-a]*finv[a]) % mod - (fact[n]*finv[n-b]*finv[b]) % mod) % mod)

Fixed submission:
n,a,b = map(int,input().split())
mod = 10**9 + 7
ans = pow(2,n,mod) - 1
fa = 1
fb = 1
for i in range(1, a+1):
    fa *= i
    fa %= mod
for i in range(1, b+1):
    fb *= i
    fb %= mod

fa = pow(fa, mod-2, mod)
fb = pow(fb, mod-2, mod)

for i in range(a):
    fa *= n - i
    fa %= mod
for i in range(b):
    fb *= n - i
    fb %= mod

print((ans - fa - fb) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
n,a,b = map(int,input().split())
mod = 10**9 + 7
ans = pow(2,n,mod) - 1
fact = [1]
finv = [1]
for i in range(1, n+1):
    fact += [(fact[i-1] * i) % mod]
    finv += [pow(fact[i], mod-2, mod)]
print((ans - (fact[n]*finv[n-a]*finv[a]) % mod - (fact[n]*finv[n-b]*finv[b]) % mod) % mod)

Fixed submission:
n,a,b = map(int,input().split())
mod = 10**9 + 7
ans = pow(2,n,mod) - 1
fa = 1
fb = 1
for i in range(1, a+1):
    fa *= i
    fa %= mod
for i in range(1, b+1):
    fb *= i
    fb %= mod

fa = pow(fa, mod-2, mod)
fb = pow(fb, mod-2, mod)

for i in range(a):
    fa *= n - i
    fa %= mod
for i in range(b):
    fb *= n - i
    fb %= mod

print((ans - fa - fb) % mod)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
mod = 10**9 + 7

fact = [1]
finv = [1]
for i in range(1, 2*n):
    fact.append((fact[i-1] * i) % mod)
    finv.append(pow(fact[i], mod-2, mod))

if n-1 <= k:
    print((fact[2*n-1] * finv[n] * finv[n-1]) % mod)

ans = 0
for i in range(k+1):
    ans += fact[n] * finv[n-i] * finv[i] * fact[n-1] * finv[n-1-i] * finv[i]
    ans %= mod

print(ans)

Fixed submission:
n,k = map(int,input().split())
mod = 10**9 + 7

fact = [1]
finv = [1]
for i in range(1, 2*n):
    fact.append((fact[i-1] * i) % mod)
    finv.append(pow(fact[i], mod-2, mod))

if n-1 <= k:
    print((fact[2*n-1] * finv[n] * finv[n-1]) % mod)
    exit()

ans = 0
for i in range(k+1):
    ans += fact[n] * finv[n-i] * finv[i] * fact[n-1] * finv[n-1-i] * finv[i]
    ans %= mod

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = {}
for i in range(n):
  s = input()
  d[s] = 1 if not s in d else d[s] += 1

ans = []
c = max(d.values())
for k,v in d.items():
  if v == c:
    ans += [k]
for x in sorted(ans):
  print(x)

Fixed submission:
n = int(input())
d = dict()
for i in range(n):
    s = input()
    if not s in d:
        d[s] = 1
    else:
        d[s] += 1

ans = []
c = max(d.values())
for k, v in d.items():
    if v == c:
        ans += [k]
for x in sorted(ans):
    print(x)
Buggy python submission (verdict: Runtime Error):
h = int(input())
ans = 1
h //= 2
i = 2
while h > 0:
    ans += i
    i *= 2
    h //= 2
print(ans)
pow(2,n)-1

Fixed submission:
h = int(input())
ans = 1
h //= 2
i = 2
while h > 0:
    ans += i
    i *= 2
    h //= 2
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = []
v = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(h):
    s += [input()]
ans = 0


def dfs(d, i, j, c):
    if i < 0 or h <= i or j < 0 or w <= j:
        return
    if s[i][j] == '#' or d[i][j] <= c:
        return

    d[i][j] = c
    for y,x in v:
        dfs(d, i+y, j+x, c+1)


for i in range(h*w): 
    for j in range(h*w):
        d = [[h * w] * w for i in range(h)]
        p = (i // w, i % w)
        q = (j // w, j % w)
        if s[p[0]][p[1]] == '#' or s[q[0]][q[1]] == '#':
            continue
        dfs(d, p[0], p[1], 0)
        if d[q[0]][q[1]] < h*w:
            ans = max(d[q[0]][q[1]], ans)

print(ans)

Fixed submission:
import queue
h,w = map(int,input().split())
v = [(1, 0), (0, 1), (-1, 0), (0, -1)]
s = [input() for i in range(h)]

ans = 0
que = queue.Queue()
for i in range(h * w):
    c = 0
    d = [[h*w] * w for i in range(h)]
    p = (i//w, i%w)
    if s[p[0]][p[1]] == '#':
        continue
    d[p[0]][p[1]] = 0
    que.put(p)
    while not que.empty():
        y,x = que.get()
        c = d[y][x]
        for dy, dx in v:
            yy = y + dy
            xx = x + dx
            if yy < 0 or xx < 0 or h <= yy or w <= xx:
                continue
            if s[yy][xx] == '#':
                continue
            if d[yy][xx] < h*w:
                continue
            que.put((yy, xx))
            d[yy][xx] = c + 1
    ans = max(ans, c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = []
v = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(h):
    s += [input()]
ans = 0


def dfs(d, i, j, c):
    if i < 0 or h <= i or j < 0 or w <= j:
        return
    if s[i][j] == '#' or d[i][j] <= c:
        return

    d[i][j] = c
    for y,x in v:
        dfs(d, i+y, j+x, c+1)


for i in range(h*w):
    for j in range(h*w):
        d = [[h * w] * w for i in range(h)]
        p = (i // w, i % w)
        q = (j // w, j % w)
        if s[p[0]][p[1]] == '#' or s[q[0]][q[1]] == '#':
            continue
        dfs(d, p[0], p[1], 0)
        if d[q[0]][q[1]] < h*w:
            ans = max(d[q[0]][q[1]], ans)

print(ans)

Fixed submission:
import queue
h,w = map(int,input().split())
v = [(1, 0), (0, 1), (-1, 0), (0, -1)]
s = [input() for i in range(h)]

ans = 0
que = queue.Queue()
for i in range(h * w):
    c = 0
    d = [[h*w] * w for i in range(h)]
    p = (i//w, i%w)
    if s[p[0]][p[1]] == '#':
        continue
    d[p[0]][p[1]] = 0
    que.put(p)
    while not que.empty():
        y,x = que.get()
        c = d[y][x]
        for dy, dx in v:
            yy = y + dy
            xx = x + dx
            if yy < 0 or xx < 0 or h <= yy or w <= xx:
                continue
            if s[yy][xx] == '#':
                continue
            if d[yy][xx] < h*w:
                continue
            que.put((yy, xx))
            d[yy][xx] = c + 1
    ans = max(ans, c)
print(ans)
Buggy python submission (verdict: Runtime Error):
x = int(input())
primes = []
n = 2

def is_prime(num):
  for p in primes:
    if num % p == 0:
      return False
  return True

while true:
  if is_prime(n):
    if n >= x:
      print(n)
      exit()
    else:
      primes.append(n)
  n += 1
  

Fixed submission:
x = int(input())
primes = []
n = 2


def is_prime(num):
    for p in primes:
        if num % p == 0:
            return False
        if p * p > num:
            return True
    return True


while True:
    if is_prime(n):
        if n >= x:
            print(n)
            exit()
        else:
            primes.append(n)
    n += 1
Buggy python submission (verdict: Runtime Error):
a = list(int,input().split())
if sum(a) >= 22:
  print('bust')
else:
  print('win')

Fixed submission:
a = list(map(int,input().split()))
if sum(a) >= 22:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Runtime Error):
n = int(input())
d = [dict()] * n
for i in range(n):
  a = int(input())
  for j in range(a):
    x,y = map(int,input().split())
    d[i][x-1] = y
ans = 0

def count_honest(bits):
  count = 0
  vec = [-1] * n
  for j in range(n):
    honest = (bits >> j) | 1
    count += honest
    for k,v in d[j]:
      v = v if honest else (v+1) % 2
      if vec[k] == -1:
        vec[k] = v
      elif vec[k] != v:
        return 0
  return count
  
for i in range(2**n):
  ans = max(ans, count_honest(i))


Fixed submission:
n = int(input())
d = [dict() for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        d[i][x - 1] = y

def count_honest(bits):
    honest = [(bits >> i) & 1 for i in range(n)]
    for i in range(n):
        if not honest[i]:
            continue
        for k, v in d[i].items():
            if honest[k] != v:
                return 0
    return sum(honest)


print(max([count_honest(i) for i in range(2**n)]))