qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys

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

WA = [0] * N
isAC = [False] * N

for _ in range(M):
	p, S = input().split()
	if S == "AC":
		isAC[int(p) - 1] = True
	elif not isAC[int(p) - 1]:
		WA += 1

ACsum, WAsum = 0, 0
for i in range(N):
	if isAC[i]:
		ACsum += 1
		WAsum += WA[i]

print(ACsum, WAsum)

Fixed code:
import sys

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

WA = [0] * N
isAC = [False] * N

for _ in range(M):
	p, S = input().split()
	if S == "AC":
		isAC[int(p) - 1] = True
	elif not isAC[int(p) - 1]:
		WA[int(p) - 1] += 1

ACsum, WAsum = 0, 0
for i in range(N):
	if isAC[i]:
		ACsum += 1
		WAsum += WA[i]

print(ACsum, WAsum)
Buggy code:
N, M = map(int,input().split())
AC_Set = set()
WA_Dict = {}
WA_SUM = 0
for i in range(M):
    num,result = list(input().split())
    if num in AC_Set:
        continue
    else:
        if result == "AC":
            AC_Set.add(num)
            WA_SUM += WA_Dict.get(num)
        else:
            WA_Dict[num] = WA_Dict.get(num,0) + 1

print("{} {}".format(len(AC_Set),WA_SUM))


Fixed code:
N, M = map(int,input().split())
AC_Set = set()
WA_Dict = {}
WA_SUM = 0
for i in range(M):
    num,result = list(input().split())
    if num in AC_Set:
        continue
    else:
        if result == "AC":
            AC_Set.add(num)
            WA_SUM += WA_Dict.get(num,0)
        else:
            WA_Dict[num] = WA_Dict.get(num,0) + 1

print("{} {}".format(len(AC_Set),WA_SUM))
Buggy code:
N, M = map(int, input().split())
count = [0]*N
ans = 0
ok = 1
for _ in range(M):
    p, s = input().split()
    if count[int(p)-1] >= 0 and s == "WA":
        count[int(p) - 1] += 1
    elif count[int(p)-1] >= 0 and s == "AC":
        ans += count[int(p)-1]
        count[int(p)-1] = -1
        ok += 1
print(ok, ans)

Fixed code:
N, M = map(int, input().split())
count = [0]*N
ans = 0
ok = 0
for _ in range(M):
    p, s = input().split()
    if count[int(p)-1] >= 0 and s == "WA":
        count[int(p) - 1] += 1
    elif count[int(p)-1] >= 0 and s == "AC":
        ans += count[int(p)-1]
        count[int(p)-1] = -1
        ok += 1
print(ok, ans)
Buggy code:
N,M = map(int,input().split())
AC = 0
penalty = 0
AC_list = [0]*N
WA_list = [0]*N

for i in range(M):
  p,s = map(str,input().split())
  p = int(p-1)
  if s == "AC" and AC_list[p] == 0:
    AC += 1
    AC_list[p] = 1
    penalty += WA_list[p]
  elif s == "WA":
    WA_list[p] += 1
  if AC == N:
    break
print(AC,penalty)

Fixed code:
N,M = map(int,input().split())
AC = 0
penalty = 0
AC_list = [0]*N
WA_list = [0]*N

for i in range(M):
  p,s = map(str,input().split())
  p = int(p)-1
  if s == "AC" and AC_list[p] == 0:
    AC += 1
    AC_list[p] = 1
    penalty += WA_list[p]
  elif s == "WA":
    WA_list[p] += 1
  if AC == N:
    break
print(AC,penalty)
Buggy code:
n, m = map( int, input().split())

ac = [False] * n
wa = [0] * n

for i in range( m ):
  p = input().split()
  prob_no =int( p[ 0 ])
  if p[ 1 ] == "WA":
    wa[ prob_no - 1 ] += 1
  else:
    ac[ prob_no - 1 ] = True

wa_cnt = 0
for i in range( n ):
  if ac[ i ]:
    wa_cnt += wa[ i ]
