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

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    H, W = map(int, input().rstrip().split())
    G = []
    for i in range(H):
        s = list(input())
        G.append(s)
    # print(G)
    cnt = [[0 for j in range(W)] for i in range(H)]

    for i in range(H):
        done = [0] * W
        for j in range(W):
            if G[i][j] == "#":
                continue
            if done[j]:
                continue
            length = 0
            while j + length < W:
                if G[i][j+length] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i][j + k] += length
                done[j + k] = 1

    for j in range(W):
        done = [0] * H
        for i in range(H):
            if G[i][j] == "#":
                continue
            if done[i]:
                continue
            length = 0
            while i + length < H:
                if G[i+length][j] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i + k][j] += length
                done[i + k] = 1
    ans = 0
    for i in range(H):
        ans = max(ans, max(cnt[i]) - 1)
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    H, W = map(int, input().rstrip().split())
    G = []
    for i in range(H):
        s = list(input())
        G.append(s)
    # print(G)
    cnt = [[0 for j in range(W)] for i in range(H)]

    for i in range(H):
        done = [0] * W
        for j in range(W):
            if G[i][j] == "#":
                continue
            if done[j]:
                continue
            length = 0
            while j + length < W:
                if G[i][j+length] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i][j + k] += length
                done[j + k] = 1

    for j in range(W):
        done = [0] * H
        for i in range(H):
            if G[i][j] == "#":
                continue
            if done[i]:
                continue
            length = 0
            while i + length < H:
                if G[i+length][j] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i + k][j] += length
                done[i + k] = 1
    ans = 0
    for i in range(H):
        ans = max(ans, max(cnt[i]) - 1)
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    H, W = map(int, input().rstrip().split())
    G = []
    for i in range(H):
        s = list(input())
        G.append(s)
    # print(G)

    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]

    INF = 10 ** 18 + 10

    def bfs(i, j):
        d = [[INF for k in range(W)] for l in range(H)]
        q = deque()
        q.append((i, j))
        d[i][j] = 0
        cnt = 1
        while q:
            a, b = q.popleft()
            for k in range(4):
                to_w = max(0, min(W - 1, b + dx[k]))
                to_h = max(0, min(H - 1, a + dy[k]))
                if G[to_h][to_w] == "#":
                    continue
                if d[to_h][to_w] != INF:
                    continue
                if to_w != j and to_h != i:
                    continue
                d[to_h][to_w] = d[a][b] + 1
                q.append((to_h, to_w))
                cnt += 1
        # print(i, j, cnt)
        return cnt

    res = 0
    for h in range(H):
        for w in range(W):
            if G[h][w] == "#":
                continue
            res = max(res, bfs(h, w))
    # bfs(2, 5)
    print(res)


if __name__ == "__main__":
    main()


Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    H, W = map(int, input().rstrip().split())
    G = []
    for i in range(H):
        s = list(input())
        G.append(s)
    # print(G)
    cnt = [[0 for j in range(W)] for i in range(H)]

    for i in range(H):
        done = [0] * W
        for j in range(W):
            if G[i][j] == "#":
                continue
            if done[j]:
                continue
            length = 0
            while j + length < W:
                if G[i][j+length] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i][j + k] += length
                done[j + k] = 1

    for j in range(W):
        done = [0] * H
        for i in range(H):
            if G[i][j] == "#":
                continue
            if done[i]:
                continue
            length = 0
            while i + length < H:
                if G[i+length][j] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i + k][j] += length
                done[i + k] = 1
    ans = 0
    for i in range(H):
        ans = max(ans, max(cnt[i]) - 1)
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = map(int, input().split())
G = []
for i in range(H):
    s = list(input())
    G.append(s)
# print(G)


dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


INF = 10 ** 18 + 10


def bfs(i, j):
    d = [[INF for k in range(W)] for l in range(H)]
    q = deque()
    q.append((i, j))
    d[i][j] = 0
    cnt = 1
    while q:
        a, b = q.popleft()
        for k in range(4):
            to_w = max(0, min(W - 1, b + dx[k]))
            to_h = max(0, min(H - 1, a + dy[k]))
            if G[to_h][to_w] == "#":
                continue
            if d[to_h][to_w] != INF:
                continue
            if to_w != j and to_h != i:
                continue
            d[to_h][to_w] = d[a][b] + 1
            q.append((to_h, to_w))
            cnt += 1
    # print(i, j, cnt)
    return cnt


res = 0
for h in range(H):
    for w in range(W):
        if G[h][w] == "#":
            continue
        res = max(res, bfs(h, w))
# bfs(2, 5)
print(res)


Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    H, W = map(int, input().rstrip().split())
    G = []
    for i in range(H):
        s = list(input())
        G.append(s)
    # print(G)
    cnt = [[0 for j in range(W)] for i in range(H)]

    for i in range(H):
        done = [0] * W
        for j in range(W):
            if G[i][j] == "#":
                continue
            if done[j]:
                continue
            length = 0
            while j + length < W:
                if G[i][j+length] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i][j + k] += length
                done[j + k] = 1

    for j in range(W):
        done = [0] * H
        for i in range(H):
            if G[i][j] == "#":
                continue
            if done[i]:
                continue
            length = 0
            while i + length < H:
                if G[i+length][j] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i + k][j] += length
                done[i + k] = 1
    ans = 0
    for i in range(H):
        ans = max(ans, max(cnt[i]) - 1)
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

H, W = map(int, input().split())
G = []
for i in range(H):
    s = list(input())
    G.append(s)
# print(G)


dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


INF = 10 ** 18 + 10


def bfs(i, j):
    d = [[INF for k in range(W)] for l in range(H)]
    q = deque()
    q.append((i, j))
    d[i][j] = 0
    cnt = 1
    while q:
        a, b = q.popleft()
        for k in range(4):
            to_w = max(0, min(W - 1, b + dx[k]))
            to_h = max(0, min(H - 1, a + dy[k]))
            if G[to_h][to_w] == "#":
                continue
            if d[to_h][to_w] != INF:
                continue
            if to_w != j and to_h != i:
                continue
            d[to_h][to_w] = d[a][b] + 1
            q.append((to_h, to_w))
            cnt += 1
    # print(i, j, cnt)
    return cnt


res = 0
for h in range(H):
    for w in range(W):
        if G[h][w] == "#":
            continue
        res = max(res, bfs(h, w))
# bfs(2, 5)
print(res)


Fixed submission:
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    H, W = map(int, input().rstrip().split())
    G = []
    for i in range(H):
        s = list(input())
        G.append(s)
    # print(G)
    cnt = [[0 for j in range(W)] for i in range(H)]

    for i in range(H):
        done = [0] * W
        for j in range(W):
            if G[i][j] == "#":
                continue
            if done[j]:
                continue
            length = 0
            while j + length < W:
                if G[i][j+length] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i][j + k] += length
                done[j + k] = 1

    for j in range(W):
        done = [0] * H
        for i in range(H):
            if G[i][j] == "#":
                continue
            if done[i]:
                continue
            length = 0
            while i + length < H:
                if G[i+length][j] == "#":
                    break
                length += 1
            for k in range(length):
                cnt[i + k][j] += length
                done[i + k] = 1
    ans = 0
    for i in range(H):
        ans = max(ans, max(cnt[i]) - 1)
    print(ans)


if __name__ == "__main__":
    main()