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

    U = [[0 for i in range(W)] for j in range(H)]
    D = [[0 for i in range(W)] for j in range(H)]
    L = [[0 for i in range(W)] for j in range(H)]
    R = [[0 for i in range(W)] for j in range(H)]

    for i in range(H):
        for j in range(W):
            # 上方向
            if i > 0:
                if S[i - 1][j] == '#':
                    U[i][j] = 0
                else:
                    U[i][j] = U[i - 1][j] + 1
            
            # 左方向
            
            if j > 0:
                if S[i][j - 1] == '#':
                    L[i][j] = 0
                else:
                    L[i][j] = L[i][j - 1] + 1
    
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            # 下方向
            if i < H - 1:
                if S[i + 1][j] == '#':
                    D[i][j] = 0
                else:
                    D[i][j] = D[i + 1][j] + 1
            
            # 右方向
            if j < W - 1:
                if S[i][j + 1] == '#':
                    R[i][j] = 0
                else:
                    R[i][j] = R[i][j + 1] + 1
                
            

    res = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                res = max(res, U[i][j] + D[i][j] + R[i][j] + L[i][j])
    
    print(res + 1)

if __name__ == "__main__":
    main()

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

    U = [[0 for i in range(W)] for j in range(H)]
    D = [[0 for i in range(W)] for j in range(H)]
    L = [[0 for i in range(W)] for j in range(H)]
    R = [[0 for i in range(W)] for j in range(H)]

    for i in range(H):
        for j in range(W):
            # 上方向
            if i > 0:
                if S[i - 1][j] == '#':
                    U[i][j] = 0
                else:
                    U[i][j] = U[i - 1][j] + 1
            
            # 左方向
            if j > 0:
                if S[i][j - 1] == '#':
                    L[i][j] = 0
                else:
                    L[i][j] = L[i][j - 1] + 1
    
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            # 下方向
            if i < H - 1:
                if S[i + 1][j] == '#':
                    D[i][j] = 0
                else:
                    D[i][j] = D[i + 1][j] + 1
            
            # 右方向
            if j < W - 1:
                if S[i][j + 1] == '#':
                    R[i][j] = 0
                else:
                    R[i][j] = R[i][j + 1] + 1

    res = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                res = max(res, U[i][j] + D[i][j] + R[i][j] + L[i][j])
    
    print(res + 1)

if __name__ == "__main__":
    main()

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

    U = [[0 for i in range(W)] for j in range(H)]
    D = [[0 for i in range(W)] for j in range(H)]
    L = [[0 for i in range(W)] for j in range(H)]
    R = [[0 for i in range(W)] for j in range(H)]

    for i in range(H):
        for j in range(W):
            # 上方向
            if i > 0:
                if S[i - 1][j] == '#':
                    U[i][j] = 0
                else:
                    U[i][j] = U[i - 1][j] + 1
            # 下方向
            if i < H - 1:
                if i == 0:
                    d = 0
                    for h in range(i+1, H):
                        if S[h][j] == '.':
                            d += 1
                        else:
                            break
                    D[i][j] = d
                else:
                    if D[i - 1][j] > 0:
                        D[i][j] = D[i - 1][j] - 1
                    else:
                        d = 0
                        for h in range(i+1, H):
                            if S[h][j] == '.':
                                d += 1
                            else:
                                break
                        D[i][j] = d
            
            # 左方向
            if j > 0:
                if S[i][j - 1] == '#':
                    L[i][j] = 0
                else:
                    L[i][j] = L[i][j - 1] + 1
            
            # 右方向
            if j < W - 1:
                if j == 0:
                    r = 0
                    for w in range(j+1, W):
                        if S[i][w] == '.':
                            r += 1
                        else:
                            break
                    R[i][j] = r
                else:
                    if R[i][j - 1] > 0:
                        R[i][j] = R[i][j - 1] - 1
                    else:
                        r = 0
                        for w in range(j + 1, W):
                            if S[i][w] == '.':
                                r += 1
                            else:
                                break
                        R[i][j] = r

    res = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                res = max(res, U[i][j] + D[i][j] + R[i][j] + L[i][j])

    print(res + 1)