ac_cnt = sum( ac )

print( ac_cnt, wa_cnt )

Fixed code:
n, m = map( int, input().split())

ac = [False] * n
wa = [0] * n

for i in range( m ):
  p = input().split()
  prob_no =int( p[ 0 ])
  if p[ 1 ] == "WA":
    if not ac[ prob_no - 1 ]:
      wa[ prob_no - 1 ] += 1
  else:
    ac[ prob_no - 1 ] = True

wa_cnt = 0
for i in range( n ):
  if ac[ i ]:
    wa_cnt += wa[ i ]
ac_cnt = sum( ac )

print( ac_cnt, wa_cnt )
Buggy code:
n,m=map(int,input().split())

N=[[0,0]*n]
co=0
pe=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=='WA':
        N[p-1][0]+=1
    elif N[p-1][1]!=1:
        pe+=N[p-1][0]
        co+=1
        N[p-1][1]=1

print(str(co)+' '+str(pe))

Fixed code:
n,m=map(int,input().split())

N=[]

for i in range(n):
    N.append([0,0])

co=0
pe=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=='WA':
        N[p-1][0]+=1
    elif N[p-1][1]!=1:
        pe+=N[p-1][0]
        co+=1
        N[p-1][1]=1

print(str(co)+' '+str(pe))
Buggy code:

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

AC = 0
WA = 0


was = [0]*(N+1)
acs = [0]*(N+1)

for i in range(M):
	p,s = input().split()
	p = int(p)

	if s = "AC":
		if acs[p] == 0:
			AC += 1
			WA += was[p]
			acs[p] = 1
	else:
		was[p] += 1

print(AC,WA)

Fixed code:

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

AC = 0
WA = 0


was = [0]*(N+1)
acs = [0]*(N+1)

for i in range(M):
	p,s = input().split()
	p = int(p)

	if s == "AC":

		if acs[p] == 0:

			AC += 1
			WA += was[p]
			acs[p] = 1
			
	else:
		was[p] += 1

print(AC,WA)
Buggy code:
#C
N,M=map(int,input().split())
re=[0 for i in range(N+1)]
P=[0 for i in range(N+1)]
x=0
y=0
for i in range(M):
    p,S=input().split()
    p=int(p)
    if re[p]=="AC":
        continue
    elif S=="WA":
        P[p]+=1
    elif S=="AC":
        re[p]="AC"
        y+=1
for i in range(1,N+1):
    if re[p]=="AC":
        x+=P[p]
print(y,x)

Fixed code:
#C
N,M=map(int,input().split())
re=[0 for i in range(N+1)]
P=[0 for i in range(N+1)]
x=0
y=0
for i in range(M):
    p,S=input().split()
    p=int(p)
    if re[p]=="AC":
        continue
    elif S=="WA":
        P[p]+=1
    elif S=="AC":
        re[p]="AC"
        y+=1
for i in range(1,N+1):
    if re[i]=="AC":
        x+=P[i]
print(y,x)
Buggy code:
N,M = map(int,input().split(" "))
L = [0] * M
for i in range(M):
  L(i) = input().split(" ")

memoAC = [0]*N
memoWA = [0]*N
for list in L:
  if list[1]=="AC":
    memoAC[int(list[0])]=1
  else:
    if memoAC[int(list[0])]!=1:
      memoWA[int(list)[0]]+=1
      
AC = sum(memoAC)
WA = sum(memoWA)
print(AC,WA)

Fixed code:
N,M = map(int,input().split(" "))
L = [0] * M
for i in range(M):
    L[i] = input().split(" ")
    
memoAC = [0] * N
memoWA = [0] * N
for list in L:
    if list[1] == "AC":
        memoAC[int(list[0])-1] = 1
    else:
        if memoAC[int(list[0])-1] != 1:
            memoWA[int(list[0])-1] += 1

for j in range(N):
    if memoAC[j] == 0:
        memoWA[j] = 0

