Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
for i in range(n):
    while b[j] < c[i]:
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += sum(num_b[:j])

print(ans)


Fixed submission:
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
temp_sum = 0
for i in range(n):
    while b[j] < c[i]:
        temp_sum += num_b[j]
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += temp_sum

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
for i in range(n):
    num_b[i] = bisect.bisect_left(a, b[i])

ans = 0
for i in range(n):
    ans += sum(num_b[:bisect.bisect_left(b, c[i])])

print(ans)


Fixed submission:
import bisect

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a = sorted(a)
b = sorted(b)
c = sorted(c)

num_b = [0 for _ in range(n)]
j = 0
for i in range(n):
    if j == n:
        num_b[i] = n
        continue
    while a[j] < b[i]:
        j += 1
        if j == n:
            break
    num_b[i] = j

ans = 0
j = 0
temp_sum = 0
for i in range(n):
    while b[j] < c[i]:
        temp_sum += num_b[j]
        j += 1
        if j == n:
            ans += (n - i) * sum(num_b)
            break
    if j == n:
        break
    ans += temp_sum

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

x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
    x[i], y[i] = map(int, input().split())

min_x = min(x)
min_y = min(y)
for i in range(n):
    x[i] -= min_x
    y[i] -= min_y

sx = sorted(x)
sy = sorted(y)

if n == k:
    print(sx[n - 1] * sy[n - 1])
    exit()

d = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n):
    d[sx.index(x[i]) + 1][sy.index(y[i]) + 1] = 1

#for p in d: print(p)

for i in range(n + 1):
    for j in range(1, n + 1):
        d[i][j] += d[i][j - 1]

for i in range(n + 1):
    for j in range(1, n + 1):
        d[j][i] += d[j - 1][i]

sx = [0] + sx
sy = [0] + sy

a = 0
b = 1
ans = sx[n] * sy[n]
temp = 0
for p in range(n):
    for q in range(p + 1, n + 1):
        for a in range(n):
            for b in range(a + 1, n + 1):
                temp = d[q][b] - d[q][a] - d[p][b] + d[p][a]
                if temp >= k:
                    break
            if temp >= k:
                ans = min(ans, max(1, (sx[b] - sx[a + 1])) * max(1, (sy[q] - sy[p + 1])))

print(ans)

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

a = sorted(a)

if a[0] == a[1]:
    print(a[2])
else:
    print(a[0])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
    x[i], y[i] = map(int, input().split())

min_x = min(x)
min_y = min(y)
for i in range(n):
    x[i] -= min_x
    y[i] -= min_y

sx = sorted(x)
sy = sorted(y)

if n == k:
    print(sx[n - 1] * sy[n - 1])
    exit()

a = 0
b = 1
ans = sx[n - 1] * sy[n - 1]
temp = 0
for p in range(n):
    for q in range(p + 1, n):
        for a in range(n):
            for b in range(a + 1, n):
                count = 0
                for i in range(n):
                    if sx[a] <= x[i] <= sx[b] and sy[p] <= y[i] <= sy[q]:
                        count += 1
                if count >= k:
                    ans = min(ans, (sx[b] - sx[a]) * (sy[q] - sy[p]))

print(ans)

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

x = [0 for _ in range(n)]
y = [0 for _ in range(n)]
for i in range(n):
    x[i], y[i] = map(int, input().split())

min_x = min(x)
min_y = min(y)
for i in range(n):
    x[i] -= min_x
    y[i] -= min_y

sx = sorted(x)
sy = sorted(y)

if n == k:
    print(sx[n - 1] * sy[n - 1])
    exit()

