Buggy python submission (verdict: Time Limit Exceeded):
H, W = [int(_) for _ in input().split()]

S = [input() for _ in range(H)]
memo = [[0] * W for _ in range(H)]

for h in range(H):
    done = [False] * W
    for w in range(W):
        if S[h][w] == '#': continue
        if done[w]: continue

        tmp = w
        cnt = 0
        while tmp < W:
            if S[h][tmp] == '#': break
            cnt += 1
            tmp += 1

        for i in range(w, tmp):
            memo[h][i] += cnt
            done[i] = True

for w in range(W):
    done = [False] * H
    for h in range(H):
        if S[h][w] == '#': continue
        if done[h]: continue

        tmp = h
        cnt = 0
        while tmp < H:
            if S[tmp][w] == '#': break
            cnt += 1
            tmp += 1

        for i in range(h, tmp):
            memo[i][w] += cnt
            done[i] = True

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, memo[i][j] - 1)
print(ans)


Fixed submission:
H, W = [int(_) for _ in input().split()]

S = [input() for _ in range(H)]
memo = [[0] * W for _ in range(H)]

for h in range(H):
    done = [False] * W
    for w in range(W):
        if S[h][w] == '#': continue
        if done[w]: continue

        tmp = w
        cnt = 0
        while tmp < W:
            if S[h][tmp] == '#': break
            cnt += 1
            tmp += 1

        for i in range(w, tmp):
            memo[h][i] += cnt
            done[i] = True

for w in range(W):
    done = [False] * H
    for h in range(H):
        if S[h][w] == '#': continue
        if done[h]: continue

        tmp = h
        cnt = 0
        while tmp < H:
            if S[tmp][w] == '#': break
            cnt += 1
            tmp += 1

        for i in range(h, tmp):
            memo[i][w] += cnt
            done[i] = True

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, memo[i][j] - 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W = [int(_) for _ in input().split()]

S = [input() for _ in range(H)]
memo = [[[-1] * 4 for _ in range(W)] for _ in range(H)]

D = [(1, 0), (0, 1), (-1, 0), (0, -1)]


def walk(h, w, d):
    if not (0 <= h < H and 0 <= w < W):
        return 0

    if memo[h][w][d] >= 0:
        return memo[h][w][d]

    if S[h][w] == '#':
        for i in range(4):
            memo[h][w][i] = 0
        return 0
    v = walk(h + D[d][0], w + D[d][1], d)
    memo[h][w][d] = v + 1
    return memo[h][w][d]


def solve():
    ans = 0
    for h in range(H):
        for w in range(W):
            tmp = 0
            for d in range(4):
                tmp += walk(h, w, d)
            ans = max(ans, tmp - 3)
    print(ans)

    # for i in range(H):
    #     print(memo[i])


solve()


Fixed submission:
H, W = [int(_) for _ in input().split()]

S = [input() for _ in range(H)]
memo = [[0] * W for _ in range(H)]

for h in range(H):
    done = [False] * W
    for w in range(W):
        if S[h][w] == '#': continue
        if done[w]: continue

        tmp = w
        cnt = 0
        while tmp < W:
            if S[h][tmp] == '#': break
            cnt += 1
            tmp += 1

        for i in range(w, tmp):
            memo[h][i] += cnt
            done[i] = True

for w in range(W):
    done = [False] * H
    for h in range(H):
        if S[h][w] == '#': continue
        if done[h]: continue

        tmp = h
        cnt = 0
        while tmp < H:
            if S[tmp][w] == '#': break
            cnt += 1
            tmp += 1

        for i in range(h, tmp):
            memo[i][w] += cnt
            done[i] = True

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, memo[i][j] - 1)
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W = [int(_) for _ in input().split()]

S = [input() for _ in range(H)]
memo = [[[-1] * 4 for _ in range(W)] for _ in range(H)]

D = [(1, 0), (0, 1), (-1, 0), (0, -1)]


def walk(h, w, d):
    if not (0 <= h < H and 0 <= w < W):
        return 0

    if memo[h][w][d] >= 0:
        return memo[h][w][d]

    if S[h][w] == '#':
        for i in range(4):
            memo[h][w][i] = 0
        return 0
    v = walk(h + D[d][0], w + D[d][1], d)
    memo[h][w][d] = v + 1
    return memo[h][w][d]


def solve():
    ans = 0
    for h in range(H):
        for w in range(W):
            tmp = 0
            for d in range(4):
                tmp += walk(h, w, d)
            ans = max(ans, tmp - 3)
    print(ans)

    # for i in range(H):
    #     print(memo[i])


solve()


Fixed submission:
H, W = [int(_) for _ in input().split()]

S = [input() for _ in range(H)]
memo = [[0] * W for _ in range(H)]

for h in range(H):
    done = [False] * W
    for w in range(W):
        if S[h][w] == '#': continue
        if done[w]: continue

        tmp = w
        cnt = 0
        while tmp < W:
            if S[h][tmp] == '#': break
            cnt += 1
            tmp += 1

        for i in range(w, tmp):
            memo[h][i] += cnt
            done[i] = True

for w in range(W):
    done = [False] * H
    for h in range(H):
        if S[h][w] == '#': continue
        if done[h]: continue

        tmp = h
        cnt = 0
        while tmp < H:
            if S[tmp][w] == '#': break
            cnt += 1
            tmp += 1

        for i in range(h, tmp):
            memo[i][w] += cnt
            done[i] = True

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, memo[i][j] - 1)
print(ans)