Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

U = [[0] * W for h in range(H)]
D = [[0] * W for h in range(H)]
L = [[0] * W for h in range(H)]
R = [[0] * W for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == 1:
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            U[h][w] = 0
        else:
            U[h][w] = U[h-1][w] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            L[h][w] = 0
        else:
            L[h][w] = L[h][w-1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == 1:
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            D[h][w] = 0
        else:
            D[h][w] = D[h+1][w] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            R[h][w] = 0
        else:
            R[h][w] = R[h][w+1] + 1

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        cnt = U[h][w] + L[h][w] + D[h][w] + R[h][w] + 1
        if cnt > ans:
            ans = cnt

print(ans)


Fixed submission:
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

U = [[0] * W for h in range(H)]
D = [[0] * W for h in range(H)]
L = [[0] * W for h in range(H)]
R = [[0] * W for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == 1:
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            U[h][w] = 0
        else:
            U[h][w] = U[h-1][w] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            L[h][w] = 0
        else:
            L[h][w] = L[h][w-1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == 1:
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            D[h][w] = 0
        else:
            D[h][w] = D[h+1][w] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            R[h][w] = 0
        else:
            R[h][w] = R[h][w+1] + 1

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        cnt = U[h][w] + L[h][w] + D[h][w] + R[h][w] + 1
        if cnt > ans:
            ans = cnt

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

b = [[[0, 0, 0, 0] for w in range(W)] for h in range(H)]
m = [[0]*W for i in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            m[h][w] = 1

for h in range(H):
    for w in range(W):
        if m[h][w] == 1:
            continue
        # up
        if h-1 < 0 or m[h-1][w] == 1:
            b[h][w][0] = 0
        else:
            b[h][w][0] = b[h-1][w][0] + 1
        # left
        if w-1 < 0 or m[h][w-1] == 1:
            b[h][w][1] = 0
        else:
            b[h][w][1] = b[h][w-1][1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if m[h][w] == 1:
            continue
        # down
        if h+1 >= H or m[h+1][w] == 1:
            b[h][w][2] = 0
        else:
            b[h][w][2] = b[h+1][w][2] + 1
        # right
        if w+1 >= W or m[h][w+1] == 1:
            b[h][w][3] = 0
        else:
            b[h][w][3] = b[h][w+1][3] + 1

#for h in range(H):
#    print(b[h])
ans = 0
for h in range(H):
    for w in range(W):
        if m[h][w] == 1:
            continue
        tmp = sum(b[h][w]) + 1
        if tmp > ans:
            ans = tmp

print(ans)


Fixed submission:
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

U = [[0] * W for h in range(H)]
D = [[0] * W for h in range(H)]
L = [[0] * W for h in range(H)]
R = [[0] * W for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == 1:
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            U[h][w] = 0
        else:
            U[h][w] = U[h-1][w] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            L[h][w] = 0
        else:
            L[h][w] = L[h][w-1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == 1:
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            D[h][w] = 0
        else:
            D[h][w] = D[h+1][w] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            R[h][w] = 0
        else:
            R[h][w] = R[h][w+1] + 1

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        cnt = U[h][w] + L[h][w] + D[h][w] + R[h][w] + 1
        if cnt > ans:
            ans = cnt

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

b = [[[0, 0, 0, 0] for w in range(W)] for h in range(H)]
m = [[0]*W for i in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            m[h][w] = 1

for h in range(H):
    for w in range(W):
        if m[h][w] == 1:
            continue
        # up
        if h-1 < 0 or m[h-1][w] == 1:
            b[h][w][0] = 0
        else:
            b[h][w][0] = b[h-1][w][0] + 1
        # left
        if w-1 < 0 or m[h][w-1] == 1:
            b[h][w][1] = 0
        else:
            b[h][w][1] = b[h][w-1][1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if m[h][w] == 1:
            continue
        # down
        if h+1 >= H or m[h+1][w] == 1:
            b[h][w][2] = 0
        else:
            b[h][w][2] = b[h+1][w][2] + 1
        # right
        if w+1 >= W or m[h][w+1] == 1:
            b[h][w][3] = 0
        else:
            b[h][w][3] = b[h][w+1][3] + 1

#for h in range(H):
#    print(b[h])
ans = 0
for h in range(H):
    for w in range(W):
        if m[h][w] == 1:
            continue
        tmp = sum(b[h][w]) + 1
        if tmp > ans:
            ans = tmp

print(ans)


Fixed submission:
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

U = [[0] * W for h in range(H)]
D = [[0] * W for h in range(H)]
L = [[0] * W for h in range(H)]
R = [[0] * W for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == 1:
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            U[h][w] = 0
        else:
            U[h][w] = U[h-1][w] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            L[h][w] = 0
        else:
            L[h][w] = L[h][w-1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == 1:
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            D[h][w] = 0
        else:
            D[h][w] = D[h+1][w] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            R[h][w] = 0
        else:
            R[h][w] = R[h][w+1] + 1

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        cnt = U[h][w] + L[h][w] + D[h][w] + R[h][w] + 1
        if cnt > ans:
            ans = cnt

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

b = [[[0, 0, 0, 0] for w in range(W)] for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            b[h][w][0] = 0
        else:
            b[h][w][0] = b[h-1][w][0] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            b[h][w][1] = 0
        else:
            b[h][w][1] = b[h][w-1][1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == '#':
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            b[h][w][2] = 0
        else:
            b[h][w][2] = b[h+1][w][2] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            b[h][w][3] = 0
        else:
            b[h][w][3] = b[h][w+1][3] + 1

#for h in range(H):
#    print(b[h])
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        tmp = sum(b[h][w]) + 1
        if tmp > ans:
            ans = tmp

print(ans)


Fixed submission:
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

U = [[0] * W for h in range(H)]
D = [[0] * W for h in range(H)]
L = [[0] * W for h in range(H)]
R = [[0] * W for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == 1:
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            U[h][w] = 0
        else:
            U[h][w] = U[h-1][w] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            L[h][w] = 0
        else:
            L[h][w] = L[h][w-1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == 1:
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            D[h][w] = 0
        else:
            D[h][w] = D[h+1][w] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            R[h][w] = 0
        else:
            R[h][w] = R[h][w+1] + 1

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        cnt = U[h][w] + L[h][w] + D[h][w] + R[h][w] + 1
        if cnt > ans:
            ans = cnt

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

b = [[[0, 0, 0, 0] for w in range(W)] for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            b[h][w][0] = 0
        else:
            b[h][w][0] = b[h-1][w][0] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            b[h][w][1] = 0
        else:
            b[h][w][1] = b[h][w-1][1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == '#':
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            b[h][w][2] = 0
        else:
            b[h][w][2] = b[h+1][w][2] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            b[h][w][3] = 0
        else:
            b[h][w][3] = b[h][w+1][3] + 1

#for h in range(H):
#    print(b[h])
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        tmp = sum(b[h][w]) + 1
        if tmp > ans:
            ans = tmp

print(ans)


Fixed submission:
H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

U = [[0] * W for h in range(H)]
D = [[0] * W for h in range(H)]
L = [[0] * W for h in range(H)]
R = [[0] * W for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == 1:
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            U[h][w] = 0
        else:
            U[h][w] = U[h-1][w] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            L[h][w] = 0
        else:
            L[h][w] = L[h][w-1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == 1:
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            D[h][w] = 0
        else:
            D[h][w] = D[h+1][w] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            R[h][w] = 0
        else:
            R[h][w] = R[h][w+1] + 1

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        cnt = U[h][w] + L[h][w] + D[h][w] + R[h][w] + 1
        if cnt > ans:
            ans = cnt

print(ans)