if __name__ == "__main__":
    main()

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

    U = [[0 for i in range(W)] for j in range(H)]
    D = [[0 for i in range(W)] for j in range(H)]
    L = [[0 for i in range(W)] for j in range(H)]
    R = [[0 for i in range(W)] for j in range(H)]

    for i in range(H):
        for j in range(W):
            # 上方向
            if i > 0:
                if S[i - 1][j] == '#':
                    U[i][j] = 0
                else:
                    U[i][j] = U[i - 1][j] + 1
            
            # 左方向
            if j > 0:
                if S[i][j - 1] == '#':
                    L[i][j] = 0
                else:
                    L[i][j] = L[i][j - 1] + 1
    
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            # 下方向
            if i < H - 1:
                if S[i + 1][j] == '#':
                    D[i][j] = 0
                else:
                    D[i][j] = D[i + 1][j] + 1
            
            # 右方向
            if j < W - 1:
                if S[i][j + 1] == '#':
                    R[i][j] = 0
                else:
                    R[i][j] = R[i][j + 1] + 1

    res = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                res = max(res, U[i][j] + D[i][j] + R[i][j] + L[i][j])
    
    print(res + 1)

if __name__ == "__main__":
    main()

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

U = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H)]
L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        # 上方向
        if i > 0:
            if S[i - 1][j] == '#':
                U[i][j] = 0
            else:
                U[i][j] = U[i - 1][j] + 1
        # 下方向
        if i < H - 1:
            if i == 0:
                d = 0
                for h in range(i+1, H):
                    if S[h][j] == '.':
                        d += 1
                    else:
                        break
                D[i][j] = d
            else:
                if D[i - 1][j] > 0:
                    D[i][j] = D[i - 1][j] - 1
                else:
                    d = 0
                    for h in range(i+1, H):
                        if S[h][j] == '.':
                            d += 1
                        else:
                            break
                    D[i][j] = d
        
        # 左方向
        if j > 0:
            if S[i][j - 1] == '#':
                L[i][j] = 0
            else:
                L[i][j] = L[i][j - 1] + 1
        
        # 右方向
        if j < W - 1:
            if j == 0:
                r = 0
                for w in range(j+1, W):
                    if S[i][w] == '.':
                        r += 1
                    else:
                        break
                R[i][j] = r
            else:
                if R[i][j - 1] > 0:
                    R[i][j] = R[i][j - 1] - 1
                else:
                    r = 0
                    for w in range(j + 1, W):
                        if S[i][w] == '.':
                            r += 1
                        else:
                            break
                    R[i][j] = r

res = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            res = max(res, U[i][j] + D[i][j] + R[i][j] + L[i][j])

print(res + 1)

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

    U = [[0 for i in range(W)] for j in range(H)]
    D = [[0 for i in range(W)] for j in range(H)]
    L = [[0 for i in range(W)] for j in range(H)]
    R = [[0 for i in range(W)] for j in range(H)]

    for i in range(H):
        for j in range(W):
            # 上方向
            if i > 0:
                if S[i - 1][j] == '#':
                    U[i][j] = 0
                else:
                    U[i][j] = U[i - 1][j] + 1
            
            # 左方向
            if j > 0:
                if S[i][j - 1] == '#':
                    L[i][j] = 0
                else:
                    L[i][j] = L[i][j - 1] + 1
    
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            # 下方向
            if i < H - 1:
                if S[i + 1][j] == '#':
                    D[i][j] = 0
                else:
                    D[i][j] = D[i + 1][j] + 1
            
            # 右方向
            if j < W - 1:
                if S[i][j + 1] == '#':
                    R[i][j] = 0
                else:
                    R[i][j] = R[i][j + 1] + 1

    res = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                res = max(res, U[i][j] + D[i][j] + R[i][j] + L[i][j])
    
    print(res + 1)

if __name__ == "__main__":
    main()