Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02923 (python)

Fixed submission:
# import sys
# input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))
if n==1:
    print(0)
    exit()
else:
    count_list = []
    count = 0
    i = n-1
    while i<n:
        # print(i)
        if i>0 and h[i-1]>=h[i]:
            count += 1
            i -= 1
        else:
            count_list.append(count)
            count = 0
            if i>0:
                i = i-1
            elif i==0:
                break
print(max(count_list))

Buggy submission (verdict: Runtime Error):
# import sys
# input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))
if n==1:
    print(0)
    exit()
else:
    count_list = []
    count = 0
    i = n-1
    while 0<i<n:
        if h[i-1]>=h[i]:
            count += 1
            i -= 1
        else:
            count_list.append(count)
            count = 0
            i = i-1
print(max(count_list))

Buggy submission (verdict: Runtime Error):
# import sys
# input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))
if n==1:
    print(0)
    exit()
else:
    count_list = []
    count = 0
    i = n-1
    while 0<i<n:
        if h[i-1]>=h[i]:
            count += 1
            i -= 1
        else:
            count_list.append(count)
            count = 0
            i = i-1
print(max(count_list))

Buggy submission (verdict: Runtime Error):
# import sys
# input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))
count_list = []
count = 0
i = n-1
while 0<i<n:
    if h[i-1]>=h[i]:
        count += 1
        i -= 1
    else:
        count_list.append(count)
        count = 0
        i = i-1
# print(count_list)
print(max(count_list))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n = int(input())
h = list(map(int,input().split()))

count_list = []
count = 0
i = n-1
while 0<i<n:
    if h[i-1]>=h[i]:
        count += 1
        i -= 1
    else:
        count_list.append(count)
        count = 0
        i = i-1
# print(count_list)
print(max(count_list))
Problem p02947 (python)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    if a[i] >= 2:
        count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
import math
count = 0
for i in range(len(a)):
    count += math.factorial(a[i])//(math.factorial(a[i]-2)*2)
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = [input() for i in range(n)]
# print(n)
# print(s)
s = list(map(list, s))
# print(s)
for i in range(n):
    s[i].sort()
    s[i] = "".join(s[i])
# print(s)
dic = {}
for i in range(n):
    if s[i] in dic:
        dic[s[i]] += 1
    else:
        dic.setdefault(s[i],1)
a = list(dic.values())
# print(a)
from scipy.misc import comb
# print(comb(n,r,exact=True))
count = 0
for i in range(len(a)):
    count += comb(a[i],2,True)
print(count)
Problem p02983 (python)

Fixed submission:
l,r = map(int, input().split())
n = r - l + 1
if 2019<=n:
    print(0)
elif 3<=n and n<2019:
    for k in range(l,r+1):
        if k%673==0:
            print(0)
            exit()

    mod = 2019
    for i in range(l,r):
        for j in range(l+1,r+1):
            mod_new = (i*j)%2019
            if mod_new == 1:
                print(1)
                exit()
            else:
                mod = min(mod,mod_new)
    print(mod)                             
else:
    print((l*r)%2019)

Buggy submission (verdict: Runtime Error):
l,r = map(int, input().split())
n = r - l + 1
if 2019<=n:
    print(0)
elif:
  	mod = 2019
	for i in range(l,r):
        for j in range(l+1,r+1):
            mod_new = (i*j)%2019
            mod = min(mod,mod_new)
    print(mod)

Buggy submission (verdict: Runtime Error):
l,r = map(int, input().split())
n = r - l + 1
if 2019<=n:
    print(0)
elif 3<=n and n<2019:
	mod = 2019
    for i in range(l,r):
        for j in range(l+1,r+1):
            mod_new = (i*j)%2019
            mod = min(mod,mod_new)
    print(mod)                             
else:
    print((l*r)%2019)
Problem p02995 (python)

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

