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

ans = 1
d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        cnt = 1
        for dy, dx in d:
            y = i + dy
            x = j + dx
            while 0 <= y < H and 0 <= x < W and S[y][x] == ".":
                cnt += 1
                y += dy
                x += dx
        ans = max(ans, cnt)

print(ans)


Fixed submission:
H, W = map(int, input().split())
S = []
for _ in range(H):
    s1 = input()
    S.append(s1)

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
for i in range(W):
    if S[0][i] == ".":
        U[0][i] = 1
    if S[H-1][i] == ".":
        D[H-1][i] = 1

for i in range(H):
    if S[i][0] == ".":
        L[i][0] = 1
    if S[i][W-1] == ".":
        R[i][W-1] = 1
     
for i in range(1,H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        U[i][j] = U[i-1][j] + 1
for i in range(H-1)[::-1]:
    for j in range(W):
        if S[i][j] == "#":
            continue
        D[i][j] = D[i+1][j] + 1
for i in range(H):
    for j in range(1,W):
        if S[i][j] == "#":
            continue
        L[i][j] = L[i][j-1] + 1
for i in range(H):
    for j in range(W-1)[::-1]:
        if S[i][j] == "#":
            continue
        R[i][j] = R[i][j+1] + 1
        
ans = 0

for i in range(H):
    for j in range(W):
        ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)
print(ans)

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

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
for i in range(W):
    if S[0][i] == ".":
        U[0][i] = 1
    if S[H-1][i] == ".":
        D[H-1][i] = 1

for i in range(H):
    if S[i][0] == ".":
        L[i][0] = 1
    if S[i][W-1] == ".":
        R[i][W-1] = 1
     
for i in range(1,H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        U[i][j] = U[i-1][j] + 1
for i in range(H-1)[::-1]:
    for j in range(W):
        if S[i][j] == "#":
            continue
        D[i][j] = D[i+1][j] + 1
for i in range(H):
    for j in range(1,W):
        if S[i][j] == "#":
            continue
        L[i][j] = L[i][j-1] + 1
for i in range(H):
    for j in range(W-1)[::-1]:
        if S[i][j] == "#":
            continue
        R[i][j] = R[i][j+1] + 1
        
ans = 0

for i in range(H):
    for j in range(W):
        ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)
print(ans)
        

Fixed submission:
H, W = map(int, input().split())
S = []
for _ in range(H):
    s1 = input()
    S.append(s1)

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
for i in range(W):
    if S[0][i] == ".":
        U[0][i] = 1
    if S[H-1][i] == ".":
        D[H-1][i] = 1

for i in range(H):
    if S[i][0] == ".":
        L[i][0] = 1
    if S[i][W-1] == ".":
        R[i][W-1] = 1
     
for i in range(1,H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        U[i][j] = U[i-1][j] + 1
for i in range(H-1)[::-1]:
    for j in range(W):
        if S[i][j] == "#":
            continue
        D[i][j] = D[i+1][j] + 1
for i in range(H):
    for j in range(1,W):
        if S[i][j] == "#":
            continue
        L[i][j] = L[i][j-1] + 1
for i in range(H):
    for j in range(W-1)[::-1]:
        if S[i][j] == "#":
            continue
        R[i][j] = R[i][j+1] + 1
        
ans = 0

for i in range(H):
    for j in range(W):
        ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)
print(ans)

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

ans = 1
d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        cnt = 1
        for dy, dx in d:
            y = i + dy
            x = j + dx
            while 0 <= y < H and 0 <= x < W and S[y][x] == ".":
                cnt += 1
                y += dy
                x += dx
        ans = max(ans, cnt)

print(ans)

Fixed submission:
H, W = map(int, input().split())
S = []
for _ in range(H):
    s1 = input()
    S.append(s1)

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
for i in range(W):
    if S[0][i] == ".":
        U[0][i] = 1
    if S[H-1][i] == ".":
        D[H-1][i] = 1

for i in range(H):
    if S[i][0] == ".":
        L[i][0] = 1
    if S[i][W-1] == ".":
        R[i][W-1] = 1
     
for i in range(1,H):
    for j in range(W):
        if S[i][j] == "#":
            continue
        U[i][j] = U[i-1][j] + 1
for i in range(H-1)[::-1]:
    for j in range(W):
        if S[i][j] == "#":
            continue
        D[i][j] = D[i+1][j] + 1
for i in range(H):
    for j in range(1,W):
        if S[i][j] == "#":
            continue
        L[i][j] = L[i][j-1] + 1
for i in range(H):
    for j in range(W-1)[::-1]:
        if S[i][j] == "#":
            continue
        R[i][j] = R[i][j+1] + 1
        
ans = 0

for i in range(H):
    for j in range(W):
        ans = max(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)
print(ans)