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

Fixed submission:
from queue import deque


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

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

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

P = [-1] * N

root = 0
q = deque([root])
while q:
    x = q.popleft()
    for y in graph[x]:
        if y == P[x]:
            continue
        C[y] += C[x]
        q.append(y)
        P[y] = x

print(*C)

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
connect = {a:[] for a in range(1,n+1)}
ans = [0]*n

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

def d(p, x):
    ans[p-1] += x
    for b in connect[p]:
        d(b, x)
        
for _ in range(q):
    p, x = map(int, input().split())
    d(p, x)
    
print(*ans)
Problem p02983 (python)

Fixed submission:
l, r = map(int, input().split())
ans = 2019
if r-l > 2019:
    print(0)
else:
    for i in range(l, r+1):
        for j in range(i+1, r+1):
            mod = divmod(i*j, 2019)[-1]
            if mod < ans:
                ans = mod
    print(ans)

Buggy submission (verdict: Runtime Error):
import math

l, r = map(int, input().split())
e = 2019
e1 = 3
e2 = e // e1

if r-l == 1:
    print(l*r % e)
else:
    if divmod(l,e2)[0] < divmod(r,e2)[0]:
        print(0)
    else:
        if r < e
            print(r*(r-1) % e)
        elif e < l:
            print(l*(l+1) % e)
Problem p03103 (python)

Fixed submission:
import itertools

n,m = map(int, input().split())
AB = []
ans = 0
for n in range(n):
    a,b = map(int,input().split())
    AB.append([a,b])
AB.sort()
A,B = zip(*AB)
A,B = list(A), list(B)

i = list(_ for _ in itertools.accumulate(B) if _ <= m)
if i == []:
    ans = A[0]*m
else:
    B = B[:len(i)] + [m-i[-1]]
    A = A[:len(B)]

    ans = sum([a*b for a,b in zip(A,B)])
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

n,m = map(int, input().split())
AB = []
ans = 0
for n in range(n):
    a,b = map(int,input().split())
    AB.append([a,b])
AB.sort()
A,B = zip(*AB)
A,B = list(A), list(B)

i = list(_ for _ in itertools.accumulate(B) if _ <= m)

B = B[:len(i)] + [m-i[-1]]
A = A[:len(B)]

ans = sum([a*b for a,b in zip(A,B)])
print(ans)
Problem p03244 (python)

Fixed submission:
from collections import Counter
from statistics import mode


n = int(input())
V = list(map(int, input().split()))

