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

left = [[-1 for j in range(W)] for i in range(H)]
right = [[W for j in range(W)] for i in range(H)]
up = [[-1 for j in range(W)] for i in range(H)]
down = [[H for j in range(W)] for i in range(H)]

# from left upper to right down
up_wall = [-1 for i in range(W)]
for h in range(H):
    left_wall = -1    
    for w in range(W):
        if S[h][w] == '#':
            left_wall = w
            up_wall[w] = h
        left[h][w] = left_wall
        up[h][w] = up_wall[w]

# from right down to left up
down_wall = [H for i in range(W)]
for h in range(H - 1, -1, -1):
    right_wall = W
    for w in range(W - 1, -1, -1):
        if S[h][w] == '#':
            right_wall = w
            down_wall[w] = h
        right[h][w] = right_wall
        down[h][w] = down_wall[w]

# print(left)
# print(right)
# print(up)
# print(down)

max_score = 0
for h in range(H):
    for w in range(W):
        left_score = (w - left[h][w])
        right_score = (right[h][w] - w)
        up_score = (h - up[h][w])
        down_score = (down[h][w] - h)
        score = left_score + right_score + up_score + down_score - 3
        # print(h, w, score, left_score, right_score, up_score, down_score)
        if max_score < score:
            max_score = score
print(max_score)

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

left = [[-1 for j in range(W)] for i in range(H)]
right = [[W for j in range(W)] for i in range(H)]
up = [[-1 for j in range(W)] for i in range(H)]
down = [[H for j in range(W)] for i in range(H)]

# from left upper to right down
up_wall = [-1 for i in range(W)]
for h in range(H):
    left_wall = -1    
    for w in range(W):
        if S[h][w] == '#':
            left_wall = w
            up_wall[w] = h
        left[h][w] = left_wall
        up[h][w] = up_wall[w]

# from right down to left up
down_wall = [H for i in range(W)]
for h in range(H - 1, -1, -1):
    right_wall = W
    for w in range(W - 1, -1, -1):
        if S[h][w] == '#':
            right_wall = w
            down_wall[w] = h
        right[h][w] = right_wall
        down[h][w] = down_wall[w]

# print(left)
# print(right)
# print(up)
# print(down)

max_score = 0
for h in range(H):
    for w in range(W):
        left_score = (w - left[h][w])
        right_score = (right[h][w] - w)
        up_score = (h - up[h][w])
        down_score = (down[h][w] - h)
        score = left_score + right_score + up_score + down_score - 3
        # print(h, w, score, left_score, right_score, up_score, down_score)
        if max_score < score:
            max_score = score
print(max_score)

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

yoko = {}
tate = {}
tate_counter = [0 for i in range(W)]
for h in range(H):
    yoko_counter = 0
    for w in range(W):
        if S[h][w] == '#':
            for i in range(yoko_counter):
                yoko[(h, w - i - 1)] = yoko_counter
            for i in range(tate_counter[w]):
                tate[(h - i - 1, w)] = tate_counter[w]
            yoko_counter = 0
            tate_counter[w] = 0
            continue
        yoko_counter += 1
        tate_counter[w] += 1
    if yoko_counter > 0:
        for i in range(yoko_counter):
            yoko[(h, W - i - 1)] = yoko_counter
for w in range(W):
    if tate_counter[w] > 0:
        for i in range(tate_counter[w]):        
            tate[(H - i - 1, w)] = tate_counter[w]


max_score = 0
for h in range(H):
    for w in range(W):
        if (h,w) in yoko and (h,w) in tate:
            score = yoko[(h,w)] + tate[(h,w)] - 1
            if max_score < score:
                #print(h,w, score)
                max_score = score

print(max_score)


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

left = [[-1 for j in range(W)] for i in range(H)]
right = [[W for j in range(W)] for i in range(H)]
up = [[-1 for j in range(W)] for i in range(H)]
down = [[H for j in range(W)] for i in range(H)]

# from left upper to right down
up_wall = [-1 for i in range(W)]
for h in range(H):
    left_wall = -1    
    for w in range(W):
        if S[h][w] == '#':
            left_wall = w
            up_wall[w] = h
        left[h][w] = left_wall
        up[h][w] = up_wall[w]

# from right down to left up
down_wall = [H for i in range(W)]
for h in range(H - 1, -1, -1):
    right_wall = W
    for w in range(W - 1, -1, -1):
        if S[h][w] == '#':
            right_wall = w
            down_wall[w] = h
        right[h][w] = right_wall
        down[h][w] = down_wall[w]

# print(left)
# print(right)
# print(up)
# print(down)

max_score = 0
for h in range(H):
    for w in range(W):
        left_score = (w - left[h][w])
        right_score = (right[h][w] - w)
        up_score = (h - up[h][w])
        down_score = (down[h][w] - h)
        score = left_score + right_score + up_score + down_score - 3
        # print(h, w, score, left_score, right_score, up_score, down_score)
        if max_score < score:
            max_score = score
print(max_score)

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

yoko = {}
tate = {}
tate_counter = [0 for i in range(W)]
for h in range(H):
    yoko_counter = 0
    for w in range(W):
        if S[h][w] == '#':
            for i in range(yoko_counter):
                yoko[(h, w - i - 1)] = yoko_counter
            for i in range(tate_counter[w]):
                tate[(h - i - 1, w)] = tate_counter[w]
            yoko_counter = 0
            tate_counter[w] = 0
            continue
        yoko_counter += 1
        tate_counter[w] += 1
    if yoko_counter > 0:
        for i in range(yoko_counter):
            yoko[(h, W - i - 1)] = yoko_counter
for w in range(W):
    if tate_counter[w] > 0:
        for i in range(tate_counter[w]):        
            tate[(H - i - 1, w)] = tate_counter[w]


max_score = 0
for h in range(H):
    for w in range(W):
        if (h,w) in yoko and (h,w) in tate:
            score = yoko[(h,w)] + tate[(h,w)] - 1
            if max_score < score:
                #print(h,w, score)
                max_score = score

print(max_score)

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

left = [[-1 for j in range(W)] for i in range(H)]
right = [[W for j in range(W)] for i in range(H)]
up = [[-1 for j in range(W)] for i in range(H)]
down = [[H for j in range(W)] for i in range(H)]

# from left upper to right down
up_wall = [-1 for i in range(W)]
for h in range(H):
    left_wall = -1    
    for w in range(W):
        if S[h][w] == '#':
            left_wall = w
            up_wall[w] = h
        left[h][w] = left_wall
        up[h][w] = up_wall[w]

# from right down to left up
down_wall = [H for i in range(W)]
for h in range(H - 1, -1, -1):
    right_wall = W
    for w in range(W - 1, -1, -1):
        if S[h][w] == '#':
            right_wall = w
            down_wall[w] = h
        right[h][w] = right_wall
        down[h][w] = down_wall[w]

# print(left)
# print(right)
# print(up)
# print(down)

max_score = 0
for h in range(H):
    for w in range(W):
        left_score = (w - left[h][w])
        right_score = (right[h][w] - w)
        up_score = (h - up[h][w])
        down_score = (down[h][w] - h)
        score = left_score + right_score + up_score + down_score - 3
        # print(h, w, score, left_score, right_score, up_score, down_score)
        if max_score < score:
            max_score = score
print(max_score)