Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

#障害物がない直線経路を前計算しておく
L = [[0] * w for i in range(h)]
R = [[0] * w for i in range(h)]
U = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        temp_L = s[i][j]
        temp_R = s[i][-(j + 1)]
        temp_U = s[i][j]
        temp_D = s[-(i + 1)][j]

        if temp_L == '#':L[i][j] = 0
        else:
            if j == 0:L[i][j] = 1
            else:L[i][j] = L[i][j - 1] + 1

        if temp_R == '#':R[i][-(j + 1)] = 0
        else:
            if j == 0:R[i][-(j + 1)] = 1
            else:R[i][-(j + 1)] = R[i][-(j + 1) + 1] + 1

        if temp_U == '#':U[i][j] = 0
        else:
            if i == 0:U[i][j] = 1
            else:U[i][j] = U[i - 1][j] + 1

        if temp_D == '#':D[-(i + 1)][j] = 0
        else:
            if i == 0:D[-(i + 1)][j] = 1
            else:D[-(i + 1)][j] = D[-(i + 1) + 1][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        if ans < temp:ans = temp
print(ans)
#print(L,R,U,D,sep ='\n')

Fixed submission:
h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

L = [[0] * w for i in range(h)]
R = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]
U = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if s[i][j] == '.':
                L[i][j] = 1
            if s[i][- (j + 1)] =='.':
                R[i][- (j + 1)] = 1

        if j != 0:
            if s[i][j] == '.':
                L[i][j] = L[i][j - 1] + 1
            if s[i][- (j + 1)] == '.':
                R[i][- (j + 1)] = R[i][- (j + 1) + 1] + 1

        if i == 0:
            if s[i][j] == '.':
                U[i][j] = 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = 1
        if i != 0:
            if s[i][j] == '.':
                U[i][j] = U[i - 1][j] + 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = D[- (i + 1) + 1][j] + 1
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = R[i][j] + L[i][j] + D[i][j] + U[i][j] -3
        if ans < temp:ans = temp
        #print(temp)
print(ans)

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

from functools import lru_cache
from collections import deque
@lru_cache()
def dfs(i,j):
    q = deque()
    q.append((i, j, 0))

    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    cnt = 1

    while q:
        x, y, num = q.pop()
        if num == 0:
            for i in range(1,5):
                dx, dy = d[i-1]
                nx = x + dx
                ny = y + dy
                if not(0 <= nx < h and 0 <= ny < w):continue
                if s[nx][ny] == '#':continue
                q.append((nx, ny, i))
                cnt += 1

        else:
            nx = x + d[num-1][0]
            ny = y + d[num-1][1]
            if not(0 <= nx < h and 0 <= ny < w):continue
            if s[nx][ny] == '#':continue
            q.append((nx, ny, num))
            cnt += 1

    return cnt

h,w = map(int, input().split())
s = [list(input()) for i in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if ans == h + w -1:
            print(ans)
            exit()

        if s[i][j] == '#':continue
        temp = dfs(i, j)
        #print(temp,(i,j))
        if temp > ans:ans = temp

print(ans)

Fixed submission:
h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

L = [[0] * w for i in range(h)]
R = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]
U = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if s[i][j] == '.':
                L[i][j] = 1
            if s[i][- (j + 1)] =='.':
                R[i][- (j + 1)] = 1

        if j != 0:
            if s[i][j] == '.':
                L[i][j] = L[i][j - 1] + 1
            if s[i][- (j + 1)] == '.':
                R[i][- (j + 1)] = R[i][- (j + 1) + 1] + 1

        if i == 0:
            if s[i][j] == '.':
                U[i][j] = 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = 1
        if i != 0:
            if s[i][j] == '.':
                U[i][j] = U[i - 1][j] + 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = D[- (i + 1) + 1][j] + 1
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = R[i][j] + L[i][j] + D[i][j] + U[i][j] -3
        if ans < temp:ans = temp
        #print(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def dfs(i,j):
    q = deque()
    q.append((i, j, 0))

    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    cnt = 1

    while q:
        x, y, num = q.pop()
        if num == 0:
            for i in range(1,5):
                dx, dy = d[i-1]
                nx = x + dx
                ny = y + dy
                if not(0 <= nx < h and 0 <= ny < w):continue
                if s[nx][ny] == '#':continue
                q.append((nx, ny, i))
                cnt += 1

        else:
            nx = x + d[num-1][0]
            ny = y + d[num-1][1]
            if not(0 <= nx < h and 0 <= ny < w):continue
            if s[nx][ny] == '#':continue
            q.append((nx, ny, num))
            cnt += 1

    return cnt