d = [[0 for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(n):
    d[sx.index(x[i]) + 1][sy.index(y[i]) + 1] = 1

for i in range(n + 1):
    for j in range(1, n + 1):
        d[i][j] += d[i][j - 1]

for i in range(n + 1):
    for j in range(1, n + 1):
        d[j][i] += d[j - 1][i]

#sx = [0] + sx
#sy = [0] + sy

a = 0
b = 1
ans = sx[n - 1] * sy[n - 1]
temp = 0
for p in range(n):
    for q in range(p + 1, n):
        for a in range(n):
            for b in range(a + 1, n):
                count = 0
                if d[b + 1][q + 1] - d[b + 1][p] - d[a][q + 1] + d[a][p] >= k:
                    ans = min(ans, (sx[b] - sx[a]) * (sy[q] - sy[p]))

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a = []
for _ in range(n):
    p = int(input())
    if p not in a:
        a.append(p)
    else:
        a.remove(p)

print(len(a))


Fixed submission:
n = int(input())

a = [int(input()) for _ in range(n)]

a = sorted(a)

ans = n
flag = 0
for i in range(1, n):
    if a[i] != a[i-1] or flag == 1:
        flag = 0
    else:
        flag = 1
        ans -= 2

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

if n == 1:
    print(1)
    exit()
elif n == 2:
    if abs(a[0] - a[1]) <= 2:
        print(2)
    else:
        print(1)
    exit()

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1

d = sorted(d.items())

m = len(d)
ans = d[0][1]
if d[1][0] == d[0][0] + 1:
    ans += d[1][1]
r = d[m-1][1]
if d[m-2][0] == d[m-1][0] - 1:
    r += d[m-2][1]
ans = max(r, ans)

for i in range(1, m-1):
    r = d[i][1]
    if d[i-1][0] + 1 == d[i][0]:
        r += d[i-1][1]
    if d[i+1][0] - 1 == d[i][0]:
        r += d[i+1][1]
    ans = max(ans, r)


print(ans)



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

d = {}
for x in a:
    if x in d:
        d[x] += 1
    else:
        d[x] = 1

d = sorted(d.items())

m = len(d)

if m == 1:
    print(d[0][1])
    exit()
elif m == 2:
    if d[1][0] - d[0][0] <= 2:
        print(d[0][1] + d[1][1])
    else:
        print(max(d[0][1], d[1][1]))
    exit()

ans = d[0][1]
if d[1][0] == d[0][0] + 1:
    ans += d[1][1]
r = d[m-1][1]
if d[m-2][0] == d[m-1][0] - 1:
    r += d[m-2][1]
ans = max(r, ans)

for i in range(1, m-1):
    r = d[i][1]
    if d[i-1][0] + 1 == d[i][0]:
        r += d[i-1][1]
    if d[i+1][0] - 1 == d[i][0]:
        r += d[i+1][1]
    ans = max(ans, r)


print(ans)
Buggy python submission (verdict: Runtime Error):
x, a, b = map(int, input().split())

if min(abs(x-a) > abs(x-b)):
    print('B')
else:
    print('A')

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

if abs(x-a) > abs(x-b):
    print('B')
else:
    print('A')
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))

f = 0
d = 0
for x in a:
    if x % 4 == 0:
        f += 1
    elif x % 2 == 0:
        d += 1

if 0 < d < n:
    d -= 1

if n > f * 2 + 1 + d:
    print('No')
else:
    print('Yes')


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

h = 0
w = 0

ans = [[0 for _ in range(W)] for _ in range(H)]
for i in range(n):
    for j in range(a[i]):
        ans[h][w] = i + 1
        if h % 2 == 0:
            if w == W - 1:
                h += 1
            else:
                w += 1
        else:
            if w == 0:
                h += 1
            else:
                w -= 1

