Buggy python submission (verdict: Time Limit Exceeded):
import sys

input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    S = [None] * (H + 2)
    S[0] = S[-1] = "#" * (W + 2)
    for i in range(1, H + 1):
        S[i] = "".join(["#", input().rstrip(), "#"])

    U = [[-1] * (W + 2) for _ in range(H + 2)]
    D = [[-1] * (W + 2) for _ in range(H + 2)]
    L = [[-1] * (W + 2) for _ in range(H + 2)]
    R = [[-1] * (W + 2) for _ in range(H + 2)]
    for h in range(1, H + 1):
        for w in range(1, W + 1):
            if S[h][w] == "#":
                continue
            if U[h][w] == -1:
                U[h][w] = 0
                d = 0
                while True:
                    d += 1
                    if S[h + d][w] == "#":
                        break
                    U[h + d][w] = d
            if L[h][w] == -1:
                L[h][w] = 0
                d = 0
                while True:
                    d += 1
                    if S[h][w + d] == "#":
                        break
                    L[h][w + d] = d

    for h in reversed(range(1, H + 1)):
        for w in reversed(range(1, W + 1)):
            if S[h][w] == "#":
                continue
            if D[h][w] == -1:
                D[h][w] = 0
                d = 0
                while True:
                    d += 1
                    if S[h - d][w] == "#":
                        break
                    D[h - d][w] = d
            if R[h][w] == -1:
                R[h][w] = 0
                d = 0
                while True:
                    d += 1
                    if S[h][w - d] == "#":
                        break
                    R[h][w - d] = d

    ans = 0
    for h in range(1, H + 1):
        for w in range(1, W + 1):
            dist = U[h][w] + D[h][w] + L[h][w] + R[h][w] + 1
            if ans < dist:
                ans = dist

    print(ans)


if __name__ == "__main__":
    main()


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

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

# up and left
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            up[h][w] = 0
            left[h][w] = 0
        else:
            # up
            if h == 0:
                up[h][w] = 1
            else:
                up[h][w] = up[h - 1][w] + 1
            # left
            if w == 0:
                left[h][w] = 1
            else:
                left[h][w] = left[h][w - 1] + 1

# down and right
for h in reversed(range(H)):
    for w in reversed(range(W)):
        if S[h][w] == "#":
            down[h][w] = 0
            right[h][w] = 0
        else:
            # down
            if h == H - 1:
                down[h][w] = 1
            else:
                down[h][w] = down[h + 1][w] + 1
            # right
            if w == W - 1:
                right[h][w] = 1
            else:
                right[h][w] = right[h][w + 1] + 1


ans = 0
for h in range(H):
    for w in range(W):
        masu = -3
        masu += up[h][w]
        masu += down[h][w]
        masu += left[h][w]
        masu += right[h][w]
        if masu > ans:
            ans = masu

print(ans)

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

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

# up and left
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            up[h][w] = 0
            left[h][w] = 0
        else:
            # up
            if h == 0:
                up[h][w] = 1
            else:
                up[h][w] = up[h - 1][w] + 1
            # left
            if w == 0:
                left[h][w] = 1
            else:
                left[h][w] = left[h][w - 1] + 1

# down and right
for h in reversed(range(H)):
    for w in reversed(range(W)):
        if S[h][w] == "#":
            down[h][w] = 0
            right[h][w] = 0
        else:
            # down
            if h == H - 1:
                down[h][w] = 1
            else:
                down[h][w] = down[h + 1][w] + 1
            # right
            if w == W - 1:
                right[h][w] = 1
            else:
                right[h][w] = right[h][w + 1] + 1


ans = 0
for h in range(H):
    for w in range(W):
        masu = -3
        masu += up[h][w]
        masu += down[h][w]
        masu += left[h][w]
        masu += right[h][w]
        if masu > ans:
            ans = masu

print(ans)


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

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

# up and left
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            up[h][w] = 0
            left[h][w] = 0
        else:
            # up
            if h == 0:
                up[h][w] = 1
            else:
                up[h][w] = up[h - 1][w] + 1
            # left
            if w == 0:
                left[h][w] = 1
            else:
                left[h][w] = left[h][w - 1] + 1

# down and right
for h in reversed(range(H)):
    for w in reversed(range(W)):
        if S[h][w] == "#":
            down[h][w] = 0
            right[h][w] = 0
        else:
            # down
            if h == H - 1:
                down[h][w] = 1
            else:
                down[h][w] = down[h + 1][w] + 1
            # right
            if w == W - 1:
                right[h][w] = 1
            else:
                right[h][w] = right[h][w + 1] + 1


ans = 0
for h in range(H):
    for w in range(W):
        masu = -3
        masu += up[h][w]
        masu += down[h][w]
        masu += left[h][w]
        masu += right[h][w]
        if masu > ans:
            ans = masu

print(ans)

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

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

