Buggy python submission (verdict: Time Limit Exceeded):
# ABC129D - Lamp
def main():
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1 in range(H):
        for y1 in range(W):
            if S[x1][y1] == ".":  # left and upper sides of S
                U[x1][y1] = U[x1 - 1][y1] + 1
                L[x1][y1] = L[x1][y1 - 1] + 1
            x2, y2 = -x1 - 1, -y1 - 1
            if S[x2][y2] == ".":  # right and under sides
                D[x2][y2] = D[x2 + 1][y2] + 1
                R[x2][y2] = R[x2][y2 + 1] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i][j] == 0
                U[i][j] == 0
            else:
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            if S[i][j] == "#":
                R[i][j] == 0
                D[i][j] == 0
            else:
                if j == W - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1

                if i == H - 1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i + 1][j] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i][j] == 0
                U[i][j] == 0
            else:
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            if S[i][j] == "#":
                R[i][j] == 0
                D[i][j] == 0
            else:
                if j == W - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1

                if i == H - 1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i + 1][j] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i][j] == 0
                U[i][j] == 0
            else:
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            if S[i][j] == "#":
                R[i][j] == 0
                D[i][j] == 0
            else:
                if j == W - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1

                if i == H - 1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i + 1][j] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    # T = tuple(zip(*S))  # slice S vertically
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i][j] == 0
            else:
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1
    for i in range(H):
        for j in range(W - 1, -1, -1):
            if S[i][j] == "#":
                R[i][j] == 0
            else:
                if j == W - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                U[i][j] == 0
            else:
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1
    for i in range(H - 1, -1, -1):
        for j in range(W):
            if S[i][j] == "#":
                D[i][j] == 0
            else:
                if i == H - 1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i + 1][j] + 1

    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i][j] == 0
                U[i][j] == 0
            else:
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            if S[i][j] == "#":
                R[i][j] == 0
                D[i][j] == 0
            else:
                if j == W - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1

                if i == H - 1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i + 1][j] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()