Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().rsplit())
S = [list(input().rstrip()) for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if S[i][j] == ".":
                L[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            L[i][j] += 1 + L[i][j - 1]
for i in range(h):
    for j in range(w):
        if i == 0:
            if S[i][j] == ".":
                U[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            U[i][j] += 1 + U[i - 1][j]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if j == w - 1:
            if S[i][j] == ".":
                R[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            R[i][j] += 1 + R[i][j + 1]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if i == h - 1:
            if S[i][j] == ".":
                D[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            D[i][j] += 1 + D[i + 1][j]
ans = 0
for i in range(h):
    for j in range(w):
        temp = D[i][j] + U[i][j] + L[i][j] + R[i][j] - 3
        ans = max(temp, ans)
print(ans)


Fixed submission:
h, w = map(int, input().rsplit())
S = [list(input().rstrip()) for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if S[i][j] == ".":
                L[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            L[i][j] += 1 + L[i][j - 1]
for i in range(h):
    for j in range(w):
        if i == 0:
            if S[i][j] == ".":
                U[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            U[i][j] += 1 + U[i - 1][j]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if j == w - 1:
            if S[i][j] == ".":
                R[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            R[i][j] += 1 + R[i][j + 1]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if i == h - 1:
            if S[i][j] == ".":
                D[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            D[i][j] += 1 + D[i + 1][j]
ans = 0
for i in range(h):
    for j in range(w):
        temp = D[i][j] + U[i][j] + L[i][j] + R[i][j] - 3
        ans = max(temp, ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
imput=sys.stdin.readline
h,w=map(int,input().split())
w+=2
h+=2
grid='#'*w
for _ in range(h-2):
    grid+='#'+input()+'#'
grid+='#'*w
move=[1,-1,w,-w]
score_a=[0]*(h*w)
score_b=[0]*(h*w)
score_c=[0]*(h*w)
score_d=[0]*(h*w)

for i in range(h*w):
    if grid[i]=='#':
        score_a[i]=0
        score_b[i]=0
    else:
        if i-1>=0 and i-1<=h*w-1:
            score_a[i]+=score_a[i-1]+1
        if i-w>=0 and i-w<=h*w-1:
            score_b[i]+=score_b[i-w]+1
    if grid[h*w-1-i]=='#':
        score_c[h*w-1-i]=0
        score_d[h*w-1-i]=0
    else:
        if h*w-1-i+1<=h*w-1 and h*w-1-i+1>=0:
            score_c[h*w-1-i]+=score_c[h*w-1-i+1]+1
        if h*w-1-i+w<=h*w-1 and h*w-1-i+w>=0:
            score_d[h*w-1-i]+=score_d[h*w-1-i+w]+1
ans=0
for i in range(h*w):
    ans=max(ans, score_a[i]+score_b[i]+score_c[i]+score_d[i]-3)
print(ans)

Fixed submission:
h, w = map(int, input().rsplit())
S = [list(input().rstrip()) for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if S[i][j] == ".":
                L[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            L[i][j] += 1 + L[i][j - 1]
for i in range(h):
    for j in range(w):
        if i == 0:
            if S[i][j] == ".":
                U[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            U[i][j] += 1 + U[i - 1][j]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if j == w - 1:
            if S[i][j] == ".":
                R[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            R[i][j] += 1 + R[i][j + 1]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if i == h - 1:
            if S[i][j] == ".":
                D[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            D[i][j] += 1 + D[i + 1][j]
ans = 0
for i in range(h):
    for j in range(w):
        temp = D[i][j] + U[i][j] + L[i][j] + R[i][j] - 3
        ans = max(temp, ans)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
w+=2
h+=2
grid='#'*w
for _ in range(h-2):
    grid+='#'+input()+'#'
grid+='#'*w
move=[1,-1,w,-w]
score_a=[0]*(h*w)
score_b=[0]*(h*w)
score_c=[0]*(h*w)
score_d=[0]*(h*w)

for i in range(h*w):
    if grid[i]=='#':
        score_a[i]=0
        score_b[i]=0
    else:
        if i-1>=0 and i-1<=h*w-1:
            score_a[i]+=score_a[i-1]+1
        if i-w>=0 and i-w<=h*w-1:
            score_b[i]+=score_b[i-w]+1
    if grid[h*w-1-i]=='#':
        score_c[h*w-1-i]=0
        score_d[h*w-1-i]=0
    else:
        if h*w-1-i+1<=h*w-1 and h*w-1-i+1>=0:
            score_c[h*w-1-i]+=score_c[h*w-1-i+1]+1
        if h*w-1-i+w<=h*w-1 and h*w-1-i+w>=0:
            score_d[h*w-1-i]+=score_d[h*w-1-i+w]+1
ans=0
for i in range(h*w):
    ans=max(ans, score_a[i]+score_b[i]+score_c[i]+score_d[i]-3)
print(ans)

Fixed submission:
h, w = map(int, input().rsplit())
S = [list(input().rstrip()) for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if S[i][j] == ".":
                L[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            L[i][j] += 1 + L[i][j - 1]
for i in range(h):
    for j in range(w):
        if i == 0:
            if S[i][j] == ".":
                U[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            U[i][j] += 1 + U[i - 1][j]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if j == w - 1:
            if S[i][j] == ".":
                R[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            R[i][j] += 1 + R[i][j + 1]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if i == h - 1:
            if S[i][j] == ".":
                D[i][j] = 1
            continue
        if S[i][j] == "#":
            continue
        else:
            D[i][j] += 1 + D[i + 1][j]
ans = 0
for i in range(h):
    for j in range(w):
        temp = D[i][j] + U[i][j] + L[i][j] + R[i][j] - 3
        ans = max(temp, ans)
print(ans)