AC = sum(memoAC)
WA = sum(memoWA)
print(AC,WA)
Buggy code:
def main():
    N, M = map(int, input().split())
    cnt = 0
    answer_list = [[] for _ in range(N)]
    for i in range(M):
        p, S = input().split()
        p = int(p) - 1
        answer_list[p].append(S)

    ac = 0
    wa = 0
    for answers in answer_list:
        for a in answers:
            tmp_wa = 0
            if a == 'AC':
                ac += 1
                wa += tmp_wa
                break
            else:
                tmp_wa += 1
    
    print(ac, wa)

    

if __name__ == "__main__":
    main()

Fixed code:
def main():
    N, M = map(int, input().split())
    cnt = 0
    answer_list = [[] for _ in range(N)]
    for i in range(M):
        p, S = input().split()
        p = int(p) - 1
        answer_list[p].append(S)

    ac = 0
    wa = 0
    for answers in answer_list:
        tmp_wa = 0
        for a in answers:
            if a == 'AC':
                ac += 1
                wa += tmp_wa
                break
            else:
                tmp_wa += 1
    
    print(ac, wa)

    

if __name__ == "__main__":
    main()
Buggy code:
N,M = map(int,input().split())
AC = 0
WA = 0
lis = [0] * N
for i in range(M):
  a,b = map(input().split())
  if lis[int(a)-1] < 0:
    pass
  elif b == 'AC'
    WA += lis[int(a)-1]
    AC += 1
    lis[int(a)-1] = -1
  else:
    lis[int(a)-1] += 1
print(AC, WA)

Fixed code:
N,M = map(int,input().split())
AC = 0
WA = 0
lis = [0] * N
for i in range(M):
  a,b = input().split()
  if lis[int(a)-1] < 0:
    pass
  elif b == 'AC':
    WA += lis[int(a)-1]
    AC += 1
    lis[int(a)-1] = -1
  else:
    lis[int(a)-1] += 1
print(AC, WA)
Buggy code:
N, M = map(int, input().split())
p = [0] * M
S = ['a'] * M
for i in range(M):
    p[i], S[i] = input().split()
    p[i] = int(p[i])

ansac = answa = pen = 0
flg = [0] * N

for i in range(M):
    if flg[p[i]-1] == 1:
        continue
    if S[i] == 'WA':
        answa += 1
    elif S[i] == 'AC':
        ansac += 1
        pen += answa
        flg[p[i]-1] = 1

print(ansac, pen)


Fixed code:
N, M = map(int, input().split())
p = [0] * M
S = ['a'] * M
for i in range(M):
    p[i], S[i] = input().split()
    p[i] = int(p[i])

ansac = pen = 0
answa = [0] * N
flg = [0] * N

for i in range(M):
    if flg[p[i]-1] == 1:
        continue
    if S[i] == 'WA':
        answa[p[i]-1] += 1
    elif S[i] == 'AC':
        ansac += 1
        pen += answa[p[i]-1]
        flg[p[i]-1] = 1

print(ansac, pen)
Buggy code:
N,M = map(int, input().split())
A = {}
C = 0
P = 0
for i in range(M):
    p,S = map(str, input().split())
    if S == 'AC' and A.get(p+S) is None:
        A[p+S] = 0
        C += 1
    elif S == 'WA' and A.get(p+'AC') is None and A.get(p+S) is None:
        A[p+S] = 1
    elif S == 'WA' and A.get(p+'AC') is None:
        A[p+S] += 1
for i in range(1,N+1):
    if A.get(str(i)+'AC') is not None:
        P += A[str(i)+'WA']
print(C,P)

Fixed code:
N,M = map(int, input().split())
A = {}
C = 0
P = 0
for i in range(M):
    p,S = map(str, input().split())
    if S == 'AC' and A.get(p+S) is None:
        A[p+S] = 0
        C += 1
    elif S == 'WA' and A.get(p+'AC') is None and A.get(p+S) is None:
        A[p+S] = 1
    elif S == 'WA' and A.get(p+'AC') is None:
        A[p+S] += 1
