Buggy python submission (verdict: Time Limit Exceeded):
h,w = (int(x) for x in input().split())
ab = []
count = 0
for _ in range(h):
    a = input()
    a = a+'#'
    ab.append(list(a))
ab.append(list('#'*w))
mx = 0

for i in range(h):
    for j in range(w):
        if ab[i][j] == '.':
            dp = [[0 for a in range(w)] for b in range(h)]
            dp[i][j] = 1
            count = 1 
            step = []

            y, x = i, j
            if ab[y+1][x] == '.' :
                step.append([y+1, x])
                dp[y+1][x] = 1
                count += 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1+1][x1] == '.' :
                        step.append([y1+1, x1])
                        dp[y1+1][x1] = 1
                        count += 1 
                        
            if ab[y][x+1] == '.' :
                step.append([y, x+1])
                dp[y][x+1] = 1
                count += 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1][x1+1] == '.' :
                        step.append([y1, x1+1])
                        dp[y1][x1+1] = 1
                        count += 1
            if ab[y-1][x] == '.' :
                step.append([y-1, x])
                dp[y-1][x] = 1
                count += 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1-1][x1] == '.' :
                        step.append([y1-1, x1])
                        dp[y1-1][x1] = 1
                        count += 1
            if ab[y][x-1] == '.' :
                step.append([y, x-1])
                dp[y][x-1] = 1
                count += 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1][x1-1] == '.' :
                        step.append([y1, x1-1])
                        dp[y1][x1-1] = 1
                        count += 1

            mx = max([mx, count])
            #print(mx, i, j)

print(mx)

Fixed submission:
H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools
    
h,w = (int(x) for x in input().split())
ab = []
count = 0
for _ in range(h):
    a = input()
    a = a+'#'
    ab.append(list(a))
ab.append(list('#'*w))
mx = 0

for i in range(h):
    for j in range(w):
        if ab[i][j] == '.':
            dp = [[0 for a in range(w)] for b in range(h)]
            dp[i][j] = 1
            step = []

            y, x = i, j
            if ab[y+1][x] == '.' :
                step.append([y+1, x])
                dp[y+1][x] = 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1+1][x1] == '.' :
                        step.append([y1+1, x1])
                        dp[y1+1][x1] = 1
                        
            if ab[y][x+1] == '.' :
                step.append([y, x+1])
                dp[y][x+1] = 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1][x1+1] == '.' :
                        step.append([y1, x1+1])
                        dp[y1][x1+1] = 1
            if ab[y-1][x] == '.' :
                step.append([y-1, x])
                dp[y-1][x] = 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1-1][x1] == '.' :
                        step.append([y1-1, x1])
                        dp[y1-1][x1] = 1
            if ab[y][x-1] == '.' :
                step.append([y, x-1])
                dp[y][x-1] = 1
                while len(step)>0:
                    y1,x1=step.pop()
                    if ab[y1][x1-1] == '.' :
                        step.append([y1, x1-1])
                        dp[y1][x1-1] = 1
            #print(dp)

            mx = max([mx, sum(list(itertools.chain.from_iterable(dp)))])
            #print(mx, i, j)

print(mx)

Fixed submission:
H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)