Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

P = [ [ 0 if x == "#" else 0x00010001 for x in input()] for _ in range(H)]

class Union:
    def __init__(self):
        self.rx = 0
        self.ry = 0
        self.lx = 0
        self.ly = 0
    def init(self, y, x):
        value = P[y][x]
        if value == 0:
            return False

        self.lx = x
        self.ly = y
        w = value & 0xffff
        if w & 0x8000:
            self.ry = w ^ 0x8000
        else:
            self.ry = self.ly

        w = value >> 16
        if w & 0x8000:
            self.rx = w ^ 0x8000
        else:
            self.rx = self.lx

        return True

    def changeH(self, src, value):
        return (src ^ (src & 0xffff0000)) | (value << 16)
    def changeV(self, src, value):
        return (src ^ (src & 0xffff)) | value

    def changeHA(self, value):
        return self.changeH(value, self.rx | 0x8000)
    def changeVA(self, value):
        return self.changeV(value, self.ry | 0x8000)

    def getHC(self):
        return P[self.ly][self.rx] >> 16
    def setHC(self, value):
        P[self.ly][self.rx] = self.changeH(P[self.ly][self.rx], value)
    def getVC(self):
        return P[self.ry][self.lx] & 0xffff
    def setVC(self, value):
        P[self.ry][self.lx] = self.changeV(P[self.ry][self.lx], value)
        
uni = Union()

for i in range(H):
    for j in range(W):
        if P[i][j] != 0:
            if i > 0 and uni.init(i-1, j):
                uni.setVC(uni.getVC() + 1)
                P[i][j] = uni.changeVA(P[i][j])
            if j > 0 and uni.init(i, j-1):
                uni.setHC(uni.getHC() + 1)
                P[i][j] = uni.changeHA(P[i][j])


w = 0
for i in range(H):
    for j in range(W):
        if uni.init(i, j):
            w = max(w, uni.getHC() + uni.getVC() -1)

print(w)


Fixed submission:
H, W = map(int, input().split())

P = [[0 if x == "#" else 1 for x in input()] for _ in range(H)]
C = [[-3*P[x][y] for y in range(W)] for x in range(H)]

for j in range(W):
    cntU = 0
    cntD = 0
    for i in range(H):
        if P[i][j] == 0:
            cntD = 0
        else:
            cntD += 1
        C[i][j] += cntD 

        if P[H-1-i][j] == 0:
            cntU = 0
        else:
            cntU += 1
        C[H-1-i][j] += cntU 

for i in range(H):
    cntR = 0
    cntL = 0
    for j in range(W):
        if P[i][j] == 0:
            cntR = 0
        else:
            cntR += 1
        C[i][j] += cntR 

        if P[i][W-1-j] == 0:
            cntL = 0
        else:
            cntL += 1
        C[i][W-1-j] += cntL 




print(max((x for ci in C for x in ci)))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

P = [[0 if x == "#" else 1 for x in input()] for _ in range(H)]
C = [[-3*P[x][y] for y in range(W)] for x in range(H)]

import numpy as np
P = np.array(P, dtype=np.int32)
C = np.array(C, dtype=np.int32)

cur = np.ones(P[0].shape, dtype=np.int32)
for i in range(0, H):
    cur *= P[i]
    C[i] += cur
    cur += 1

cur = 1
for i in range(H-1, -1, -1):
    cur *= P[i]
    C[i] += cur
    cur += 1

cur = np.ones(P[:,0].shape, dtype=np.int32)
for i in range(0, W):
    cur *= P[:,i]
    C[:,i] += cur
    cur += 1

cur = 1
for i in range(W-1, -1, -1):
    cur *= P[:,i]
    C[:,i] += cur
    cur += 1

print(max((x for ci in C for x in ci)))


Fixed submission:
H, W = map(int, input().split())

P = [[0 if x == "#" else 1 for x in input()] for _ in range(H)]
C = [[-3*P[x][y] for y in range(W)] for x in range(H)]

