Buggy python submission (verdict: Time Limit Exceeded):
2324
668
3648
182432
8168126


H, W = map(int, input().split())
S_list = [None] * H

for h in range(H):
    input_str = list(input())
    S_list[h] = [0 if char == '#' else 1 for char in input_str]


l_list = [[0] * W for _ in range(H)]
r_list = [[0] * W for _ in range(H)]
d_list = [[0] * W for _ in range(H)]
u_list = [[0] * W for _ in range(H)]
for h in range(H):
    for w in range(W):
        left_index = w
        right_index = W - w - 1
        up_index = h
        down_index = H - h - 1

        #left
        if left_index == 0:
            l_list[h][left_index] = S_list[h][left_index]
        else:
            l_list[h][left_index] = (l_list[h][left_index - 1] + 1) * S_list[h][left_index]

        #right
        if right_index == W - 1:
            r_list[h][right_index] = S_list[h][right_index]
        else:
            r_list[h][right_index] = (r_list[h][right_index + 1] + 1) * S_list[h][right_index]

        #up
        if up_index == 0:
            u_list[up_index][w] = S_list[up_index][w]
        else:
            u_list[up_index][w] = (u_list[up_index - 1][w] + 1) * S_list[up_index][w]

        #down
        if down_index == H - 1:
            d_list[down_index][w] = S_list[down_index][w]
        else:
            d_list[down_index][w] = (d_list[down_index + 1][w] + 1) * S_list[down_index][w]


max_light = 0
for h in range(H):
    for w in range(W):
        lights = l_list[h][w] + r_list[h][w] + u_list[h][w] + d_list[h][w] - 3
        max_light = max(max_light, lights)

print(max_light)


Fixed submission:
#ref. https://atcoder.jp/contests/abc129/submissions/5906191
import numpy as np
import sys