for h in range(H):
  for w in range(W):
    # up
    if h-1 >= 0:
      if S[h-1][w] == "#":
        up[h][w] = 0
      else:
        up[h][w] = up[h-1][w] + 1
    # left
    if w-1 >= 0:
      if S[h][w-1] == "#":
        left[h][w] = 0
      else:
        left[h][w] = left[h][w-1] + 1

    _h = H-1-h
    _w = W-1-w
    # down
    if _h+1 <= H-1:
      if S[_h+1][_w] == "#":
        down[_h][_w] = 0
      else:
        down[_h][_w] = down[_h+1][_w] + 1
    # right
    if _w+1 <= W-1:
      if S[_h][_w+1] == "#":
        right[_h][_w] = 0
      else:
        right[_h][_w] = right[_h][_w+1] + 1

ans = 0
for h in range(H):
  for w in range(W):
    if S[h][w] == "#":
      continue
    masu = 1
    masu += up[h][w]
    masu += down[h][w]
    masu += left[h][w]
    masu += right[h][w]
    if masu > ans:
      ans = masu

print(ans)


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

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

# up and left
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            up[h][w] = 0
            left[h][w] = 0
        else:
            # up
            if h == 0:
                up[h][w] = 1
            else:
                up[h][w] = up[h - 1][w] + 1
            # left
            if w == 0:
                left[h][w] = 1
            else:
                left[h][w] = left[h][w - 1] + 1

# down and right
for h in reversed(range(H)):
    for w in reversed(range(W)):
        if S[h][w] == "#":
            down[h][w] = 0
            right[h][w] = 0
        else:
            # down
            if h == H - 1:
                down[h][w] = 1
            else:
                down[h][w] = down[h + 1][w] + 1
            # right
            if w == W - 1:
                right[h][w] = 1
            else:
                right[h][w] = right[h][w + 1] + 1


ans = 0
for h in range(H):
    for w in range(W):
        masu = -3
        masu += up[h][w]
        masu += down[h][w]
        masu += left[h][w]
        masu += right[h][w]
        if masu > ans:
            ans = masu

print(ans)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
S = [None] * H
for i in range(H):
  S[i] = input()

# direction definition
# 0: up
# 1: down
# 2: left
# 3: right
grid = [[[-1, -1, -1, -1] for w in range(W)] for h in range(H)]

# Initialize top and bottom sides
for w in range(W):
  grid[0][w][0] = 1
  grid[H-1][w][1] = 1

# Initialize left and right sides
for h in range(H):
  grid[h][0][2] = 1
  grid[h][W-1][3] = 1

# height, width, direction
def dfs(h, w, d):
  if not (0<=h<=H-1 and 0<=w<=W-1):
    return 0
  
  if S[h][w] == "#":
    grid[h][w] = [0, 0, 0, 0]
    return 0

  # up
  if d == 0:
    if grid[h][w][d] == -1:
      grid[h][w][d] = 1 + dfs(h-1, w, d)
    return grid[h][w][d]
  # down
  elif d == 1:
    if grid[h][w][d] == -1:
      grid[h][w][d] = 1 + dfs(h+1, w, d)
    return grid[h][w][d]
  # left
  elif d == 2:
    if grid[h][w][d] == -1:
      grid[h][w][d] = 1 + dfs(h, w-1, d)
    return grid[h][w][d]
  # right
  elif d == 3:
    if grid[h][w][d] == -1:
      grid[h][w][d] = 1 + dfs(h, w+1, d)
    return grid[h][w][d]

ans = 0
for h in range(H):
  for w in range(W):
    if S[h][w] == ".":
      count = 1
      count += dfs(h-1, w, 0)
      count += dfs(h+1, w, 1)
      count += dfs(h, w-1, 2)
      count += dfs(h, w+1, 3)
      if count >= ans:
        ans = count
    
print(ans)


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

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

# up and left
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            up[h][w] = 0
            left[h][w] = 0
        else:
            # up
            if h == 0:
                up[h][w] = 1
            else:
                up[h][w] = up[h - 1][w] + 1
            # left
            if w == 0:
                left[h][w] = 1
            else:
                left[h][w] = left[h][w - 1] + 1

# down and right
for h in reversed(range(H)):
    for w in reversed(range(W)):
        if S[h][w] == "#":
            down[h][w] = 0
            right[h][w] = 0
        else:
            # down
            if h == H - 1:
                down[h][w] = 1
            else:
                down[h][w] = down[h + 1][w] + 1
            # right
            if w == W - 1:
                right[h][w] = 1
            else:
                right[h][w] = right[h][w + 1] + 1


ans = 0
for h in range(H):
    for w in range(W):
        masu = -3
        masu += up[h][w]
        masu += down[h][w]
        masu += left[h][w]
        masu += right[h][w]
        if masu > ans:
            ans = masu

print(ans)