h,w = map(int, input().split())
s = [list(input()) for i in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if ans == h + w -1:
            print(ans)
            exit()
            
        if s[i][j] == '#':continue
        temp = dfs(i, j)
        #print(temp,(i,j))
        if temp > ans:ans = temp

print(ans)

Fixed submission:
h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

L = [[0] * w for i in range(h)]
R = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]
U = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if s[i][j] == '.':
                L[i][j] = 1
            if s[i][- (j + 1)] =='.':
                R[i][- (j + 1)] = 1

        if j != 0:
            if s[i][j] == '.':
                L[i][j] = L[i][j - 1] + 1
            if s[i][- (j + 1)] == '.':
                R[i][- (j + 1)] = R[i][- (j + 1) + 1] + 1

        if i == 0:
            if s[i][j] == '.':
                U[i][j] = 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = 1
        if i != 0:
            if s[i][j] == '.':
                U[i][j] = U[i - 1][j] + 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = D[- (i + 1) + 1][j] + 1
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = R[i][j] + L[i][j] + D[i][j] + U[i][j] -3
        if ans < temp:ans = temp
        #print(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def dfs(i,j):
    q = deque()
    q.append((i, j, 0))

    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    cnt = 1

    while q:
        x, y, num = q.pop()
        if num == 0:
            for i in range(1,5):
                dx, dy = d[i-1]
                nx = x + dx
                ny = y + dy
                if not(0 <= nx < h and 0 <= ny < w):continue
                if s[nx][ny] == '#':continue
                q.append((nx, ny, i))
                cnt += 1

        else:
            nx = x + d[num-1][0]
            ny = y + d[num-1][1]
            if not(0 <= nx < h and 0 <= ny < w):continue
            if s[nx][ny] == '#':continue
            q.append((nx, ny, num))
            cnt += 1

    return cnt

h,w = map(int, input().split())
s = [list(input()) for i in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = dfs(i, j)
        #print(temp,(i,j))
        if temp > ans:ans = temp
print(ans)

Fixed submission:
h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

L = [[0] * w for i in range(h)]
R = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]
U = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if s[i][j] == '.':
                L[i][j] = 1
            if s[i][- (j + 1)] =='.':
                R[i][- (j + 1)] = 1

        if j != 0:
            if s[i][j] == '.':
                L[i][j] = L[i][j - 1] + 1
            if s[i][- (j + 1)] == '.':
                R[i][- (j + 1)] = R[i][- (j + 1) + 1] + 1

        if i == 0:
            if s[i][j] == '.':
                U[i][j] = 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = 1
        if i != 0:
            if s[i][j] == '.':
                U[i][j] = U[i - 1][j] + 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = D[- (i + 1) + 1][j] + 1
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = R[i][j] + L[i][j] + D[i][j] + U[i][j] -3
        if ans < temp:ans = temp
        #print(temp)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
def dfs(i,j):
    q = deque()
    q.append((i, j, 0))

    d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    cnt = 1

    while q:
        x, y, num = q.pop()
        if num == 0:
            for i in range(1,5):
                dx, dy = d[i-1]
                nx = x + dx
                ny = y + dy
                if not(0 <= nx < h and 0 <= ny < w):continue
                if s[nx][ny] == '#':continue
                q.append((nx, ny, i))
                cnt += 1

        else:
            nx = x + d[num-1][0]
            ny = y + d[num-1][1]
            if not(0 <= nx < h and 0 <= ny < w):continue
            if s[nx][ny] == '#':continue
            q.append((nx, ny, num))
            cnt += 1

    return cnt

h,w = map(int, input().split())
s = [list(input()) for i in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = dfs(i, j)
        #print(temp,(i,j))
        if temp > ans:ans = temp
print(ans)

Fixed submission:
h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

L = [[0] * w for i in range(h)]
R = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]
U = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if s[i][j] == '.':
                L[i][j] = 1
            if s[i][- (j + 1)] =='.':
                R[i][- (j + 1)] = 1

        if j != 0:
            if s[i][j] == '.':
                L[i][j] = L[i][j - 1] + 1
            if s[i][- (j + 1)] == '.':
                R[i][- (j + 1)] = R[i][- (j + 1) + 1] + 1

        if i == 0:
            if s[i][j] == '.':
                U[i][j] = 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = 1
        if i != 0:
            if s[i][j] == '.':
                U[i][j] = U[i - 1][j] + 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = D[- (i + 1) + 1][j] + 1
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = R[i][j] + L[i][j] + D[i][j] + U[i][j] -3
        if ans < temp:ans = temp
        #print(temp)
print(ans)