Buggy python submission (verdict: Time Limit Exceeded):
H,W=map(int,input().split())
A=[list(map(lambda x:False if x=='#' else True ,input())) for i in range(H)]

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


for i in range(H):
	for j in range(1,W):
		if A[i][j]:
			L[i][j]=int(A[i][j-1])+L[i][j-1]

for i in range(H):
	for j in range(W-1)[::-1]:
		if A[i][j]:
			R[i][j]=int(A[i][j+1])+R[i][j+1]

for i in range(1,H):
	for j in range(W):
		if A[i][j]:
			U[i][j]=int(A[i-1][j])+U[i-1][j]


for i in range(H-1)[::-1]:
	for j in range(W):
		if A[i][j]:
			D[i][j]=int(A[i+1][j])+D[i+1][j]

ans=0
for i in range(H):
	for j in range(W):
		ans=max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]+1)

print(ans)

Fixed submission:
H,W=map(int,input().split())
A=[list(map(lambda x:False if x=='#' else True ,input())) for i in range(H)]

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


for i in range(H):
	for j in range(1,W):
		if A[i][j]:
			L[i][j]=int(A[i][j-1])+L[i][j-1]

for i in range(H):
	for j in range(W-1)[::-1]:
		if A[i][j]:
			R[i][j]=int(A[i][j+1])+R[i][j+1]

for i in range(1,H):
	for j in range(W):
		if A[i][j]:
			U[i][j]=int(A[i-1][j])+U[i-1][j]


for i in range(H-1)[::-1]:
	for j in range(W):
		if A[i][j]:
			D[i][j]=int(A[i+1][j])+D[i+1][j]

ans=0
for i in range(H):
	for j in range(W):
		ans=max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]+1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
A=[0]*h
s=[[0]*w for i in range(h)]
t=[[0]*h for i in range(w)]

for i in range(h):
    A[i]=[1 if i=='.' else 0 for i in list(input())]

for ip,a in enumerate(A):
    p1=[]
    p2=[]
    if a[0]==1:p1.append(0)
    for i in range(1,len(a)):
        if a[i-1]==0 and a[i]==1:p1.append(i)
        if a[i-1]==1 and a[i]==0:p2.append(i)
    if a[-1]==1:p2.append(len(a))
        
    
    for s1,g1 in zip(p1,p2):
        for j in range(s1,g1):
            s[ip][j]=g1-s1
            
for ip,a in enumerate(zip(*A)):
    p1=[]
    p2=[]
    if a[0]==1:p1.append(0)
    for i in range(1,len(a)):
        if a[i-1]==0 and a[i]==1:p1.append(i)
        if a[i-1]==1 and a[i]==0:p2.append(i)
    if a[-1]==1:p2.append(len(a))
        
    
    for s1,g1 in zip(p1,p2):
        for j in range(s1,g1):
            t[ip][j]=g1-s1

ans=0
for i in range(w):
	for j in range(h):
		ans=max(ans,s[j][i]+t[i][j])
print(ans-1)

Fixed submission:
H,W=map(int,input().split())
A=[list(map(lambda x:False if x=='#' else True ,input())) for i in range(H)]

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


for i in range(H):
	for j in range(1,W):
		if A[i][j]:
			L[i][j]=int(A[i][j-1])+L[i][j-1]

for i in range(H):
	for j in range(W-1)[::-1]:
		if A[i][j]:
			R[i][j]=int(A[i][j+1])+R[i][j+1]

for i in range(1,H):
	for j in range(W):
		if A[i][j]:
			U[i][j]=int(A[i-1][j])+U[i-1][j]


for i in range(H-1)[::-1]:
	for j in range(W):
		if A[i][j]:
			D[i][j]=int(A[i+1][j])+D[i+1][j]

ans=0
for i in range(H):
	for j in range(W):
		ans=max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]+1)

print(ans)