Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
cnt = [[-3]*w for _ in range(h)]

for i in range(h):
    c = 1
    for j in range(w):
        if s[i][j] == "#": c = 1
        else:
            cnt[i][j] += c
            c += 1
    c = 1
    for j in range(w)[::-1]:
        if s[i][j] == "#": c = 1
        else:
            cnt[i][j] += c
            c += 1

for j in range(w):
    c = 1
    for i in range(h):
        if s[i][j] == "#": c = 1
        else:
            cnt[i][j] += c
            c += 1
    c = 1
    for i in range(h)[::-1]:
        if s[i][j] == "#": c = 1
        else:
            cnt[i][j] += c
            c += 1

print(max(max(i) for i in cnt))

Fixed submission:
h,w = map(int,input().split())
s = [input() for _ in range(h)]
u1 = [[0 for _ in range(w)] for _ in range(h)]
u2 = [[0 for _ in range(w)] for _ in range(h)]
d1 = {}
d2 = {}

idx = 1
cnt = 0
for i in range(h):
    flag = False
    for j in range(w):
        if s[i][j] == ".":
            flag = True
            u1[i][j] = idx
            cnt += 1
        elif flag:
            d1[idx] = cnt
            cnt = 0
            idx += 1
            flag = False  
    if flag:
        d1[idx] = cnt
        cnt = 0
        idx += 1

idx = 1
cnt = 0
for j in range(w):
    flag = False
    for i in range(h):
        if s[i][j] == ".":
            flag = True
            u2[i][j] = idx
            cnt += 1
        elif flag:
            d2[idx] = cnt
            cnt = 0
            idx += 1
            flag = False  
    if flag:
        d2[idx] = cnt
        cnt = 0
        idx += 1

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            ans = max(ans, d1[u1[i][j]]+d2[u2[i][j]]-1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
u1 = [[0 for _ in range(w)] for _ in range(h)]
u2 = [[0 for _ in range(w)] for _ in range(h)]
d1 = {}
d2 = {}

idx = 1
cnt = 0
for i in range(h):
    flag = False
    for j in range(w):
        if s[i][j] == ".":
            flag = True
            u1[i][j] = idx
            cnt += 1
        elif flag:
            d1[idx] = cnt
            cnt = 0
            idx += 1
            flag = False  
    if flag:
        d1[idx] = cnt
        cnt = 0
        idx += 1

idx = 1
cnt = 0
for j in range(w):
    flag = False
    for i in range(h):
        if s[i][j] == ".":
            flag = True
            u2[i][j] = idx
            cnt += 1
        elif flag:
            d2[idx] = cnt
            cnt = 0
            idx += 1
            flag = False  
    if flag:
        d2[idx] = cnt
        cnt = 0
        idx += 1

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            ans = max(ans, d1[u1[i][j]]+d2[u2[i][j]]-1)
print(ans)

Fixed submission:
h,w = map(int,input().split())
s = [input() for _ in range(h)]
u1 = [[0 for _ in range(w)] for _ in range(h)]
u2 = [[0 for _ in range(w)] for _ in range(h)]
d1 = {}
d2 = {}

idx = 1
cnt = 0
for i in range(h):
    flag = False
    for j in range(w):
        if s[i][j] == ".":
            flag = True
            u1[i][j] = idx
            cnt += 1
        elif flag:
            d1[idx] = cnt
            cnt = 0
            idx += 1
            flag = False  
    if flag:
        d1[idx] = cnt
        cnt = 0
        idx += 1

idx = 1
cnt = 0
for j in range(w):
    flag = False
    for i in range(h):
        if s[i][j] == ".":
            flag = True
            u2[i][j] = idx
            cnt += 1
        elif flag:
            d2[idx] = cnt
            cnt = 0
            idx += 1
            flag = False  
    if flag:
        d2[idx] = cnt
        cnt = 0
        idx += 1

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            ans = max(ans, d1[u1[i][j]]+d2[u2[i][j]]-1)
print(ans)