for i in range(1,N+1):
    if A.get(str(i)+'AC') is not None and A.get(str(i)+'WA') is not None:
        P += A[str(i)+'WA']
print(C,P)
Buggy code:
import sys
N, M, *PS = sys.stdin.read().strip().split()
N = int(N)
ac = [0] * N
wa = [0] * N
for p, s in zip(*[iter(PS)] * 2):
  p = int(p) - 1
  if s == "AC":
    ac[p] = 1
  elif ac[p] == 0:
    wa[p] += 1
penalties = sum(w * a else 0 for a, w in zip(ac, wa))
print(sum(ac), penalties)

Fixed code:
import sys
N, M, *PS = sys.stdin.read().strip().split()
N = int(N)
ac = [0] * N
wa = [0] * N
for p, s in zip(*[iter(PS)] * 2):
  p = int(p) - 1
  if s == "AC":
    ac[p] = 1
  elif ac[p] == 0:
    wa[p] += 1
penalties = sum(w if a > 0 else 0 for a, w in zip(ac, wa))
print(sum(ac), penalties)
Buggy code:
import sys
N, M, *PS = sys.stdin.read().strip().split()
N = int(N)
ac = [0] * N
wa = [0] * N
for p, s in zip(*[iter(PS)] * 2):
  p = int(p) -1
  if s == "AC":
    ac[p] = 1
  elif ac[p] == 0:
    wa[p] += 1