nc = (b//c) - ((a-1)//c)
# print(nc)

nd = (b//d) - ((a-1)//d)
# print(nd)

def gcd(a, b):
    if a < b:
        a,b = b,a
    while (a%b)!=0:
        a,b = b,a%b
    return b

def lcm(a, b):
    return (a*b)//gcd(a, b)

ncd = (b//lcm(c,d)) - ((a-1)//lcm(c,d))
# print(ncd)

u = b - a + 1
# print(u)

ans = u - nc - nd + ncd

print(ans)

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())

nc = int(b/c) - int((a-1)/c)
# print(nc)

nd = int(b/d) - int((a-1)/d)
# print(nd)

import math 

def lcm(a,b):
    y = a*b/math.gcd(a,b)
    return int(y)

ncd = int(b/lcm(c,d)) - int((a-1)/lcm(c,d))
# print(ncd)

u = b - a + 1
# print(u)

ans = u - nc - nd + ncd

print(ans)
Problem p03043 (python)

Fixed submission:
n,k = map(int,input().split())
import math
s = 0
for i in range(n):
    if i>=k:
        s += (1/n)
    else:
        r  = int(math.ceil(math.log2(k/(i+1))))
        s += (1/n)*((1/2)**r)
print(s)

Buggy submission (verdict: Runtime Error):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

INF = float("inf")

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,k = myinput()

ans = 0
import math
for i in range(n):
    m = i+1
    if m<k:
        x = math.ceil( math.log2(k/m) )
        ans += 1/n * ( (1/2)**x )
    else:
        ans += 1/n
print(ans)
Problem p03633 (python)

Fixed submission:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd
from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n = int(input())
t = [ int(input()) for _ in range(n) ]
# print(t)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

ans = lcm_list(t)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from math import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n = int(input())
t = [ int(input()) for _ in range(n) ]
# print(t)

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

ans = lcm_list(t)
print(ans)
Problem p04048 (python)

Fixed submission:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,x = myinput()

def mycalc(a,b):
    if b==0:
        return 0
    else:
        return ( (a//b) * 3 * b ) + mycalc(b,a%b)

ans = mycalc(n-x,x)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from math import gcd
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,x = myinput()
ans = (n-1)*3
print(ans)
Problem p02983 (python)

Fixed submission:
import numpy as np
L, R = list(map(int, input().split(' ')))
x = []
x.append(L % 2019)
for i in range(L+1, R+1):
    m = i % 2019
    if x[0] == m:
        break
    x.append(m)
    
min_v = 2018
for i in range(0, len(x)-1):
    tmp = np.amin(np.mod([x[i]*x[j] for j in range(i+1, len(x))], 2019))
    if tmp < min_v:
        min_v = tmp

print(min_v)

Buggy submission (verdict: Runtime Error):
import numpy as np
L, R = list(map(int, input().split(' ')))
x = []
x.append(L % 2019)
for i in range(L+1, R+1):
    m = i % 2019
    if s == m:
        break
    x.append(m)
min_v = 2018
for i in range(0, len(x)-1):
    tmp = np.amin(np.mod([x[i]*x[j] for j in range(i+1, len(x))], 2019))
    if tmp < min_v:
        min_v = tmp

print(min_v)

Buggy submission (verdict: Runtime Error):
import numpy as np
L, R = list(map(int, input().split(' ')))
x = []
x.append(L % 2019)
for i in range(L+1, R+1):
    m = i % 2019
    if s == m:
        break
    x.append(m)
min_v = 2018
for i in range(0, len(x)-1):
    tmp = np.amin(np.mod([x[i]*x[j] for j in range(i+1, len(x))], 2019))
    if tmp < min_v:
        min_v = tmp

print(min_v)

Buggy submission (verdict: Runtime Error):
import numpy as np
L, R = list(map(int, input().split(' ')))
x = []
x.append(L % 2019)
for i in range(L+1, R+1):
    m = i % 2019
    if s == m:
        break
    x.append(m)
min_v = 2018
for i in range(0, len(x)-1):
    tmp = np.amin(np.mod([x[i]*x[j] for j in range(i+1, len(x))], 2019))
    if tmp < min_v:
        min_v = tmp

print(min_v)
Problem p02993 (python)

Fixed submission:
key_no = input()
ret = 'Good'
for i in range(len(key_no)-1):
  if key_no[i] == key_no[i+1]:
    ret = 'Bad'
    break  
print(ret)

Buggy submission (verdict: Runtime Error):
key_no = input()
ret = 'Good'
for i in range(len(key_no)-1):
  if key_no[i] == key_no[i+1]:
    ret = 'Bad'
  	break
print(ret)
Problem p03030 (python)

Fixed submission:
N = int(input())  
sps = []
ss = []
for i in range(1, N+1):
    s, p = input().split(' ')
    sps.append([i, s, int(p)])
    if s not in ss:
        ss.append(s)

sps = sorted(sps, key=lambda x: x[2], reverse=True)
ss = sorted(ss)
ret = []
for s in ss:
    t = [tmp for tmp in sps if tmp[1]==s]
    ret.extend(t)

for i in range(N):
    print(ret[i][0])

Buggy submission (verdict: Runtime Error):
import pandas as pd
N = int(input())
sps = []
for i in range(1, N+1):
    s, p = input().split(' ')
    sps.append({'i': i, 's': s, 'p': int(p)})
ret = pd.DataFrame(sps).sort_values(['s', 'p'], ascending=[True, False]).values.tolist()
for i in range(N):
    print(ret[i][0])

Buggy submission (verdict: Runtime Error):
import pandas as pd
N = int(input())
sps = []
for i in range(1, N+1):
    s, p = input().split(' ')
    sps.append({'i': i, 's': s, 'p': p})
ret = pd.DataFrame(sps).sort_values(['s', 'p'], ascending=[True, False]).values.tolist()
for i in range(N):
    print(ret[i][0])
Problem p03037 (python)

Fixed submission:
N, M = map(int, input().split(' '))
 
data = []
l = 1
r = 10**5
for m in range(M):
    li, ri = map(int, input().split(' '))
    if li > l:
      l = li
    if ri < r:
      r = ri
 
if l<= N <= r:
  cnt = (N - l) + 1
elif l > r:
  cnt = 0
elif r < N:
  cnt = (r - l) + 1
else:
  cnt = 0
 
print(cnt)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split(' '))

data = []
l = 1
r = 10**5
for m in range(M):
    li, ri = map(int, input().split(' '))
    if li > l:
      l = li
    if ri < r:
      r = ri

if l<= N <= r:
  cnt = (N - l) + 1
elif r >= N:
  cnt = (r - l) + 1
else N < l:
  cnt = 0
Problem p02678 (python)

Fixed submission:
n,m = map(int,input().split())
map_li = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1
    map_li[a].append(b)
    map_li[b].append(a)

ans_li = [-1]*n
queue=[0]
visited = [False]*n

while queue:
    x = queue.pop(0)
    for g in map_li[x]:
        if visited[g]==False:
            queue.append(g)
            if ans_li[g]==-1:
                ans_li[g]=x
                visited[g]=True 
if -1 in ans_li[1:]:
    print('No')
else:
    print('Yes')
    for ans in ans_li[1:]:
        print(ans+1)

Buggy submission (verdict: Runtime Error):
import networkx as nx
n,m,*s = map(int, open(0).read().split())
 
g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])
 
for x in s:
    g.add_edge(x[0],x[1])
di=nx.predecessor(g,source=1)
 
if len(di)!=n:
    print("No");exit()
print("Yes")
for x in range(2,n+1):
    print(di[x][0])

Buggy submission (verdict: Runtime Error):
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for i in range(m)]