def main():
    sin = sys.stdin.buffer
    H, W = map(int, sin.readline().split())
    grid = np.frombuffer(sin.read(H * (W + 1)), dtype="B") == ord(".")
    grid = grid.reshape((H, W + 1))[:, :-1]

    L = np.empty((H, W), dtype="i4")
    R = np.empty((H, W), dtype="i4")
    T = np.empty((H, W), dtype="i4")
    B = np.empty((H, W), dtype="i4")

    T[0] = grid[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * grid[i]

    B[-1] = grid[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * grid[i]

    L[:, 0] = grid[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * grid[:, i]

    R[:, -1] = grid[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * grid[:, i]

    ans = (T + B + L + R - 3).max()
    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S_list = [None] * H

for h in range(H):
    S_list[h] = list(input())


l_list = [[0] * W for _ in range(H)]
r_list = [[0] * W for _ in range(H)]
d_list = [[0] * W for _ in range(H)]
u_list = [[0] * W for _ in range(H)]
for h in range(H):
    for w in range(W):
        left_index = w
        right_index = W - w - 1
        up_index = h
        down_index = H - h - 1

        #left
        if S_list[h][left_index] != '#':
            if left_index == 0:
                l_list[h][left_index] = 1
            else:
                l_list[h][left_index] = l_list[h][left_index - 1] + 1

        #right
        if S_list[h][right_index] != '#':
            if right_index == W - 1:
                r_list[h][right_index] = 1
            else:
                r_list[h][right_index] = r_list[h][right_index + 1] + 1

        #up
        if S_list[up_index][w] != '#':
            if up_index == 0:
                u_list[up_index][w] = 1
            else:
                u_list[up_index][w] = u_list[up_index - 1][w] + 1

        #down
        if S_list[down_index][w] != '#':
            if down_index == H - 1:
                d_list[down_index][w] = 1
            else:
                d_list[down_index][w] = d_list[down_index + 1][w] + 1


max_right = 0
for h in range(H):
    for w in range(W):
        rights = l_list[h][w] + r_list[h][w] + u_list[h][w] + d_list[h][w] - 3
        max_right = max(max_right, rights)

print(max_right)


Fixed submission:
#ref. https://atcoder.jp/contests/abc129/submissions/5906191
import numpy as np
import sys

def main():
    sin = sys.stdin.buffer
    H, W = map(int, sin.readline().split())
    grid = np.frombuffer(sin.read(H * (W + 1)), dtype="B") == ord(".")
    grid = grid.reshape((H, W + 1))[:, :-1]

    L = np.empty((H, W), dtype="i4")
    R = np.empty((H, W), dtype="i4")
    T = np.empty((H, W), dtype="i4")
    B = np.empty((H, W), dtype="i4")

    T[0] = grid[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * grid[i]

    B[-1] = grid[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * grid[i]

    L[:, 0] = grid[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * grid[:, i]

    R[:, -1] = grid[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * grid[:, i]

    ans = (T + B + L + R - 3).max()
    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S_list = [None] * H

for h in range(H):
    S_list[h] = list(input())


l_list = [[0] * W for _ in range(H)]
r_list = [[0] * W for _ in range(H)]
d_list = [[0] * W for _ in range(H)]
u_list = [[0] * W for _ in range(H)]
for h in range(H):
    #left
    for w in range(W):
        if S_list[h][w] == '#':
            continue
        elif w == 0:
            l_list[h][w] = 1
        else:
            l_list[h][w] = l_list[h][w - 1] + 1
    #right
    for w in reversed(range(W)):
        if S_list[h][w] == '#':
            continue
        elif w == W - 1:
            r_list[h][w] = 1
        else:
            r_list[h][w] = r_list[h][w + 1] + 1

for w in range(W):
    #up
    for h in range(H):
        if S_list[h][w] == '#':
            continue
        elif h == 0:
            u_list[h][w] = 1
        else:
            u_list[h][w] = u_list[h - 1][w] + 1
    #down
    for h in reversed(range(H)):
        if S_list[h][w] == '#':
            continue
        elif h == H - 1:
            d_list[h][w] = 1
        else:
            d_list[h][w] = d_list[h + 1][w] + 1


max_right = 0
for h in range(H):
    for w in range(W):
        rights = l_list[h][w] + r_list[h][w] + u_list[h][w] + d_list[h][w] - 3
        max_right = max(max_right, rights)

print(max_right)


Fixed submission:
#ref. https://atcoder.jp/contests/abc129/submissions/5906191
import numpy as np
import sys

def main():
    sin = sys.stdin.buffer
    H, W = map(int, sin.readline().split())
    grid = np.frombuffer(sin.read(H * (W + 1)), dtype="B") == ord(".")
    grid = grid.reshape((H, W + 1))[:, :-1]

    L = np.empty((H, W), dtype="i4")
    R = np.empty((H, W), dtype="i4")
    T = np.empty((H, W), dtype="i4")
    B = np.empty((H, W), dtype="i4")

    T[0] = grid[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * grid[i]

    B[-1] = grid[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * grid[i]

    L[:, 0] = grid[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * grid[:, i]

    R[:, -1] = grid[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * grid[:, i]

    ans = (T + B + L + R - 3).max()
    print(ans)

main()

Buggy python submission (verdict: Time Limit Exceeded):
def search(s_y, s_x):
    count = 1
    for vec_x, vec_y in vecs:
        n_y = s_y + vec_y
        n_x = s_x + vec_x

        while judge(n_y, n_x):
            #is_visited[n_y][n_x] = True
            count += 1
            n_y += vec_y
            n_x += vec_x
    return count

def judge(y, x):
    return 0 <= y <= H -1 and 0 <= x <= W - 1 and not is_visited[y][x] and S_list[y][x] != '#'

H, W = map(int, input().split())
S_list = [None] * H
is_visited = [[False] * W for _ in range(H)]

for h in range(H):
    S_list[h] = list(input())

vecs = [(1, 0), (-1, 0), (0, 1), (0, -1)]

max_num = 0
for h in range(H):
    for w in range(W):
        if S_list[h][w] != '#':
            max_num = max(max_num, search(h, w))

print(max_num)


Fixed submission:
#ref. https://atcoder.jp/contests/abc129/submissions/5906191
import numpy as np
import sys

def main():
    sin = sys.stdin.buffer
    H, W = map(int, sin.readline().split())
    grid = np.frombuffer(sin.read(H * (W + 1)), dtype="B") == ord(".")
    grid = grid.reshape((H, W + 1))[:, :-1]

    L = np.empty((H, W), dtype="i4")
    R = np.empty((H, W), dtype="i4")
    T = np.empty((H, W), dtype="i4")
    B = np.empty((H, W), dtype="i4")

    T[0] = grid[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * grid[i]

    B[-1] = grid[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * grid[i]

    L[:, 0] = grid[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * grid[:, i]

    R[:, -1] = grid[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * grid[:, i]

    ans = (T + B + L + R - 3).max()
    print(ans)

main()