for j in range(W):
    cntU = 0
    cntD = 0
    for i in range(H):
        if P[i][j] == 0:
            cntD = 0
        else:
            cntD += 1
        C[i][j] += cntD 

        if P[H-1-i][j] == 0:
            cntU = 0
        else:
            cntU += 1
        C[H-1-i][j] += cntU 

for i in range(H):
    cntR = 0
    cntL = 0
    for j in range(W):
        if P[i][j] == 0:
            cntR = 0
        else:
            cntR += 1
        C[i][j] += cntR 

        if P[i][W-1-j] == 0:
            cntL = 0
        else:
            cntL += 1
        C[i][W-1-j] += cntL 




print(max((x for ci in C for x in ci)))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

P = [[0 if x == "#" else 1 for x in input()]+[0] for _ in range(H)]
C = [[-1*P[x][y] for y in range(W)] + [0] for x in range(H)]
W += 1
H += 1
P.append([0] * W)
C.append([0] * W)


for i in range(H):
    cnt = 0
    for j in range(W):
        if P[i][j] == 0:
            for k in range(cnt):
                C[i][j-1-k] += k
            cnt = 0
        else:
            cnt += 1
        C[i][j] += cnt

for j in range(W):
    cnt = 0
    for i in range(H):
        if P[i][j] == 0:
            for k in range(cnt):
                C[i-1-k][j] += k
            cnt = 0
        else:
            cnt += 1
        C[i][j] += cnt


print(max((x for ci in C for x in ci)))


Fixed submission:
H, W = map(int, input().split())

P = [[0 if x == "#" else 1 for x in input()] for _ in range(H)]
C = [[-3*P[x][y] for y in range(W)] for x in range(H)]

for j in range(W):
    cntU = 0
    cntD = 0
    for i in range(H):
        if P[i][j] == 0:
            cntD = 0
        else:
            cntD += 1
        C[i][j] += cntD 

        if P[H-1-i][j] == 0:
            cntU = 0
        else:
            cntU += 1
        C[H-1-i][j] += cntU 

for i in range(H):
    cntR = 0
    cntL = 0
    for j in range(W):
        if P[i][j] == 0:
            cntR = 0
        else:
            cntR += 1
        C[i][j] += cntR 

        if P[i][W-1-j] == 0:
            cntL = 0
        else:
            cntL += 1
        C[i][W-1-j] += cntL 




print(max((x for ci in C for x in ci)))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

P = [[0 if x == "#" else 1 for x in input()] for _ in range(H)]
C = [[-3*P[x][y] for y in range(W)] for x in range(H)]

for j in range(W):
    cntU = 0
    cntD = 0
    for i in range(H):
        if P[i][j] == 0:
            cntD = 0
        else:
            cntD += 1
        C[i][j] += cntD 

        if P[H-1-i][j] == 0:
            cntU = 0
        else:
            cntU += 1
        C[H-1-i][j] += cntU 

for i in range(H):
    cntR = 0
    cntL = 0
    for j in range(W):
        if P[i][j] == 0:
            cntR = 0
        else:
            cntR += 1
        C[i][j] += cntR 

        if P[i][W-1-j] == 0:
            cntL = 0
        else:
            cntL += 1
        C[i][W-1-j] += cntL 




print(max((x for ci in C for x in ci)))


Fixed submission:
H, W = map(int, input().split())

P = [[0 if x == "#" else 1 for x in input()] for _ in range(H)]
C = [[-3*P[x][y] for y in range(W)] for x in range(H)]

for j in range(W):
    cntU = 0
    cntD = 0
    for i in range(H):
        if P[i][j] == 0:
            cntD = 0
        else:
            cntD += 1
        C[i][j] += cntD 

        if P[H-1-i][j] == 0:
            cntU = 0
        else:
            cntU += 1
        C[H-1-i][j] += cntU 

for i in range(H):
    cntR = 0
    cntL = 0
    for j in range(W):
        if P[i][j] == 0:
            cntR = 0
        else:
            cntR += 1
        C[i][j] += cntR 

        if P[i][W-1-j] == 0:
            cntL = 0
        else:
            cntL += 1
        C[i][W-1-j] += cntL 




print(max((x for ci in C for x in ci)))