for p in ans: print(' '.join(map(str, p)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(input().split())

if n == 1:
    print(1)
    print(1)
    exit()

MOD = 10 ** 9 + 7

b = sorted(a)

for i in range(n):
    if b[i] == b[i + 1]:
        d = b[i]
        break

p = []
for i in range(n):
    if a[i] == d:
        p.append(i)

w = p[0] + n - p[1]

c = [0 for _ in range(n + 2)]

temp = 1
for i in range(1, n + 2):
    temp *= i
    c[i] = temp

def cmb(x, y):
    if y < 0 or y > x:
        return 0
    elif x == y:
        return 1
    else:
        return c[x] // c[y] // c[x - y] % MOD


print(n)
for k in range(2, n + 2):
    ans = cmb(n + 1, k) - cmb(w, k - 1)
    print(ans % MOD)



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

print(a + b + c - max(a, b, c))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(input().split())

b = []
for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.insert(0, a[i])

if n % 2 == 1:
    b = list(reversed(b))

print(' '.join(b))

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

b = ['' for _ in range(n)]
m = n // 2

b[m] = a[0]

p = 1

for i in range(1, n):
    if i % 2 == 1:
        b[m - p] = a[i]
    else:
        b[m + p] = a[i]
        p += 1

if n % 2 == 1:
    b = list(reversed(b))

print(' '.join(b))

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

b = []
for x in a:
    b.append(x)
    b = list(reversed(b))

print(' '.join(b))

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

b = ['' for _ in range(n)]
m = n // 2

b[m] = a[0]

p = 1

for i in range(1, n):
    if i % 2 == 1:
        b[m - p] = a[i]
    else:
        b[m + p] = a[i]
        p += 1

if n % 2 == 1:
    b = list(reversed(b))

print(' '.join(b))
Buggy python submission (verdict: Time Limit Exceeded):
from bisect import bisect_left

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

p = [0] * (n + 1)
q = [] + p

L = [] + a[:n]
R = [] + a[n * 2:]
C = [] + a[n:n * 2]

p[0] = sum(L)
q[n] = sum(R)

L.sort()
R.sort()

for i in range(n):
    if C[i] > L[0]:
        p[i + 1] = p[i] + C[i] - L[0]
        del L[0]
        L.insert(bisect_left(L, C[i]), C[i])
    else:
        p[i + 1] = p[i]
    if C[n - 1 - i] < R[n -1]:
        q[n - 1 - i] = q[n - i] + C[n - 1 - i] - R[n - 1]
        del R[n - 1]
        R.insert(bisect_left(R, C[n - 1 - i]), C[n - 1 - i])
    else:
        q[n - 1 - i] = q[n - i]

ans = p[0] - q[0]
for i in range(1, n + 1):
    ans = max(ans, p[i] - q[i])

print(ans)



Fixed submission:
import heapq

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

p = [0] * (n + 1)
q = [] + p

L = []
R = []
C = [] + a[n:n * 2]

for i in range(n):
    heapq.heappush(L, a[i])
    heapq.heappush(R, - a[n * 2 + i])

p[0] = sum(L)
q[n] = sum(R)
for i in range(n):
    if C[i] > L[0]:
        p[i + 1] = p[i] + C[i] - L[0]
        heapq.heappop(L)
        heapq.heappush(L, C[i])
    else:
        p[i + 1] = p[i]

    temp = C[n - 1 - i] * -1
    if temp > R[0]:
        q[n - 1 - i] = q[n - i] + temp - R[0]
        heapq.heappop(R)
        heapq.heappush(R, temp)
    else:
        q[n - 1 - i] = q[n - i]

ans = p[n] + q[n]
for i in range(n):
    ans = max(ans, p[i] + q[i])

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

a.sort()

l = 0
r = n

while l < r:
    m = (l + r) // 2
    if a[m] >= k:
        r = m
        continue
    dp = [set() for _ in range(n + 1)]
    dp[0].add(0)
    check = 0
    for i in range(n):
        if i == m:
            dp[i + 1] = dp[i]
            continue
        for x in dp[i]:
            dp[i + 1].add(x)
            temp = x + a[i]
            if k - a[m] <= temp < k:
                check = 1
                break
            elif temp < k - a[m]:
                dp[i + 1].add(temp)
        if check == 1:
            break
    if check == 0:
        l = m + 1
    else:
        r = m

print(l)

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

a.sort(reverse=True)

temp = 0
ans = 0

for x in a:
    if temp + x < k:
        temp += x
        ans += 1
    else:
        ans = 0

print(ans)

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

a.sort()

l = 0
r = n

while l < r:
    m = (l + r) // 2
    if a[m] >= k:
        r = m
        continue
    dp = set()
    dp.add(0)
    check = 0
    for i in range(n):
        next = set()
        if i == m:
            continue
        for x in dp:
            temp = x + a[i]
            if k - a[m] <= temp < k:
                check = 1
                break
            elif temp < k - a[m]:
                next.add(temp)
        if check == 1:
            break
        else:
            dp = dp | next
    if check == 0:
        l = m + 1
    else:
        r = m

print(l)

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

a.sort(reverse=True)

temp = 0
ans = 0

for x in a:
    if temp + x < k:
        temp += x
        ans += 1
    else:
        ans = 0

print(ans)

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

a.sort()

l = 0
r = n

while l < r:
    m = (l + r) // 2
    if a[m] >= k:
        r = m
        continue
    dp = [[0 for _ in range(k)] for _ in range(n)]
    dp[0][0] = 1
    t = 1
    check = 0
    for i in range(n):
        if i == m:
            continue
        for j in range(k - a[i]):
            if dp[t - 1][j] == 1:
                dp[t][j] = 1
                temp = j + a[i]
                if k - a[m] <= temp < k:
                    check = 1
                    break
                elif temp < k - a[m]:
                    dp[t][temp] = 1
        if check == 1:
            break
        t += 1
    if check == 0:
        l = m + 1
    else:
        r = m

print(l)

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

a.sort(reverse=True)

temp = 0
ans = 0

for x in a:
    if temp + x < k:
        temp += x
        ans += 1
    else:
        ans = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

if m // 2 <= n:
    print(m // 2)
else:
    m -= n * 2
    print(n + m // 4)


Fixed submission:
n = int(input())

x = n * 800
y = (n // 15) * 200

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

if sum(a) % ( (1 + n) * n // 2 ) != 0:
    print('NO')
    exit()

while a[0] > 0:
    temp = min(a)
    if temp < 0:
        print('NO')
        exit()
    p = a.index(min(a))
    for i in range(n):
        a[(p + i) % n] -= i + 1

if min(a) < 0 or sum(a) != 0:
    print('NO')
else:
    print('YES')


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

if n == 1:
    print('YES')
    exit()

if sum(a) % ( (1 + n) * n // 2 ) != 0:
    print('NO')
    exit()

k = sum(a) // ( (1 + n) * n // 2 )

temp = k - a[0] + a[n - 1]
if temp % n != 0 or temp < 0:
    print('NO')
    exit()

d = temp // n
for i in range(1, n):
    temp = k - a[i] + a[i - 1]
    if temp % n != 0 or temp < 0:
        print('NO')
        exit()
    d += temp // n

print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for a, b in reversed(ab):
    while (a+ans) % b != 0:
        ans += 1

print(ans)

Fixed submission:
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for a, b in reversed(ab):
    if (a + ans) % b != 0:
        ans += b - (a + ans) % b

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, t = map(int, input().split())
a = np.array(list(map(int, input().split())))

d = 0
c = 1

m = 0
while m < n - 1:
    i = np.argmax(a[m:])
    if i == 0:
        m += 1
        continue
    #print(i,m, a[i], a[m:m+i])
    j = np.argmin(a[m:m+i])
    x = a[m+j]
    y = a[m+i]
    #print(x, y, i, j, y - x)
    if y - x == d:
        c += 1
    elif y - x > d:
        d = y - x
        c = 1
    m += i
    #print(m, a[m:])

print(c)


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

m = a[0]
d = 0
c = 1

for i in range(1, n):
    if a[i] - m > d:
        d = a[i] - m
        c = 1
    elif a[i] - m == d:
        c += 1
    elif a[i] < m:
        m = a[i]

print(c)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n, t = map(int, input().split())
a = list(map(int, input().split()))

d = 0
c = 1

m = 0
while m < n - 1:
    y = np.max(a[m:])
    i = a.index(y)
    if i == m:
        m += 1
        continue
    x = np.min(a[m:i])
    if y - x == d:
        c += 1
    elif y - x > d:
        d = y - x
        c = 1
    m = i + 1

print(c)




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

m = a[0]
d = 0
c = 1

for i in range(1, n):
    if a[i] - m > d:
        d = a[i] - m
        c = 1
    elif a[i] - m == d:
        c += 1
    elif a[i] < m:
        m = a[i]

print(c)

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

b = dict()
for i in range(n):
    b[i] = a[i]

d = 0
c = 1

m = 0
while m < n - 1:
    y = max(a[m:])
    i = a.index(y)
    if i == m:
        m += 1
        continue
    x = min(a[m:i])
    if y - x == d:
        c += 1
    elif y - x > d:
        d = y - x
        c = 1
    m = i + 1

print(c)




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

m = a[0]
d = 0
c = 1

for i in range(1, n):
    if a[i] - m > d:
        d = a[i] - m
        c = 1
    elif a[i] - m == d:
        c += 1
    elif a[i] < m:
        m = a[i]

print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ta = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = 0
b = 0
for x, y in ta:
    if x >= a and y >= b:
        a = x
        b = y
    else:
        temp = 2
        while x * temp < a or y * temp < b:
            temp += 1
        a = x * temp
        b = y * temp

print(a + b)


Fixed submission:
n = int(input())
ta = [tuple(int(x) for x in input().split()) for _ in range(n)]

a = 0
b = 0
for x, y in ta:
    if x >= a and y >= b:
        a = x
        b = y
    else:
        temp = max(a // x, b // y)
        while x * temp < a or y * temp < b:
            temp += 1
        a = x * temp
        b = y * temp

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

a = list(map(int, input().split()))

temp = 0
check = 0
for i in range(1, n):
    if a[i] <= a[i - 1] + x:
        check = 1
        temp = i
        break

if check == 1:
    a = a[temp:] + a[:temp]

check = 1
for i in range(1, n):
    if a[i] >= a[i - check] + x:
        a[i] = a[i - check] + x
        check += 1
    else:
        check = 1

print(sum(a))

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

if x[0] * x[1] * x[2] % 2 == 0:
    print('0')
else:
    x = sorted(x)
    print(x[0] * x[1])
Buggy python submission (verdict: Runtime Error):
n = int(n)
a = list(map(int, input().split()))

a.sort()

ans = 0
for i in range(n):
    ans += a[i*2]

print(ans)

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

a.sort()

ans = 0
for i in range(n):
    ans += a[i*2]

print(ans)
Buggy python submission (verdict: Runtime Error):
def check(numbers, threshold):
    
    total = 0
    
    for number in numbers:
        d, m = divmod(number, threshold)
        if m == 0:
            d -= 1
        total += d
    return total
    
def main():
    n, k = map(int, input().rstrip().split(" "))
    
    numbers = list(map(int, input().rstrip().split(" ")))
    
    bottom, top = 0, 2 * (10 ** 9)
    
    while bottom < top:
        #print(bottom, top)
        if check(numbers, (bottom + top )// 2) <= k:
            top = (bottom + top )// 2
        else:
            bottom = ((bottom + top )// 2) + 1
    print(top)
    
if __name__ == '__main__':
    main()


Fixed submission:
def check(numbers, threshold):
    
    total = 0
    
    for number in numbers:
        d, m = divmod(number, threshold)
        if m == 0:
            d -= 1
        total += d
    return total
    
def main():
    n, k = map(int, input().rstrip().split(" "))
    
    numbers = list(map(int, input().rstrip().split(" ")))
    
    bottom, top = 1, 2 * (10 ** 9)
    
    while bottom < top:
        #print(bottom, top)
        if check(numbers, (bottom + top )// 2) <= k:
            top = (bottom + top )// 2
        else:
            bottom = ((bottom + top )// 2) + 1
    print(top)
    
if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
buffer = ""

def set_buffer(text):
    global buffer
    import io
    buffer = io.StringIO(text)
    
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])
def solve(maze, start_r, start_c):
    
    distances = {}
    offsets = [(-1,0),(1,0),(0,-1),(0,1)]
    
    distances[start_r, start_c] = 0
    candidates = [(start_r, start_c)]
    
    while candidates:
        r, c= candidates.pop(0)
        
        for offset_r, offset_c in offsets:
            move_r, move_c = r + offset_r, c + offset_c
            if not (move_r, move_c) in distances and maze[move_r, move_c] == ".":
                distances[move_r, move_c] = distances[r, c] + 1
                candidates.append((move_r, move_c))
    
    return max(distances.values())
    

def main(input_text=""):
    if input_text:
        set_buffer(input_text)
    h, w = get_next_ints()
    from collections import defaultdict
    maze = defaultdict(str)
    for r in range(h):
        line = get_next_str()
        for c in range(w):
            maze[r,c] = line[c]
    
    results = []
    for r in range(h):
        for c in range(w):
            result = solve(maze, r, c)
            results.append(result)
    
    print(max(results))
    
if __name__ == '__main__':
    main()
if __name__ == '__jupyter__':
    import doctest
    print(doctest.testmod())
    

Fixed submission:

def get_next_str():
    return input().rstrip("\n")
def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])
def solve(maze, start_r, start_c):
    
    distances = {}
    offsets = [(-1,0),(1,0),(0,-1),(0,1)]
    
    distances[start_r, start_c] = 0
    candidates = [(start_r, start_c)]
    
    while candidates:
        r, c= candidates.pop(0)
        
        for offset_r, offset_c in offsets:
            move_r, move_c = r + offset_r, c + offset_c
            if not (move_r, move_c) in distances and maze[move_r, move_c] == ".":
                distances[move_r, move_c] = distances[r, c] + 1
                candidates.append((move_r, move_c))
    
    return max(distances.values())
    

def main():
    h, w = get_next_ints()
    from collections import defaultdict
    maze = defaultdict(str)
    for r in range(h):
        line = get_next_str()
        for c in range(w):
            maze[r,c] = line[c]
    
    results = []
    for r in range(h):
        for c in range(w):
            if maze[r,c] != "#":
                result = solve(maze, r, c)
                results.append(result)
    
    print(max(results))
    
if __name__ == '__main__':
    main()