Buggy python submission (verdict: Time Limit Exceeded):
import sys
def solve():
    readline = sys.stdin.readline

    H, W = map(int, readline().split())
    rW = range(W); rH = range(H)
    S = [readline() for i in rH]

    def gen():
        U = [-1]*W
        V = [0]*W
        for i in rH:
            p = -1
            Si = S[i]
            for j in rW:
                if Si[j] == '#':
                    c = j - p - 1
                    for k in range(p+1, j):
                        V[k] = max(V[k], c)
                    yield V[j] + (i - U[j] - 1)
                    V[j] = 0
                    U[j] = i
                    p = j
            c = W - p - 1
            for k in range(p+1, W):
                V[k] = max(V[k], c)
        for u, v in zip(U, V):
            yield v + (H - u - 1)
    sys.stdout.write("%d\n" % (max(gen()) - 1))
solve()

Fixed submission:
H, W = map(int, input().split())
S = [input() for i in range(H)]
P = [[0]*W for i in range(H)]
Q = [[0]*W for i in range(H)]
for i in range(H):
    p = -1
    for j in range(W):
        if S[i][j] == '#':
            c = j - p - 1
            for k in range(p+1, j):
                P[i][k] = c
            p = j
    c = W - p - 1
    for k in range(p+1, W):
        P[i][k] = c
for j in range(W):
    p = -1
    for i in range(H):
        if S[i][j] == '#':
            c = i - p - 1
            for k in range(p+1, i):
                Q[k][j] = c
            p = i
    c = H - p - 1
    for k in range(p+1, H):
        Q[k][j] = c
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            ans = max(ans, P[i][j] + Q[i][j])
print(ans - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H, W = map(int, readline().split())
rW = range(W); rH = range(H)
S = [readline() for i in rH]
P = [[0]*W for i in rH]
for i in rH:
    p = -1
    Si = S[i]
    Pi = P[i]
    for j in rW:
        if Si[j] == '#':
            c = j - p - 1
            Pi[p+1:j] = (c for k in range(c))
            p = j
    c = W - p - 1
    Pi[p+1:W] = (c for k in range(c))

ans = 0
U = [-1]*W
V = [0]*W
for i in rH:
    Si = S[i]
    for j in rW:
        if Si[j] == '#':
            ans = max(ans, V[j] + (i - U[j] - 1))
            V[j] = 0
            U[j] = i
        else:
            V[j] = max(V[j], P[i][j])
for j in rW:
    ans = max(ans, V[j] + (H - U[j] - 1))
sys.stdout.write("%d\n" % (ans - 1))

Fixed submission:
H, W = map(int, input().split())
S = [input() for i in range(H)]
P = [[0]*W for i in range(H)]
Q = [[0]*W for i in range(H)]
for i in range(H):
    p = -1
    for j in range(W):
        if S[i][j] == '#':
            c = j - p - 1
            for k in range(p+1, j):
                P[i][k] = c
            p = j
    c = W - p - 1
    for k in range(p+1, W):
        P[i][k] = c
for j in range(W):
    p = -1
    for i in range(H):
        if S[i][j] == '#':
            c = i - p - 1
            for k in range(p+1, i):
                Q[k][j] = c
            p = i
    c = H - p - 1
    for k in range(p+1, H):
        Q[k][j] = c
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            ans = max(ans, P[i][j] + Q[i][j])
print(ans - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H, W = map(int, readline().split())
rW = range(W); rH = range(H)
S = [readline() for i in rH]
P = [[0]*W for i in rH]
for i in rH:
    p = -1
    Si = S[i]
    Pi = P[i]
    for j in rW:
        if Si[j] == '#':
            c = j - p - 1
            Pi[p+1:j] = (c for k in range(c))
            p = j
    c = W - p - 1
    Pi[p+1:W] = (c for k in range(c))
ans = 0
for j in rW:
    p = -1
    v = 0
    for i in rH:
        if S[i][j] == '#':
            ans = max(ans, v + (i - p - 1))
            v = 0
            p = i
        else:
            v = max(v, P[i][j])
    ans = max(ans, v + (H - p - 1))
sys.stdout.write("%d\n" % (ans - 1))

Fixed submission:
H, W = map(int, input().split())
S = [input() for i in range(H)]
P = [[0]*W for i in range(H)]
Q = [[0]*W for i in range(H)]
for i in range(H):
    p = -1
    for j in range(W):
        if S[i][j] == '#':
            c = j - p - 1
            for k in range(p+1, j):
                P[i][k] = c
            p = j
    c = W - p - 1
    for k in range(p+1, W):
        P[i][k] = c
for j in range(W):
    p = -1
    for i in range(H):
        if S[i][j] == '#':
            c = i - p - 1
            for k in range(p+1, i):
                Q[k][j] = c
            p = i
    c = H - p - 1
    for k in range(p+1, H):
        Q[k][j] = c
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            ans = max(ans, P[i][j] + Q[i][j])
print(ans - 1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H, W = map(int, readline().split())
S = [readline() for i in range(H)]
P = [[0]*W for i in range(H)]
rW = range(W); rH = range(H)
for i in rH:
    p = -1
    Si = S[i]
    Pi = P[i]
    for j in rW:
        if Si[j] == '#':
            c = j - p - 1
            Pi[p+1:j] = (c for k in range(c))
            p = j
    c = W - p - 1
    Pi[p+1:W] = (c for k in range(c))
for j in rW:
    p = -1
    for i in rH:
        if S[i][j] == '#':
            c = i - p - 1
            for k in range(p+1, i):
                P[k][j] += c
            p = i
    c = H - p - 1
    for k in range(p+1, H):
        P[k][j] += c
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            ans = max(ans, P[i][j])
sys.stdout.write("%d\n" % (ans - 1))

Fixed submission:
H, W = map(int, input().split())
S = [input() for i in range(H)]
P = [[0]*W for i in range(H)]
Q = [[0]*W for i in range(H)]
for i in range(H):
    p = -1
    for j in range(W):
        if S[i][j] == '#':
            c = j - p - 1
            for k in range(p+1, j):
                P[i][k] = c
            p = j
    c = W - p - 1
    for k in range(p+1, W):
        P[i][k] = c
for j in range(W):
    p = -1
    for i in range(H):
        if S[i][j] == '#':
            c = i - p - 1
            for k in range(p+1, i):
                Q[k][j] = c
            p = i
    c = H - p - 1
    for k in range(p+1, H):
        Q[k][j] = c
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            ans = max(ans, P[i][j] + Q[i][j])
print(ans - 1)