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

Light = [[[0, 0]for _ in range(W)] for __ in range(H)]


for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            continue
        if Light[i][j][0] == 0:
            num = 0
            while True:
                num += 1
                if i + num >= H:
                    break
                if maze[i+num][j] == '#':
                    break
            for k in range(num):
                Light[i+k][j][0] = num


        if Light[i][j][1] == 0:
            num = 0
            while True:
                num += 1
                if j + num >= W:
                    break
                if maze[i][j + num] == '#':
                    break
            for k in range(num):
                Light[i][j+k][1] = num

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, Light[i][j][0] + Light[i][j][1])
print(ans-1)


Fixed submission:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
Ans = [[[-1, -1]for __ in range(W)] for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        else:
            if Ans[i-1][j][0] != -1:
                Ans[i][j][0] = Ans[i-1][j][0]
            else:
                num0 = 0
                while True:
                    num0 += 1
                    if i + num0 >= H:
                        break
                    elif S[i+num0][j] == '#':
                        break
                Ans[i][j][0] = num0

            if Ans[i][j-1][1] != -1:
                Ans[i][j][1] = Ans[i][j-1][1]
            else:
                num1 = 0
                while True:
                    num1 += 1
                    if j + num1 >= W:
                        break
                    elif S[i][j+num1] == '#':
                        break
                Ans[i][j][1] = num1

        ans = max(ans, sum(Ans[i][j]))
print(ans-1)

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

Light = [[[0, 0]for _ in range(W)] for __ in range(H)]


for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            continue
        if Light[i][j][0] == 0:
            num = 0
            while True:
                num += 1
                if i + num >= H:
                    break
                if maze[i+num][j] == '#':
                    break
            for k in range(num):
                Light[i+k][j][0] = num


        if Light[i][j][1] == 0:
            num = 0
            while True:
                num += 1
                if j + num >= W:
                    break
                if maze[i][j + num] == '#':
                    break
            for k in range(num):
                Light[i][j+k][1] = num

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, Light[i][j][0] + Light[i][j][1])
print(ans-1)


Fixed submission:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
Ans = [[[-1, -1]for __ in range(W)] for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        else:
            if Ans[i-1][j][0] != -1:
                Ans[i][j][0] = Ans[i-1][j][0]
            else:
                num0 = 0
                while True:
                    num0 += 1
                    if i + num0 >= H:
                        break
                    elif S[i+num0][j] == '#':
                        break
                Ans[i][j][0] = num0

            if Ans[i][j-1][1] != -1:
                Ans[i][j][1] = Ans[i][j-1][1]
            else:
                num1 = 0
                while True:
                    num1 += 1
                    if j + num1 >= W:
                        break
                    elif S[i][j+num1] == '#':
                        break
                Ans[i][j][1] = num1

        ans = max(ans, sum(Ans[i][j]))
print(ans-1)