Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
a=input()
b=input()

int(a)
int(b)

if a*b%2 ==0:
    print('Even')
else:
    print('Odd')

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


if (a*b)%2 ==0:
    print('Even')
else:
    print('Odd')

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

c=int(a)*int(b)

if c%2 ==0:
    print('Even')
else:
    print('Odd')

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


if (a*b)%2 ==0:
    print('Even')
else:
    print('Odd')

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


if (int(a)*int(b))%2 ==0:
    print('Even')
else:
    print('Odd')


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


if (a*b)%2 ==0:
    print('Even')
else:
    print('Odd')
Buggy python submission (verdict: Runtime Error):




#他人のコピー
n=input()
n = int(input())
candy = (1 / 2) * n * (n + 1)
print(int(candy))
#他人のコピー




Fixed submission:




#他人のコピー
n=input()
candy = (1 / 2) * int(n) * (int(n) + 1)
print(int(candy))
#他人のコピー
Buggy python submission (verdict: Runtime Error):
n = input()
if n[-3] == 0:
  print(0)
else:
  print((10-int(n[-3]))**100)

Fixed submission:
n = int(input())
if n%1000 == 0:
    print(0)
else:
    print(1000-n%1000)
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

cnt = 0
for i in range():
    if s[i] != t[i]:
        cnt += 1

print(cnt)        


Fixed submission:
s = input()
t = input()

cnt = 0
for i in range(len(s)):
    if s[i] != t[i]:
        cnt += 1

print(cnt)
Buggy python submission (verdict: Runtime Error):
n,k = int(input())
p = list(map(int,input().split()))

p.sort()
ans = 0
for i in range(k):
  ans += p[i]
print(ans)

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