g=nx.Graph()
g.add_nodes_from([i for i in range(1,n+1)])

for x in s:
    g.add_edge(x[0],x[1])
di=nx.predecessor(g,source=1)

if len(di)!=n:
    print("No")
    exit()

print("Yes")
for x in range(2,n+1):
    print(di[x][0])

Buggy submission (verdict: Runtime Error):
from collections import deque

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

ans_li = [-1]*n
queue=deque()
queue.append(0)

while queue:
    x = queue.pop(0)
    for g in map_li[x]:
        if ans_li[g]==-1:
            ans_li[g]=x
if -1 in ans_li[1:]:
    print('No')
else:
    print('Yes')
    for ans in ans_li[1:]:
        print(ans+1)
Problem p02690 (python)

Fixed submission:
x = int(input())

if x==1:
    print(0,-1);exit()

num_li = [i**5 for i in range(1,1000)]

for i in range(1000):
    a = num_li[i]
    if x-a in num_li:
        b = num_li.index(x-a)+1
        a = -(num_li.index(a)+1)
        break
    if x+a in num_li:
        b = num_li.index(x+a)+1
        a = num_li.index(a)+1
        break

print(b,a)

Buggy submission (verdict: Runtime Error):
x = int(input())

if x==1:
    print(0,-1);exit()

num_li = [i**5 for i in range(1,100)]

for i in range(100):
    a = num_li[i]
    if x-a in num_li:
        b = num_li.index(x-a)+1
        a = -(num_li.index(a)+1)
        break
    if x+a in num_li:
        b = num_li.index(x+a)+1
        a = num_li.index(a)+1
        break

print(b,a)
Problem p02696 (python)

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

ans = math.floor(a*min((b-1),n)/b)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
a,b,n = map(int,input().split())

for i in range(n,0,-1):
    if a*math.floor(i/b)<math.floor(a*i/b):
        ans=math.floor(a*i/b)-a*math.floor(i/b)
        break

print(ans)

Buggy submission (verdict: Runtime Error):
import math
a,b,n = map(int,input().split())

for i in range(n,1,-1):
    if a*math.floor(i/b)<math.floor(a*i/b):
        ans=math.floor(a*i/b)-a*math.floor(i/b)
        break

print(ans)
Problem p02732 (python)

Fixed submission:
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in a_count.items():
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
a_input = list(map(int,input().split()))

a_count = Counter(a_input)

score_dic={}
exclude_dic={}

for k,v in enumerate(a_count.items()):
    score_dic[k]=v*(v-1)//2
    exclude_dic[k]=(v-1)*(v-2)//2