penalties = sum([w or a for a, w in zip(ac, wa)])
print("{} {}".format(sum(ac),penalties)

Fixed code:
import sys
N, M, *PS = sys.stdin.read().strip().split()
N = int(N)
ac = [0] * N
wa = [0] * N
for p, s in zip(*[iter(PS)] * 2):
  p = int(p) - 1
  if s == "AC":
    ac[p] = 1
  elif ac[p] == 0:
    wa[p] += 1
penalties = sum([w * a for a, w in zip(ac, wa)])
print("{} {}".format(sum(ac), penalties))
Buggy code:
from sys import stdin
input = stdin.readline
N, M = map(int, input().split())
ac = [False] * N
wa = [0] * N
wa_cnt = 0
for i in range(M):
  p, s = input().split()
  p = int(p) - 1
  if ac[p] is False and s == "AC":
    wa_cnt += 1
    ac[p] = True
  elif s == "WA":
    wa[p] += 1
print(ac.count(True), wa_cnt)

Fixed code:
from sys import stdin
input = stdin.readline
N, M = map(int, input().split())
ac = [False] * N
wa = [0] * N
wa_cnt = 0
for i in range(M):
  p, s = input().split()
  p = int(p) - 1
  if ac[p] is False and s == "AC":
    wa_cnt += wa[p]
    ac[p] = True
  elif s == "WA":
    wa[p] += 1
print(ac.count(True), wa_cnt)
Buggy code:
N, M = list(map(int, input().split()))
results =[ input().split(" ") for i in range(M) ]

acc = [ False ] * N
pena = [ 0 ] * N 
for p, S in results:
  p = int(p) - 1
  if acc[p] < 1 and p <= N:
    acc[p] = True if S == 'AC' else False 
    pena[p] = pena[p] + 1 if S == 'WA' else pena[p] 

wa = 0
for i in range(N):
  wa += pena[i] if acc is True else 0
    
print(sum(acc), wa)



Fixed code:
N, M = list(map(int, input().split()))
results =[ input().split(" ") for i in range(M) ]

acc = [ False ] * N
pena = [ 0 ] * N 
for p, S in results:
  p = int(p) - 1
  if acc[p] is False:
    acc[p] = True if S == 'AC' else False 
    pena[p] = pena[p] + 1 if S == 'WA' else pena[p] 

wa = 0
for i in range(N):
  wa += pena[i] if acc[i] is True else 0
    
print(sum(acc), wa)
Buggy code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = [list(input().split()) for i in range(m)]

for i in range(m):
    A[i][0] = int(A[i][0])

P = [0] * n
AC = [0] * n

for i in range(m):
    if A[i][1] == "WA":
        if AC[A[i][0]] == 0:
            P[A[i][0]] += 1
    else:
        AC[A[i][0]] = 1
    
p=0
ac=sum(AC)
for i in range(len(P)):
    if AC[i] == 1:
        p += P[i]
print(ac,p)

Fixed code:
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
A = [list(input().split()) for i in range(m)]

for i in range(m):
    A[i][0] = int(A[i][0])-1

P = [0] * n
AC = [0] * n

for i in range(m):
    if A[i][1] == "WA":
        if AC[A[i][0]] == 0:
            P[A[i][0]] += 1
    else:
        AC[A[i][0]] = 1
    
p=0
ac=sum(AC)
for i in range(len(P)):
    if AC[i] == 1:
        p += P[i]
print(ac,p)
Buggy code:
N,M=map(int,input().split())
number=[0]*N
ac,wa=0,0
for m in range(M):
    p,s=input().split()
    if number!=-1:
        if s == "AC":
             ac+=1
             number[int(p)-1]=-1
        else:
            wa+=1
print(ac,wa)

Fixed code:
N,M=map(int,input().split())
number=[0]*N
ac,wa,=0,0
for m in range(M):
    p,s=input().split()
    p=int(p)-1
    if number[p]!=-1:
        if s == "WA":
            number[p]+=1
        elif s == "AC":
            ac+=1
            wa+=number[p]
            number[p] = -1
print(ac,wa)
Buggy code:
N,M=map(int,input().split())
P=[input().split() for i in range(M)]

WA=[]
AC=[]
for i in range(N):
    WA.append(0)
    AC.append(0)

for i in range(M):
    if P[i][1]=="WA" and  AC[int(P[i][0])-1]==0:
        WA[int(P[i][0])-1]+=1
    elif P[i][1]=="AC":
        WA[int(P[i][0])-1]=0
        AC[int(P[i][0])-1]=1

print(sum(AC),sum(WA))


Fixed code:
N,M=map(int,input().split())
P=[input().split() for i in range(M)]

WA=[]
AC=[]
for i in range(N):
    WA.append(0)
    AC.append(0)

for i in range(M):
    if P[i][1]=="WA" and  AC[int(P[i][0])-1]==0:
        WA[int(P[i][0])-1]+=1
    elif P[i][1]=="AC":
        AC[int(P[i][0])-1]=1
for i in range(N):
    if AC[i]==0:
        WA[i]=0

print(sum(AC),sum(WA))
Buggy code:
ABC151 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict
n,m=map(int, input().split())
ac=set()
ac_cnt=0
wa_cnt=0
d_ac=defaultdict(int)
d_wa=defaultdict(int)
for i in range(m):
    p,s=nm()
    if s=='AC':
        if int(p) in ac:
            continue
        ac.add(int(p))
        ac_cnt+=1
    elif s=='WA':
        if int(p) in ac:
            continue
        d_wa[p]+=1
 
for a in ac:
    wa_cnt+=d_wa[str(a)]
 
print(ac_cnt,wa_cnt)

Fixed code:
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict
n,m=map(int, input().split())
ac=set()
ac_cnt=0
wa_cnt=0
d_ac=defaultdict(int)
d_wa=defaultdict(int)
for i in range(m):
    p,s=nm()
    if s=='AC':
        if int(p) in ac:
            continue
        ac.add(int(p))
        ac_cnt+=1
    elif s=='WA':
        if int(p) in ac:
            continue
        d_wa[p]+=1
 
for a in ac:
    wa_cnt+=d_wa[str(a)]
 
print(ac_cnt,wa_cnt)
Buggy code:
n, m = map(int, input().split())
WA = [0] * n
AC = [0] * n

for i in range(m):
    p, s = map(str, input().split())
    p = int(p) - 1
    if s == "AC":
        AC[p] = 1
    elif s == "WA" and AC[p] == 0:
        WA[p] += 1

WA = [WA[i] for i in range(m) if AC[i] >= 1]

print(sum(AC), sum(WA))

Fixed code:
n, m = map(int, input().split())
WA = [0] * n
AC = [0] * n

for i in range(m):
    p, s = map(str, input().split())
    p = int(p) - 1
    if s == "AC":
        AC[p] = 1
    elif s == "WA" and AC[p] == 0:
        WA[p] += 1

for i in range(n):
    WA[i] = 0 if AC[i] == 0 else WA[i]

print(sum(AC), sum(WA))
Buggy code:
N,M=map(int,input().split())
keep=[]
lis=[]
ac=[0]*M
wa=[0]*M
WA=0
for i in range(M):
    ps=input().split()
    keep.append(ps)
    
for j in range(M):
    if keep[j][1]=="AC":
        ac[int(keep[j][0])]=1
    elif ac[int(keep[j][0])]==0:
        wa[int(keep[j][0])]+=1
AC=sum(ac)
for j in range(M):
    WA+=ac[j]*wa[j]
    
print(AC,WA)

Fixed code:
N,M=map(int,input().split())
keep=[]
lis=[]
ac=[0]*N
wa=[0]*N
WA=0
for i in range(M):
    ps=input().split()
    keep.append(ps)
    
for j in range(M):
    if keep[j][1]=="AC":
        ac[int(keep[j][0])-1]=1
    elif ac[int(keep[j][0])-1]==0:
        wa[int(keep[j][0])-1]+=1
AC=sum(ac)
for k in range(N):
    WA+=ac[k]*wa[k]
    
print(AC,WA)
Buggy code:
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
#mondaisuu
N = Line[0]
#teisyutu
M = Line[1]

AC_Lists = [""]*N
# print(AC_Lists)

for i in range(M):
    input_line = input()
    Line = input_line.split()
    print(Line)
    AC_Lists[int(Line[0])-1] += Line[1][0]
    print(AC_Lists)

AC_count = 0
WA_count = 0

for s in AC_Lists:
    # print(s)
    if 'A' in s:
        AC_count += 1
        my_str = s.split("A")
        print(my_str)
        # print(len(my_str[0]))
        WA_count += len(my_str[0])
    else:
        # print(len(s))
        WA_count += len(s)
# print(AC_Lists)

print(AC_count,WA_count)


Fixed code:
input_line = input()
Line = input_line.split()
Line = [int(s) for s in Line]
#mondaisuu
N = Line[0]
#teisyutu
M = Line[1]
 
AC_Lists = [""]*N
# print(AC_Lists)
 
for i in range(M):
    input_line = input()
    Line = input_line.split()
    # print(AC_Lists[int(Line[0])-1])
    AC_Lists[int(Line[0])-1] += Line[1][0]
 
AC_count = 0
WA_count = 0
 
for s in AC_Lists:
    # print(s)
    if 'A' in s:
        AC_count += 1
        my_str = s.split("A")
        # print(my_str)
        # print(len(my_str[0]))
        WA_count += len(my_str[0])
    # else:
    #     print(len(s))
    #     WA_count += len(s)
# print(AC_Lists)
 
print(AC_count,WA_count)
Buggy code:
from collections import deque

h,w = map(int,input().split())
maze=[]

for _ in range(h):
    maze.append(input())

ans = 0

move = [[1,0],[-1,0],[0,1],[0,-1]]

for i in range(h):
    for j in range(w):
        if(maze[i][j]=="."):
            dist = [[999999]*w for _ in range(h)]
            
            dq = deque()
            y=i
            x=j
            d=0
            
            dq.append((y,x,d))
            
            while(len(dq)):
                
                y,x,d = dq.popleft()
                dist[y][x]=d
                for m in move:
                    if((0<=x+m[0]<w) and (0<=y+m[1]<h)):
                        if(dist[y+m[1]][x+m[0]] > d+1):
                            if(maze[y+m[1]][x+m[0]] == "."):
                                dq.append((y+m[1],x+m[0],d+1))
                                
            # ans = max(ans,d)
            print(d,i,j)
print(ans)


Fixed code:
from collections import deque

h,w = map(int,input().split())
maze = []

for _ in range(h):
    maze.append(input())

ans = 0

move = [[1,0],[-1,0],[0,1],[0,-1]]

for i in range(h):
    for j in range(w):
        if(maze[i][j]=="."):
            dist = [ [99999999]*w for _ in range(h) ]
            
            dq = deque()
            y=i
            x=j
            d=0
            dist[y][x]=0
            dq.append((y,x,d))
            
            while(len(dq)):
                
                y,x,d = dq.popleft()
                
                for m in move:
                    if((0<=x+m[0]<w) and (0<=y+m[1]<h) and
                        (dist[y+m[1]][x+m[0]] > d+1) and
                            (maze[y+m[1]][x+m[0]] == ".")):
                                dist[y+m[1]][x+m[0]]=d+1
                                dq.append((y+m[1],x+m[0],d+1))
                                
            ans = max(ans,d)
            # print(d,i,j)
print(ans)
Buggy code:
H,W = map(int,input().split())
maze = [list(input()) for j in range(H)]

def bfs(h,w):
  checked = [[False for i in range(W)] for j in range(H)]
  q = [(h,w,0)] if maze[h][w]=="." else []
  g_n = 0
  while q:
    h_,w_,n = q.pop(0)
    g_n = max(n, g_n)
    for i,j in zip([0,0,-1,1],[-1,1,0,0]):
      if (0<=h_+i<H) and (0<=w_+j<W):
        if checked[h_+i][w_+j]: continue
        checked[h_+i][w_+j] = True
        if maze[pt[0]][pt[1]]==".": q.append((h_+i,w_+j,n+1))
  return g_n

n = 0
for i in range(H):
  for j in range(W):
    n = max(n, bfs(i,j))
print(n)

Fixed code:
H,W = map(int,input().split())
maze = [list(input()) for j in range(H)]

def bfs(h,w):
  checked = [[False for i in range(W)] for j in range(H)]
  q = [(h,w,0)] if maze[h][w]=="." else []
  checked[h][w] = True
  g_n = 0
  while q:
    h_,w_,n = q.pop(0)
    g_n = max(n, g_n)
    for i,j in zip([0,0,-1,1],[-1,1,0,0]):
      if (0<=h_+i<H) and (0<=w_+j<W):
        if checked[h_+i][w_+j]: continue
        checked[h_+i][w_+j] = True
        if maze[h_+i][w_+j]==".": q.append((h_+i,w_+j,n+1))
  return g_n

n = 0
for i in range(H):
  for j in range(W):
    n = max(n, bfs(i,j))
print(n)
Buggy code:
H, W = map(int, input().split())
S = [input().split() for _ in range(H)]

from collections import deque

def bfs(sy, sx):
    q = deque([[sy, sx]])
    visited = [[-1]*W for _ in range(H)]
    visited[sy][sx] = 0
    while q:
        y, x = q.popleft()
        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+i, x+j
            if not 0 <= new_y < H or not 0 <= new_x < W:
                continue
            if S[new_y][new_x] ==  "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x]+1
                q.append([new_y, new_x])
    return max(max(l) for l in visited)

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, bfs(i, j))
print (ans)

Fixed code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]

from collections import deque

def bfs(sy, sx):
    q = deque([[sy, sx]])
    visited = [[-1]*W for _ in range(H)]
    visited[sy][sx] = 0
    while q:
        y, x = q.popleft()
        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y+i, x+j
            if not 0 <= new_y < H or not 0 <= new_x < W:
                continue
            if S[new_y][new_x] ==  "." and visited[new_y][new_x] == -1:
                visited[new_y][new_x] = visited[y][x]+1
                q.append([new_y, new_x])
    return max(max(l) for l in visited)

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, bfs(i, j))
print (ans)