p.sort()
ans = 0
for i in range(k):
  ans += p[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
x,n = map(int,input().split())
if n != 0:
    p = list(map(int,input().split()))

    num = []
    for i in range(1,100):
        num.append(abs(x-i))

    for i in range(n):
        num[p[i]-1] = 1000

    min = 1000
    ansnum = 0
    for i in range(len(num)):
        if min > num[i]:
            min = num[i]
            ansnum = i

    print(ansnum+1)
else:
    print(x)

Fixed submission:
x,n = map(int,input().split())
if n != 0:
    p = list(map(int,input().split()))

    num = []
    for i in range(-49,150):
        num.append(abs(x-i))

    for i in range(n):
        num[p[i]+49] = 1000

    min = 1000
    ansnum = -49
    for i in range(len(num)):
        if min > num[i]:
            min = num[i]
            ansnum = i-50

    print(ansnum+1)
else:
    print(x)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

ans = 1
for i in range(len(a)):
    ans *= a[i]
    if ans > 10**18:
  	  print(-1)
      exit()

print(ans)


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

for i in range(len(a)):
    if a[i] == 0:
        print(0)
        exit()

ans = 1
for i in range(len(a)):
  ans *= a[i]
  if ans > 10**18:
    print(-1)
    exit()

print(ans)

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

ans = 1
for i in range(len(a)):
    ans *= a[i]
    
if ans > 10**18:
  print(-1)
  exit()
  
print(ans)


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

for i in range(len(a)):
    if a[i] == 0:
        print(0)
        exit()

ans = 1
for i in range(len(a)):
  ans *= a[i]
  if ans > 10**18:
    print(-1)
    exit()

print(ans)

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

ans = 1
for i in range(len(a)):
	if ans > 10**18:
    	print(-1)
        exit()
    else:
    	ans *= a[i]
if ans > 10**18:
	print(-1)
    exit()
print(ans)

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

for i in range(len(a)):
    if a[i] == 0:
        print(0)
        exit()

ans = 1
for i in range(len(a)):
  ans *= a[i]
  if ans > 10**18:
    print(-1)
    exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
h1,m1,h2,m2,k = map(int,input().split())
if m2 < m1:
	m2 += 60
    h2 -= 1
m = m2-m1
h = h2-h1

if 60*h+m <= k:
	print(60*h+m)
else:
	print(k)

Fixed submission:
h1,m1,h2,m2,k = map(int,input().split())
if h2 < h1:
    h2 += 24
if m2 < m1:
    m2 += 60
    h2 -= 1
print((h2-h1)*60+m2-m1-k)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
visited = [-1 for _ in range(n+1)]
visited[1] = 0
will = []
root = [[] for _ in range(n+1)] 
for i in range(m):
    a,b = map(int,input().split())
    root[a].append(b)
    root[b].append(a)

will.append(1)

while will:
    visit = will.pop(0)
    for i in root[visit]:
        if visited[i] != -1:
            continue
        if i in will:
            continue
        will.append(i)
        visited[i] = visit

if visited[1:] == -1:
    print('No')
else:
    print('Yes')
    for i in range(2,len(visited)):
        print(visited[i])


Fixed submission:
n,m = map(int,input().split())
visited = [-1 for _ in range(n+1)]
visited[1] = 0
will = []
root = [[] for _ in range(n+1)] 
for i in range(m):
    a,b = map(int,input().split())
    root[a].append(b)
    root[b].append(a)

will.append(1)

while will:
    visit = will.pop(0)
    for i in root[visit]:
        if visited[i] != -1:
            continue
        will.append(i)
        visited[i] = visit

if visited[1:] == -1:
    print('No')
else:
    print('Yes')
    for i in range(2,len(visited)):
        print(visited[i])
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
l = len(t)
judge = True
for i in range(l-1):
	if s[i] == t[i]:
    	judge = False
if judge == True:
	print('Yes')
else:
	print('No')

Fixed submission:
s = input()
t = input()
l = len(s)
if s[:l]==t[:l]:
	print('Yes')
else:
	print('No')

Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
l = len(t)
judge = True
for i in range(l-1):
	if s[i] == t[i]:
    	judge = False
if judge == True:
	print('Yes')
else:
	print('No')

Fixed submission:
s = input()
t = input()
l = len(s)
if s[:l]==t[:l]:
	print('Yes')
else:
	print('No')
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,k = map(int,input().split())
ans = 0
for i in range(a):
  if k == 0:
    print(ans)
    exit()
  ans += 1
  k -= 1
for i in range(b):
  if k == 0:
    print(ans)
    exit()
  k -= 1
for i in range(c):
  if k == 0:
    print(ans)
    exit()
  ans -= 1
  k -= 1

Fixed submission:
a,b,c,k = map(int,input().split())
ans = 0
if k <= a:
    print(k)
elif k <= a+b:
    print(a)
else:
    print(a-(k-a-b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ai = list(map(int,input().split()))
pl = []
mi = []
for i in range(n):
    pl.append(i+ai[i])
    mi.append(i-ai[i])
cnt = 0 
for i in range(n):
    cnt += mi.count(pl[i])
print(cnt)

Fixed submission:
from collections import Counter
n = int(input())
ai = list(map(int,input().split()))
pl = []
mi = []
for i in range(n):
    pl.append(i+ai[i])
    mi.append(i-ai[i])
x = Counter(pl)
y = Counter(mi)
cnt = 0
for i in x.keys():
    cnt += x[i]*y[i]
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
li = []
for i in range(n):
    if a[i] < 200000:
        li.append([a[i],i])
li.sort()
cnt = 0
for i in range(n-1):
    j = i+1
    while j <= n-1 and li[i][0] + li[j][0] < 200000:
        if abs(li[j][1]-li[i][1]) == li[i][0] + li[j][0]:
            cnt += 1
        j += 1
print(cnt)

Fixed submission:
from collections import Counter
n = int(input())
ai = list(map(int,input().split()))
pl = []
mi = []
for i in range(n):
    pl.append(i+ai[i])
    mi.append(i-ai[i])
x = Counter(pl)
y = Counter(mi)
cnt = 0
for i in x.keys():
    cnt += x[i]*y[i]
print(cnt)
Buggy python submission (verdict: Runtime Error):
k = int(input())
a,b = map(int,input().split())
for i in range(a,b+1):
	if i%k == 0:
    	print('OK')
        exit()
print('NG')

Fixed submission:
k = int(input())
a,b = map(int,input().split())
for i in range(a,b+1):
    if i%k == 0:
        print('OK')
        exit()
print('NG')
Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b,n = map(int,input().split())
ans = -10000000000 
for i in range(0,n+1):
    kari = math.floor(a*i/b) - a*math.floor(i/b)
    if ans <= kari:
        ans = kari
    else:
        break
print(ans)


Fixed submission:
import math
a,b,n = map(int,input().split())
if b <= n:
    print(math.floor(a*(b-1)/b)-a*math.floor((b-1)/b))
else:
    print(math.floor(a*n/b)-a*math.floor(n/b))

Buggy python submission (verdict: Time Limit Exceeded):
import math
a,b,n = map(int,input().split())
ans = -10000000000 
for i in range(0,n+1):
    kari = math.floor(a*i/b) - a*math.floor(i/b)
    if ans <= kari:
        ans = kari
    else:
        break
print(ans)


Fixed submission:
import math
a,b,n = map(int,input().split())
if b <= n:
    print(math.floor(a*(b-1)/b)-a*math.floor((b-1)/b))
else:
    print(math.floor(a*n/b)-a*math.floor(n/b))
Buggy python submission (verdict: Runtime Error):
n,m = map(int(input().split()))
a = list(map(int,input().split()))
sum = sum(a)
if n-sum >= 0:
	print(n-sum)
else:
	print(-1)

Fixed submission:
n,m = map(int,input().split())
a = list(map(int,input().split()))
sum = sum(a)
if n-sum >= 0:
	print(n-sum)
else:
	print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
cnt = 0
for i in range(k,n+2):
    front = 0
    end = 0
    for j in range(i):
        front += j
    for j in range(n,n-i,-1):
        end += j
    if end-front+1 > 0:
        cnt += end-front+1
print(cnt)

Fixed submission:
n,k = map(int,input().split())
cnt = 0
for i in range(k,n+2):
    if 0.5*(n-i)*(n-i+1) >= 0:
        minus = 0.5*(n-i)*(n-i+1)
    else:
        minus = 0
    front = 0.5*(i-1)*i
    end = 0.5*n*(n+1) - minus
    cnt += end-front+1
print(int(cnt%(10**9+7)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
sum = 0
for i in range(n):
  if n%3!==0 and n%5!==0:
    sum += i
print(sum)

Fixed submission:
n = int(input())
sum = 0
for i in range(n+1):
    if (i%3)!=0 and (i%5)!=0:
        sum += i
print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
sum = 0
for i in range(n):
    if s[i] == 'R':
        for j in range(i+1,n):
            if s[j] == 'G':
                for k in range(j+1,n):
                    if s[k] == 'B' and j-i!=k-j:
                        sum += 1
            if s[j] == 'B': 
                for k in range(j+1,n):
                    if s[k] == 'G' and j-i!=k-j:
                        sum += 1
for i in range(n):
    if s[i] == 'G':
        for j in range(i+1,n):
            if s[j] == 'R':
                for k in range(j+1,n):
                    if s[k] == 'B' and j-i!=k-j:
                        sum += 1
            if s[j] == 'B':
                for k in range(j+1,n):
                    if s[k] == 'R' and j-i!=k-j:
                        sum += 1
for i in range(n):
    if s[i] == 'B':
        for j in range(i+1,n):
            if s[j] == 'R':
                for k in range(j+1,n):
                    if s[k] == 'G' and j-i!=k-j:
                        sum += 1
            if s[j] == 'G': 
                for k in range(j+1,n):
                    if s[k] == 'R' and j-i!=k-j:
                        sum += 1
print(sum)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

cnt = r*g*b

for i in range(n):
    j = 1
    while i+2*j < n:
        if s[i] != s[i+j] and s[i+j] != s[i+2*j] and s[i+2*j] != s[i]:
            cnt -= 1
            j += 1
        else:
            j += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
sum = 0
for i in range(n):
    for j in range(n):
        if i < j:
            for k in range(n):
                if j < k and s[i]!=s[j]:
                    if j-i!=k-j and s[j]!=s[k] and s[k]!=s[i]:
                        sum += 1
print(sum)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

cnt = r*g*b

for i in range(n):
    j = 1
    while i+2*j < n:
        if s[i] != s[i+j] and s[i+j] != s[i+2*j] and s[i+2*j] != s[i]:
            cnt -= 1
            j += 1
        else:
            j += 1
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
sum = 0
for i in range(n):
    for j in range(n):
        if i < j:
            for k in range(n):
                if j < k and j-i!=k-j and s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
                    sum += 1
print(sum)

Fixed submission:
n = int(input())
s = input()
r = s.count('R')
g = s.count('G')
b = s.count('B')

cnt = r*g*b

for i in range(n):
    j = 1
    while i+2*j < n:
        if s[i] != s[i+j] and s[i+j] != s[i+2*j] and s[i+2*j] != s[i]:
            cnt -= 1
            j += 1
        else:
            j += 1
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())

if n == k:
  print(0)
  exit()
  
if n > k:
  if n%k == 0:
    print(0)
    exit()
  else:
    m = n
    while m > 0:
      m -= k
    if abs(m) < n%k:
      print(-m)
      exit()
    else:
      print(n%k)
      exit()

if n < k:
  if n > abs(n-k):
    print(abs(n-k))
    exit()
  else:
    print(n)
    exit()

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

if n == k:
  print(0)
  exit()
  
if n > k:
  if n%k == 0:
    print(0)
    exit()
  else:
    if n%k > abs(n%k-k):
      print(abs(n%k-k))
    else:
      print(n%k)

if n < k:
  if n > abs(n-k):
    print(abs(n-k))
    exit()
  else:
    print(n)
    exit()
Buggy python submission (verdict: Runtime Error):
n,x,y = map(int,input().split())
ans = [0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        dis = min(j-i, abs(j-(x-1))+1+abs((y-1)-i), abs(j-(y-1))+1+abs((x-1)-i))
        ans[dis-1] += 1
for i in range(n-1):
    print(ans[i])

Fixed submission:
s = input()
if s[2]==s[3] and s[4]==s[5]:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
s = input()
if s[3:4] == 'ff' and s[5:6] == 'ee'
    print('Yes')
else:
    print('No')

Fixed submission:
s = input()
if s[2]==s[3] and s[4]==s[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n,x,y = map(int,input().split())
ans = [0]*(n-1)
for i in range(n-1):
    for j in range(i+1,n):
        dis = min(j-i, abs(j-(x-1))+1+abs((y-1)-i), abs(j-(y-1))+1+abs((x-1)-i))
        ans[dis-1] += 1
for i in range(n-1):
    print(ans[i])

Fixed submission:
n,x,y = map(int,input().split())
ans = [0]*(n-1)
for i in range(1,n):
    for j in range(i+1,n+1):
        dis = min(j-i, abs(j-x)+1+abs(y-i), abs(j-y)+1+abs(x-i))
        ans[dis-1] += 1
for i in range(n-1):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
n,x,y = map(int,input().split())
ans = [0 for _ in range(n-1)]
for i in range(n-1):
    for j in range(i+1,n):
        dis = min(j-i, abs(j-(x-1))+1+abs((y-1)-i), abs(j-(y-1))+1+abs((x-1)-i))
        ans[dis-1] += 1
for i in range(n-1):
    print(ans[i])

Fixed submission:
n,x,y = map(int,input().split())
ans = [0]*(n-1)
for i in range(1,n):
    for j in range(i+1,n+1):
        dis = min(j-i, abs(j-x)+1+abs(y-i), abs(j-y)+1+abs(x-i))
        ans[dis-1] += 1
for i in range(n-1):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
l = input()
volume = l/3**3
print(volume)

Fixed submission:
l = int(input())
volume = (l/3)**3
print(volume)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
a = list(map(int,input().split()))
nans = 0
for i in range(n):
    cnt = a.count(i)
    if cnt >= 2:
        nans += math.factorial(cnt)//(math.factorial(cnt-2)*math.factorial(2))
for i in range(n):
    num = a[i]
    numcnt = a.count(num)
    print(nans-(numcnt-1))

Fixed submission:
import math
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
m = len(set(a))
nans = 0
tbl = list(Counter(a).values())
tbl2 = Counter(a)
for i in range(m):
    if tbl[i] >= 2:
        nans += math.factorial(tbl[i])//(math.factorial(tbl[i]-2)*math.factorial(2))
for i in range(n):
    num = a[i]
    numcnt = tbl2[num]
    print(nans-(numcnt-1))

Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
    acopy = a.copy()
    del acopy[i]
    l = len(acopy)
    acopy.sort()
    cnt = 1
    ans = 0
    for j in range(l-1):
        if acopy[j] == acopy[j+1]:
            cnt += 1
            continue
        else:
            if cnt != 1:
                if cnt == 2:
                    ans += 1
                    cnt = 1
                    continue
                else:
                    ans += math.factorial(cnt)//(math.factorial(cnt-2)*math.factorial(2))
                    cnt = 1
                    continue
    if cnt != 1:
        ans += math.factorial(cnt)//(math.factorial(cnt-2)*math.factorial(2))
    print(ans)

Fixed submission:
import math
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
m = len(set(a))
nans = 0
tbl = list(Counter(a).values())
tbl2 = Counter(a)
for i in range(m):
    if tbl[i] >= 2:
        nans += math.factorial(tbl[i])//(math.factorial(tbl[i]-2)*math.factorial(2))
for i in range(n):
    num = a[i]
    numcnt = tbl2[num]
    print(nans-(numcnt-1))
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
count = n//(a+b)*a
add = min(n%(a+b),a)
sum = count + add
print(sum)

Fixed submission:
a,b,c = input()
if a==b==c:
	print('No')
else:
	print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
tbl = [input().split() for _ in range(q)]
for i in range(q):
    if tbl[i][0] == '1':
        s = s[::-1]
    else:
        if tbl[i][1] == '1':
            s = tbl[i][2]+s
        else:
            s = s+tbl[i][2]
print(s)

Fixed submission:
s = input()
q = int(input())
tbl = [input().split() for _ in range(q)]
cnt = 0
r = []
l = []
for i in range(q-1,-1,-1):
    if tbl[i][0] == '1':
        cnt += 1
    else:
        if (cnt + int(tbl[i][1]))%2 == 1:
            l.append(tbl[i][2])
        else:
            r.append(tbl[i][2])
l = ''.join(l)
if cnt%2 == 1:
    s = s[::-1]
r = ''.join(r[::-1])
print(l+s+r)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
tbl = [input().split() for _ in range(q)]
for i in range(q):
    if tbl[i][0] == '1':
        s = s[::-1]
    else:
        if tbl[i][1] == '1':
            s = tbl[i][2]+s
        else:
            s = s+tbl[i][2]
print(s)

Fixed submission:
s = input()
q = int(input())
tbl = [input().split() for _ in range(q)]
cnt = 0
r = []
l = []
for i in range(q-1,-1,-1):
    if tbl[i][0] == '1':
        cnt += 1
    else:
        if (cnt + int(tbl[i][1]))%2 == 1:
            l.append(tbl[i][2])
        else:
            r.append(tbl[i][2])
l = ''.join(l)
if cnt%2 == 1:
    s = s[::-1]
r = ''.join(r[::-1])
print(l+s+r)
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n%2 = 0:
	print(n/2)
else:
    print(n//2+1)

Fixed submission:
n = int(input())
if n%2 == 0:
	print(n//2)
else:
    print(n//2+1)
Buggy python submission (verdict: Runtime Error):
a,b,c = int(input())
if a==b==c or a!=b!=c:
	print('No')
else:
	print('Yes')

Fixed submission:
a,b,c = map(int,input().split())
if a==b==c:
	print('No')
elif a!=b and b!=c and c!=a:
    print('No')
else:
	print('Yes')
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = list(map(int,input().split()))

for i in range(n):
    p[i] = (p[i]+1)/2

kset = 0
for j in range(k):
    kset += p[j] 

max = -10000
if n != k:
    for l in range(n-k):
        if kset >= max:
            max = kset
        kset = kset - p[l] + p[l+k]
else:
    max = kset
print(max)

Fixed submission:
s,t = input().split()
a,b = map(int,input().split())
u = input()
if u == s:
  print(a-1,b)
else:
  print(a,b-1)
Buggy python submission (verdict: Runtime Error):
import copy
h,w = map(int,input().split())

s = [['#' for _ in range(w+2)]]
for i in range(h):
    si = ['#']
    sij = list(input())
    si.extend(sij)
    si.append('#')
    s.append(si)
s.append(['#' for _ in range(w+2)])

def bfs(i,j):
    root = copy.deepcopy(s)
    q = []
    q.append([i,j])
    root[i][j] = 0
    while q:
        ij = q.pop(0)
        i = ij[0]
        j = ij[1]
        
        if root[i-1][j] == '.': #左
            q.append([i-1,j])
            root[i-1][j] = root[i][j] + 1
        if root[i+1][j] == '.': #右
            q.append([i+1,j])
            root[i+1][j] = root[i][j] + 1
        if root[i][j+1] == '.': #上
            q.append([i,j+1])
            root[i][j+1] = root[i][j] + 1
        if root[i][j-1] == '.': #下
            q.append([i,j-1])
            root[i][j-1] = root[i][j] + 1
    max = 0
    for i in range(1,h+1):
        for j in range(1,w+1):
            if root[i][j] != '#' and root[i][j] > max:
                max = root[i][j]
    return max

ans = -1
for i in range(1,h+1):
    for j in range(1,w+1):
        k = bfs(i,j)
        if ans < k:
            ans = k
print(ans)

Fixed submission:
import copy
h,w = map(int,input().split())

s = [['#' for _ in range(w+2)]]
for i in range(h):
    si = ['#']
    sij = list(input())
    si.extend(sij)
    si.append('#')
    s.append(si)
s.append(['#' for _ in range(w+2)])

def bfs(i,j):
    root = copy.deepcopy(s)
    q = []
    q.append([i,j])
    root[i][j] = 0
    while q:
        ij = q.pop(0)
        i = ij[0]
        j = ij[1]
        
        if root[i-1][j] == '.': #左
            q.append([i-1,j])
            root[i-1][j] = root[i][j] + 1
        if root[i+1][j] == '.': #右
            q.append([i+1,j])
            root[i+1][j] = root[i][j] + 1
        if root[i][j+1] == '.': #上
            q.append([i,j+1])
            root[i][j+1] = root[i][j] + 1
        if root[i][j-1] == '.': #下
            q.append([i,j-1])
            root[i][j-1] = root[i][j] + 1
    max = 0
    for i in range(1,h+1):
        for j in range(1,w+1):
            if root[i][j] != '#' and root[i][j] > max:
                max = root[i][j]
    return max

ans = -1
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == '.':
            k = bfs(i,j)
            if ans < k:
                ans = k
print(ans)