score_sum = sum(score_dic.values())

for i in range(n):
    print(score_sum-score_dic[a_input[i]]+exclude_dic[a_input[i]])
Problem p02744 (python)

Fixed submission:
from collections import deque
 
n = int(input())
 
def dfs(n):
  stack = deque()
  stack.append("a")
  while stack:
    q = stack.popleft()
    if len(q) == n:
      ans.append(q) 
    if len(q) < n:
      for i in range(ord("a"), ord(max(q)) + 2):
        stack.append(q + chr(i))
    #print(stack)
    
ans = []
dfs(n)
 
print("\n".join(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque
 
n = int(input())
 
def dfs(n):
  stack = deque()
  stack.append("a")
  while stack:
    q = stack.popleft()
    if len(q) == n:
      ans.append(q) 
    if len(q) < n:
      for i in range(ord("a"), ord(max(q)) + 2):
        stack.append(q + chr(i))
    print(stack)
    
ans = []
dfs(n)
 
print("\n".join(ans))
Problem p02747 (python)

Fixed submission:
s = input()

if len(s)%2!=0:
    print('No');exit()
for i in range(0,len(s),2):
    if s[i]=='h' and s[i+1]=='i':
        continue
    else:
        print('No');exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()

for i in range(0,len(s),2):
    if s[i]=='h' and s[i+1]=='i':
        continue
    else:
        print('No');exit()
print('Yes')
Problem p02761 (python)

Fixed submission:
import sys
N, M = map(int, input().split())
S = [0] * M
C = [0] * M
for i in range(M):
    S[i], C[i] = map(int, input().split())

for i in range(1000):
    string = str(i)
    if len(string) != N:
        continue
    flag = True
    for j in range(M):
        if string[S[j] - 1] == str(C[j]):
            None
        else:
            flag = False
            break
    if flag:
        print(i)
        sys.exit(0)
print("-1")

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc_inputs = [[int(j) for j in input().split()] for i in range(m)]

dic={}
for sc in sc_inputs:
    s,c = map(int,sc)
    if s in dic and dic.get(s)!=c:
        print(-1);exit()
    dic[s]=c

if dic[1]==0:
    print(-1);exit()
ans=float('inf')
for i in range(10**(n-1),10**n):
    s = str(i)
    flag = True
    for key,value in dic.items():
        if s[key-1]!=str(value):
            flag=False
    if flag:
        ans=min(ans,int(s))
print(ans)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
sc_inputs = [[int(j) for j in input().split()] for i in range(m)]

dic={}
for sc in sc_inputs:
    s,c = map(int,sc)
    if s in dic and dic.get(s)!=c:
        print(-1);exit()
    dic[s]=c

if dic[1]==0:
    print(-1);exit()
for i in range(10**(n-1),10**n):
    s = str(i)
    flag = True
    for key,value in dic.items():
        if s[key-1]!=str(value):
            flag=False
    if flag:
        print(s);exit()
Problem p02803 (python)

Fixed submission:
from collections import deque
h,w = map(int,input().split())
s_input = [list(input()) for i in range(h)]

mx = [0,0,1,-1]
my = [1,-1,0,0]

ans = 0
for i in range(h):
    for j in range(w):
        if s_input[i][j]=='#':
            continue
        queue = deque()
        queue.append([j,i])

        visited = [[-1]*w for i in range(h)]
        visited[i][j]=0

        res = 0
        while queue:
            x,y = queue.popleft()
            for k in range(4):
                nx = x+mx[k]
                ny = y+my[k]
                if 0<=nx<w and 0<=ny<h:
                    if visited[ny][nx]!=-1:
                        continue
                    if s_input[ny][nx]=='#':
                        continue
                    visited[ny][nx]=visited[y][x]+1
                    queue.append([nx,ny])
                    res = max(res,visited[ny][nx])
        ans = max(ans,res)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
h,w = map(int,input().split())
s_input = [list(input()) for i in range(h)]

mx = [0,0,1,-1]
my = [1,-1,0,0]

ans = 0
for i in range(h):
    for j in range(w):
        if s_input[i][j]=='#':
            continue
        queue = deque()
        queue.append([j,i])

        visited = [[-1]*w for i in range(h)]
        visited[i][j]=0

        res = 0
        while queue:
            y,x = queue.popleft()
            for k in range(4):
                nx = x+mx[k]
                ny = y+my[k]
                if 0<=nx<w and 0<=ny<h:
                    if visited[ny][nx]!=-1:
                        continue
                    if s_input[ny][nx]=='#':
                        continue
                    visited[ny][nx]=visited[y][x]+1
                    queue.append([nx,ny])
                    res = max(res,visited[ny][nx])
        ans = max(ans,res)
print(ans)