Buggy python submission (verdict: Time Limit Exceeded):
import sys
h, w = [int(x) for x in input().split()]
mat = [input() for _ in range(h)]
cnt = [[0] * w for _ in range(h)]
row_obs = [[-1] for _ in range(h)]
col_obs = [[-1] for _ in range(w)]

def main():
    for i, r in enumerate(mat):
        for j, c in enumerate(r):
            if c == '#':
                row_obs[i].append(j)
                col_obs[j].append(i)
        row_obs[i].append(w)
    for j in range(w):
        col_obs[j].append(h)

    for i in range(h):
        k = 0
        while True:
            prev, nxt = (row_obs[i][k], row_obs[i][k+1])
            for j in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == w:
                break
            k += 1

    for j in range(w):
        k = 0
        while True:
            prev, nxt = (col_obs[j][k], col_obs[j][k+1])
            for i in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == h:
                break
            k += 1

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, cnt[i][j] - 1)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
h, w = [int(x) for x in input().split()]
mat = [input() for _ in range(h)]
cnt = [[0] * w for _ in range(h)]
row_obs = [[-1] for _ in range(h)]
col_obs = [[-1] for _ in range(w)]

def main():
    for i, r in enumerate(mat):
        for j, c in enumerate(r):
            if c == '#':
                row_obs[i].append(j)
                col_obs[j].append(i)
        row_obs[i].append(w)
    for j in range(w):
        col_obs[j].append(h)

    for i in range(h):
        k = 0
        while True:
            prev, nxt = (row_obs[i][k], row_obs[i][k+1])
            for j in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == w:
                break
            k += 1

    for j in range(w):
        k = 0
        while True:
            prev, nxt = (col_obs[j][k], col_obs[j][k+1])
            for i in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == h:
                break
            k += 1

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, cnt[i][j] - 1)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
h, w = [int(x) for x in input().split()]
mat = [input() for _ in range(h)]
lr = [[None] * w for _ in range(h)]
ab = [[None] * w for _ in range(h)]
row_obs = [[] for _ in range(h)]
col_obs = [[] for _ in range(w)]

def main():
    global mat, h, w
    for i, l in enumerate(mat):
        for j, c in enumerate(l):
            if c == '#':
                row_obs[i].append(j)
                col_obs[j].append(i)
    for b in range(2):
        if b == 0:
            obs = row_obs
        else:
            obs = col_obs
            mat = list(zip(*mat))
            h, w = w, h
        for i in range(h):
            k = 0
            prev = -1
            nxt = obs[i][k] if len(obs[i]) > 0 else w
            for j in range(w):
                if mat[i][j] == '#':
                    prev = obs[i][k]
                    nxt = obs[i][k+1] if k+1 < len(obs[i]) else w
                    k += 1
                else:
                    if b == 0:
                        lr[i][j] = (prev, nxt)
                    else:
                        ab[j][i] = (prev, nxt)
    ans = 0
    h, w = w, h
    mat = list(zip(*mat))
    for i in range(h):
        for j in range(w):
            if mat[i][j] != '#':
                l, r = lr[i][j]
                a, b = ab[i][j]
                ans = max(ans, r - l - 1 + b - a - 1 - 1)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
h, w = [int(x) for x in input().split()]
mat = [input() for _ in range(h)]
cnt = [[0] * w for _ in range(h)]
row_obs = [[-1] for _ in range(h)]
col_obs = [[-1] for _ in range(w)]

def main():
    for i, r in enumerate(mat):
        for j, c in enumerate(r):
            if c == '#':
                row_obs[i].append(j)
                col_obs[j].append(i)
        row_obs[i].append(w)
    for j in range(w):
        col_obs[j].append(h)

    for i in range(h):
        k = 0
        while True:
            prev, nxt = (row_obs[i][k], row_obs[i][k+1])
            for j in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == w:
                break
            k += 1

    for j in range(w):
        k = 0
        while True:
            prev, nxt = (col_obs[j][k], col_obs[j][k+1])
            for i in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == h:
                break
            k += 1

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, cnt[i][j] - 1)
    print(ans)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
h, w = [int(x) for x in input().split()]
mat = [input() for _ in range(h)]
lr = [[None] * w for _ in range(h)]
ab = [[None] * w for _ in range(h)]
row_obs = [[] for _ in range(h)]
col_obs = [[] for _ in range(w)]

def main():
    global mat, h, w
    for i, l in enumerate(mat):
        for j, c in enumerate(l):
            if c == '#':
                row_obs[i].append(j)
                col_obs[j].append(i)
    for b in range(2):
        if b == 0:
            obs = row_obs
        else:
            obs = col_obs
            mat = list(zip(*mat))
            h, w = w, h
        for i in range(h):
            k = 0
            prev = -1
            nxt = obs[i][k] if len(obs[i]) > 0 else w
            for j in range(w):
                if mat[i][j] == '#':
                    prev = obs[i][k]
                    nxt = obs[i][k+1] if k+1 < len(obs[i]) else w
                    k += 1
                else:
                    if b == 0:
                        lr[i][j] = (prev, nxt)
                    else:
                        ab[j][i] = (prev, nxt)
    ans = 0
    h, w = w, h
    mat = list(zip(*mat))
    for i in range(h):
        for j in range(w):
            if mat[i][j] != '#':
                l, r = lr[i][j]
                a, b = ab[i][j]
                ans = max(ans, r - l - 1 + b - a - 1 - 1)
    print(ans)

if __name__ == '__main__':
    main()

Fixed submission:
import sys
h, w = [int(x) for x in input().split()]
mat = [input() for _ in range(h)]
cnt = [[0] * w for _ in range(h)]
row_obs = [[-1] for _ in range(h)]
col_obs = [[-1] for _ in range(w)]

def main():
    for i, r in enumerate(mat):
        for j, c in enumerate(r):
            if c == '#':
                row_obs[i].append(j)
                col_obs[j].append(i)
        row_obs[i].append(w)
    for j in range(w):
        col_obs[j].append(h)

    for i in range(h):
        k = 0
        while True:
            prev, nxt = (row_obs[i][k], row_obs[i][k+1])
            for j in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == w:
                break
            k += 1

    for j in range(w):
        k = 0
        while True:
            prev, nxt = (col_obs[j][k], col_obs[j][k+1])
            for i in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == h:
                break
            k += 1

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, cnt[i][j] - 1)
    print(ans)

if __name__ == '__main__':
    main()