A = V[::2]
B = V[1::2]
countA = sorted(list(Counter(A).items()), key=lambda x: -x[1])
countB = sorted(list(Counter(B).items()), key=lambda x: -x[1])
if len(set(V)) == 1:
    print(n//2)
elif countA[0][0] != countB[0][0]:
    print(len(A)-countA[0][1] + len(B)-countB[0][1])
else:
    print(min(
        len(A)-countA[0][1] + len(B)-countB[1][1],
        len(A)-countA[1][1] + len(B)-countB[0][1]
        ))

Buggy submission (verdict: Runtime Error):
n = int(input())
V = list(map(int, input().split()))
countA = []
countB = []
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    for i in range(N//2):
        countA.append(A.count(A[i]))
        countB.append(B.count(B[i]))
    max_countA = max(countA)
    max_countB = max(countB)
    
    print(len(A)-max_countA + len(A)-max_countB)

Buggy submission (verdict: Runtime Error):
n = int(input())
V = list(map(int, input().split()))
if len(set(V)) == 1:
    print(n//2)
else:
    A = V[::2]
    B = V[1::2]
    for _ in range(N//2):
        countA = [A.count(a) for a in set(A)]
        countB = [B.count(b) for b in set(B)]
    max_countA = max(countA)
    max_countB = max(countB)
    
    print(len(A)-max_countA + len(A)-max_countB)
Problem p03262 (python)

Fixed submission:
from fractions import gcd
from functools import reduce

n,x = map(int, input().split())
X = [int(i) for i in input().split()]
X = [abs(x-j) for j in X]
ans = reduce(gcd, X)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

n,x = map(int, input().split())
X = [int(i) for i in input().split()]
X = [abs(x-j) for j in X]
ans = reduce(math.gcd, X)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

n,x = map(int, input().split())
X = [int(i) for i in input().split()]
X = [abs(x-j) for j in X]
print(reduce(math.gcd, X))

Buggy submission (verdict: Runtime Error):
import math, functools

N, X = map(int, input().split())
x = [int(x) for x in input().split()]
A = []

if N > 1:
  for n in range(N-1):
    a = abs(x[n] - x[n+1])
    A.append(a)

  D = functools.reduce(math.gcd, A)
else:
  D = x[0] - X
print(D)
Problem p03273 (python)

Fixed submission:
h,w = map(int, input().split())
a = [input() for _ in range(h)]

r = [False] * h
c = [False] * w

for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      r[i] = True
      c[j] = True

for i in range(h):
  if r[i]:
    for j in range(w):
      if c[j]:
        print(a[i][j], end="")
    print()

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
a = [input() for _ in range(4)]

r = [False] * h
c = [False] * w

for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      r[i] = True
      c[j] = True

for i in range(h):
  if r[i]:
    for j in range(w):
      if c[j]:
        print(a[i][j], end="")
    print()

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
a = [input() for _ in range(4)]

r = [False] * h
c = [False] * w

for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      r[i] = True
      c[j] = True

for i in range(h):
  if r[i]:
    for j in range(w):
      if c[j]:
        print("{}".format(a[i][j]), end="")
    print()
Problem p03285 (python)

Fixed submission:
N = int(input())
ans = 0

for i in range(26):
  for j in range(15):
    n = 4*i + 7*j
    if n == N:
      ans = 1
      break
  if ans == 1:
    break

if ans == 1:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = 0
​
for i in range(1,26):
  for j in range(1,15):
    n = 4*i + 7*j
    if n == N:
      ans = 1
      break
      
if ans == 1:
  print("Yes")
else:
  print("No")
Problem p03294 (python)

Fixed submission:
from functools import reduce
from fractions import gcd

N = int(input())
A = [int(a) for a in input().split()]
def lcm(a,b):
    return (a*b//gcd(a, b))
def lcmm(l):
    return reduce(lcm, l)

m = lcmm(A) - 1
print(sum([m%a for a in A]))

Buggy submission (verdict: Runtime Error):
from functools import reduce
from math import gcd


N = int(input())
A = [int(a) for a in input().split()]
def lcm(a,b):
    return (a*b//gcd(a, b))
def lcmm(l):
    return reduce(lcm, l)

m = lcmm(A) - 1
print(sum([m%a for a in A]))
Problem p03386 (python)

Fixed submission:
A,B,K = map(int, input().split())
X = range(A,B+1)

for _ in sorted(set(X[:K]) | set(X[-K:])):
  print(_)

Buggy submission (verdict: Runtime Error):
A,B,K = map(int, input().split())
X = list(range(A,B+1))

for _ in sorted(set(X[:K]) | set(X[-K:])):
  print(_)

Buggy submission (verdict: Runtime Error):
A,B,K = map(int, input().split())
X = list(range(A,B+1))
ans = X[:K] + X[-K:]

for _ in sorted(set(ans)):
  print(_)

Buggy submission (verdict: Runtime Error):
A,B,K = map(int, input().split())
X = list(range(A,B+1))
ans = X[:K] + X[-K:]

for _ in set(ans):
  print(_)
Problem p03556 (python)

Fixed submission:
import math
print(int(math.sqrt(int(input()))) ** 2)

Buggy submission (verdict: Runtime Error):
import math
print(int(math.sqrt(int(input()))) ** 2
Problem p03611 (python)

Fixed submission:
from collections import Counter


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

nc = Counter(A)
C = []
for i in range(max(A) + 1):
    c = nc[i - 1] + nc[i] + nc[i + 1]
    C.append(c)

print(max(C))

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


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

nc = Counter(A)
C = []
for i in range(1, max(A)):
    c = nc[i - 1] + nc[i] + nc[i + 1]
    C.append(c)

print(max(C))
Problem p03673 (python)

Fixed submission:
from collections import deque

N = int(input())
A = [int(a) for a in input().split()]
B = deque([])
for n in range(N):
    if n % 2 == 0:
        B.append(A[n])
    else:
        B.appendleft(A[n])
if N % 2 == 0:
    print(*B)
else:
    print(*list(B)[::-1])

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(a) for a in input().split()]
B = deque([])
for n in range(N):
    if n % 2 == 0:
        B.append(A[n])
    else:
        B.appendleft(A[n])
print(*B)
Problem p03037 (python)

Fixed submission:
from itertools import accumulate

n, m = [int(x) for x in input().split()]
a = [0 for i in range(n + 2)]
for i in range(m):
    l, r = [int(x) for x in input().split()]
    a[l] += 1
    a[r + 1] -= 1
a = list(accumulate(a))
print(a.count(m))

Buggy submission (verdict: Runtime Error):
from itertools import accumulate

n, m = [int(x) for x in input().split()]
a = [0 for i in range(m + 2)]
for i in range(n):
	l, r = [int(x) for x in input().split()]
    a[l] += 1
    a[r + 1] -= 1
a = list(accumulate(a))
print(a.count(m))
Problem p03046 (python)

Fixed submission:
m, k = [int(x) for x in input().split()]
if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
else:
    if k < 1 << m:
        a = [str(i) for i in range(1 << m) if i != k]
        print(' '.join(a), k, ' '.join(reversed(a)), k)
    else:
        print(-1)

Buggy submission (verdict: Runtime Error):
m, k = [int(x) for x in input().split()]
if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
else:
    if k < 1 << m:
        print(*(i for i in range(1 << m) if i != k), k, *reversed([i for i in range(1 << m) if i != k]), k)
    else:
        print(-1)
Problem p03085 (python)

Fixed submission:
print({'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G'}[input()])

Buggy submission (verdict: Runtime Error):
  print({'A': 'T', 'T': 'A', 'G': 'C', 'C': 'G'}[input()])
Problem p02684 (python)

Fixed submission:
import numpy as np
import itertools
n, k = map(int, input().split())
a = list(map(int, input().split()))

now = 1
town_list = [0]*n
town_list[0] = 1
tn_list = [1]

while(1):
    next = a[now-1]
    now = next
    if town_list[now-1] == 0:
        town_list[now-1] = 1
        tn_list.append(now)

    else:
        idx = tn_list.index(now)
        initial = tn_list[:idx]
        cycle = tn_list[idx:]
        break

if k >= len(initial):
    end_idx = (k-len(initial))%len(cycle)
    print(cycle[end_idx])
else:
    print(initial[k])

Buggy submission (verdict: Runtime Error):
import numpy as np
import itertools
n, k = map(int, input().split())
a = list(map(int, input().split()))

now = 1
town_list = [0]*n
town_list[0] = 1
tn_list = [1]

while(1):
    next = a[now-1]
    now = next
    if town_list[now-1] == 0:
        town_list[now-1] = 1
        tn_list.append(now)

    else:
        idx = tn_list.index(now)
        initial = tn_list[:idx]
        cycle = tn_list[idx:]
        break

if k > len(initial):
    end_idx = (k-len(initial))%len(cycle)
    print(cycle[end_idx])
else:
    print(initial[k])
Problem p02717 (python)

Fixed submission:
x,y,z = map(int, input().split())

x1, y1, z1 = y, x, z
x2, y2, z2 = z1, y1, x1

print(x2, y2, z2)

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

vote.sort(reverse=True)
popular = vote[0:m]
sum = sum(vote)

yes = True
print('sum=', sum, sum/(4*m))
print('list=', popular)

for win in popular:
    if win < sum / (4*m):
        print('No')
        yes = False
        break

print(yes)

if yes:
    print('Yes')
Problem p02718 (python)

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

vote.sort(reverse=True)
popular = vote[0:m]
sum = sum(vote)

yes = True

for win in popular:
    if win < sum / (4*m):
        print('No')
        yes = False
        break


if yes:
    print('Yes')

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

vote.sort(reverse=True)
popular = vote[0:m-1]
sum = sum(vote)

yes = True

for win in popular:
    if win < sum / (4*m):
        print('No')
        yes = False
        stop

if yes:
    print('Yes')
Problem p02947 (python)

Fixed submission:

from collections import Counter

N = int(input())
S = [''.join(map(str,(sorted(str(input()))))) for i in range(N)]
counter = Counter(S)

answer = sum(x*(x-1)//2 for x in counter.values())
print(answer)

Buggy submission (verdict: Runtime Error):
import collections
from scipy.special import comb

n = int(input())
d_list = []
cnt_list = collections.defaultdict(lambda:1)
for i in range(n):
    s = str(input())
    
    d = collections.Counter(s)

    if i >= 1:
        if d in list(d_list):
            idx = d_list.index(d)
            cnt_list[idx] += 1
        else:
            d_list.append(d)
    else:
        d_list.append(d)

ans = 0
cnt_list = list(cnt_list.values())
for i in range(len(cnt_list)):
    ans += comb(cnt_list[i], 2, exact=True)
print(ans)
Problem p03628 (python)

Fixed submission:
n = int(input())
s1 = str(input())
s2 = str(input())

cnt = 1

for i in range(n):
    if i == 0:
        if s1[i] == s2[i]:
            cnt = cnt * 3
            previous = 'tate'
        else:
            cnt = cnt * 6
            previous = 'yoko1'
    else:
        if s1[i] == s2[i]:   #tate
            if previous == 'tate':
                cnt = cnt * 2
            elif previous == 'yoko2':
                cnt = cnt * 1
                previous = 'tate'
        else:   #yoko
            if previous == 'tate':
                cnt = cnt * 2
                previous = 'yoko1'
            elif previous == 'yoko2':
                cnt = cnt * 3
                previous = 'yoko1'
            elif previous == 'yoko1':
                previous = 'yoko2'
        
print(cnt%1000000007)

Buggy submission (verdict: Runtime Error):
n = int(input())
s1 = str(input())
s2 = str(input())

cnt = 1

for i in range(n):
    if i == 0:
        if s1[i] == s2[i]:
            cnt = cnt * 3
            previous = 'tate'
        else:
            cnt = cnt * 6
            previous = 'yoko1'
    else:
        if s1[i] == s2[i]:   #tate
            if previous == 'tate':
                cnt = cnt * 2
            elif previous == 'yoko2':
                cnt = cnt * 3
        else:   #yoko
            if previous = 'tate':
                cnt = cnt * 2
            elif previous = 'yoko2':
                cnt = cnt * 3
print(cnt%1000000007)
Problem p02727 (python)

Fixed submission:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

def cumsum(it):
    """
    累積和
    :param collections.Iterable it:
    """
    cs = 0
    ret = []
    for v in it:
        cs += v
        ret.append(cs)
    return ret


X, Y, A, B, C = list(map(int, sys.stdin.buffer.readline().split()))
P = list(map(int, sys.stdin.buffer.readline().split()))
Q = list(map(int, sys.stdin.buffer.readline().split()))
R = list(map(int, sys.stdin.buffer.readline().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

ps = sum(P[:X])
qs = sum(Q[:Y])
r_cum = cumsum(R)

x = X - 1
y = Y - 1

ans = ps + qs
# 何個着色するか
for cnt in range(1, min(X + Y, C) + 1):
    if x >= 0 and y >= 0 and P[x] < Q[y] or y < 0:
        ps -= P[x]
        x -= 1
    else:
        qs -= Q[y]
        y -= 1
    s = r_cum[cnt - 1] + ps + qs
    ans = max(ans, s)
print(ans)

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

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353

def cumsum(it):
    """
    累積和
    :param collections.Iterable it:
    """
    cs = 0
    ret = []
    for v in it:
        cs += v
        ret.append(cs)
    return ret


X, Y, A, B, C = list(map(int, sys.stdin.buffer.readline().split()))
P = list(map(int, sys.stdin.buffer.readline().split()))
Q = list(map(int, sys.stdin.buffer.readline().split()))
R = list(map(int, sys.stdin.buffer.readline().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

ps = sum(P[:X])
qs = sum(Q[:Y])
r_cum = cumsum(R)

x = X - 1
y = Y - 1

ans = ps + qs
# 何個着色するか
for cnt in range(1, min(X + Y, C) + 1):
    if x >= 0 and y >= 0 and P[x] < Q[y] or y < 0:
        ps -= P[x]
        x -= 1
    elif x >= 0 and y >= 0 and P[x] > Q[y] or x < 0:
        qs -= Q[y]
        y -= 1
    else:
        assert False
    s = r_cum[cnt - 1] + ps + qs
    ans = max(ans, s)
print(ans)
Problem p02780 (python)

Fixed submission:
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N, K = list(map(int, sys.stdin.buffer.readline().split()))
P = list(map(int, sys.stdin.buffer.readline().split()))

P = np.array(P, dtype=float)
E = (P + 1) / 2
cs = E.cumsum()

ans = cs[K - 1]
if K < N:
    ans = max(ans, (cs[K:] - cs[:-K]).max())
print(ans)

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

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N , K = list(map(int, sys.stdin.buffer.readline().split()))
P = list(map(int, sys.stdin.buffer.readline().split()))

P = np.array(P, dtype=float)
E = (P + 1) / 2
cs = E.cumsum()


ans = (cs[K:] - cs[:-K]).max()
ans = max(ans, cs[K - 1])
print(ans)
Problem p02799 (python)

Fixed submission:
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def argsort(li, key=None, reverse=False):
    return [i for _, i in sorted(
        [(a, i) for i, a in enumerate(li)], key=(lambda t: key(t[0])) if key else None, reverse=reverse
    )]


N, M = list(map(int, sys.stdin.buffer.readline().split()))
D = list(map(int, sys.stdin.buffer.readline().split()))
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for i, (v, u) in enumerate(VU):
    v -= 1
    u -= 1
    graph[v].append(u)
    graph[u].append(v)

edges = {}
colors = [None] * N
for v in argsort(D):
    d = D[v]
    if colors[v] is not None:
        continue
    for u in graph[v]:
        if colors[u] is not None:
            edges[v, u] = d
            colors[v] = not colors[u]
            break
        if D[u] == d:
            edges[v, u] = d
            colors[v] = True
            colors[u] = False
            break
    if colors[u] is None:
        print(-1)
        exit()
S = ''
for c in colors:
    S += 'B' if c else 'W'
ans = []
for v, u in VU:
    v -= 1
    u -= 1
    if (v, u) in edges:
        ans.append(edges[v, u])
    elif (u, v) in edges:
        ans.append(edges[u, v])
    else:
        ans.append(10 ** 9)

print(S)
print(*ans, sep='\n')

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

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def argsort(li, key=None, reverse=False):
    return [i for _, i in sorted(
        [(a, i) for i, a in enumerate(li)], key=(lambda t: key(t[0])) if key else None, reverse=reverse
    )]


N, M = list(map(int, sys.stdin.buffer.readline().split()))
D = list(map(int, sys.stdin.buffer.readline().split()))
VU = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]

graph = [[] for _ in range(N)]

for i, (v, u) in enumerate(VU):
    v -= 1
    u -= 1
    graph[v].append(u)
    graph[u].append(v)

edges = {}
ans = [0] * M
colors = [None] * M
for v in argsort(D):
    d = D[v]
    for u in graph[v]:
        if colors[u] is not None:
            edges[v, u] = d
            colors[v] = not colors[u]
            break
        if D[u] == d:
            edges[v, u] = d
            colors[v] = True
            colors[u] = False
            break
    if colors[u] is None:
        print(-1)
        exit()
S = ''
for c in colors:
    S += 'B' if c else 'W'
ans = []
for v, u in VU:
    v -= 1
    u -= 1
    if (v, u) in edges:
        ans.append(edges[v, u])
    elif (u, v) in edges:
        ans.append(edges[u, v])
    else:
        ans.append(10 ** 9)

print(S)
print(*ans, sep='\n')
Problem p02803 (python)

Fixed submission:
import os
import sys

import numpy as np
from scipy.sparse.csgraph._shortest_path import floyd_warshall

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, W = list(map(int, sys.stdin.buffer.readline().split()))
S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(H)]


def to_i(h, w):
    return h * W + w


N = H * W
graph = [[0] * N for _ in range(N)]
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            if 0 <= h - 1 < H and S[h - 1][w] == '.':
                graph[to_i(h - 1, w)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h - 1, w)] = 1
            if 0 <= h + 1 < H and S[h + 1][w] == '.':
                graph[to_i(h + 1, w)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h + 1, w)] = 1
            if 0 <= w - 1 < W and S[h][w - 1] == '.':
                graph[to_i(h, w - 1)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h, w - 1)] = 1
            if 0 <= w + 1 < W and S[h][w + 1] == '.':
                graph[to_i(h, w + 1)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h, w + 1)] = 1
dist = floyd_warshall(graph, directed=False)
dist[dist == np.inf] = 0
print(int(dist.max()))

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

import numpy as np
from scipy.sparse.csgraph._shortest_path import floyd_warshall

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

H, W = list(map(int, sys.stdin.buffer.readline().split()))
S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(H)]


def to_i(h, w):
    return h * W + w


N = H * W
graph = [[0] * N for _ in range(N)]
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            if 0 <= h - 1 < H and S[h - 1][w] == '.':
                graph[to_i(h - 1, w)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h - 1, w)] = 1
            if 0 <= h + 1 < H and S[h + 1][w] == '.':
                graph[to_i(h + 1, w)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h + 1, w)] = 1
            if 0 <= w - 1 < W and S[h][w - 1] == '.':
                graph[to_i(h, w - 1)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h, w - 1)] = 1
            if 0 <= w + 1 < H and S[h][w + 1] == '.':
                graph[to_i(h, w + 1)][to_i(h, w)] = 1
                graph[to_i(h, w)][to_i(h, w + 1)] = 1
dist = floyd_warshall(graph, directed=False)
dist[dist == np.inf] = 0
print(int(dist.max()))