There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.
Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.
Snuke wants to maximize the number of squares lighted by the lamp.
You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.
Find the maximum possible number of squares lighted by the lamp.

-----Constraints-----
 - 1 \leq H \leq 2,000
 - 1 \leq W \leq 2,000
 - S_i is a string of length W consisting of # and ..
 - . occurs at least once in one of the strings S_i (1 \leq i \leq H).

-----Input-----
Input is given from Standard Input in the following format:
H W
S_1
:
S_H

-----Output-----
Print the maximum possible number of squares lighted by the lamp.

-----Sample Input-----
4 6
#..#..
.....#
....#.
#.#...

-----Sample Output-----
8

If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.

Difficulty: interview

Starter code:

Solutions:
import numpy as np
import sys
input = sys.stdin.readline

H,W = list(map(int,input().split()))
S=np.array([list(input().rstrip("\n")) for _ in range(H)]) == '.'

D = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)

# 上下
for i in range(H):
  U[i] = (U[i-1] + 1) * S[i]
  D[-i-1] = (D[-i] + 1) * S[-i-1]

# 左右
for i in range(W):
  L[:,i] = (L[:,i-1] + 1) * S[:,i]
  R[:,-i-1] = (R[:,-i] + 1) * S[:,-i-1]

print((np.max(U+D+L+R)-3))


#numpy使い、ループが2→１にする
import numpy as np
#初期入力
H,W = (int(x) for x in input().split())
map1 =[ list(input()) for i in range(H)]
map_np =(np.array(map1)==".")*1

L =np.zeros((H,W),dtype=int)
R =np.zeros((H,W),dtype=int)
U =np.zeros((H,W),dtype=int)
D =np.zeros((H,W),dtype=int)

L[:,0] =map_np[:,0]
for i in range(1,W): # if map_np[i,j] ==1: ⇒ *map_npで１or０をかけてるから不要
    L[:,i] = (L[:,i-1] +1) *map_np[:,i]

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

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

D[H-1,:] =map_np[H-1,:]
for i in range(H-1-1,-1,-1):
    D[i,:] = (D[i+1,:] +1) *map_np[i,:]
    
ans =L +R +U +D -3
print(np.max(ans))

import numpy as np
import sys

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        S = [0 if c == '#' else 1 for c in input().strip()]
        A.append(S)

    A = np.array(A)
    top = np.zeros((H+1, W), dtype=np.int)
    bottom = np.zeros((H+1, W), dtype=np.int)
    right = np.zeros((H, W+1), dtype=np.int)
    left = np.zeros((H, W+1), dtype=np.int)

    for i in range(1, H+1):
        top[i] = (top[i-1] + 1) * A[i-1]

    for i in range(H-1, -1, -1):
        bottom[i] = (bottom[i+1] + 1) * A[i]

    for i in range(1, W+1):
        right[:, i] = (right[:, i-1] + 1) * A[:, i-1]

    for i in range(W-1, -1, -1):
        left[:, i] = (left[:, i+1] + 1) * A[:, i]

    R = (top[1:] + bottom[:H] - 1) * A
    C = (right[:, 1:] + left[:, :W] - 1) * A
    RC = (R + C - 1) * A
    return RC.max()


def __starting_point():
    print(main())
__starting_point()

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])
up = np.ones((H, W), np.int32)
up *= S
down = np.ones((H, W), np.int32)
down *= S
right = np.ones((H, W), np.int32)
right *= S
left = np.ones((H, W), np.int32)
left *= S
for i in range(H-1):
    up[i+1] += up[i]
    up[i+1] *= S[i+1]
for i in range(H-1, 0, -1):
    down[i-1] += down[i]
    down[i-1] *= S[i-1]
for i in range(W-1):
    left[:, i+1] += left[:, i]
    left[:, i+1] *= S[:, i+1]
for i in range(W-1, 0, -1):
    right[:, i-1] += right[:, i]
    right[:, i-1] *= S[:, i-1]

answer = (up + down + left + right).max() - 3
print(answer)


# # D - Lamp

import numpy as np

H, W = list(map(int, input().split()))
M = [list(input()) for _ in range(H)]
M = (np.array(M) == '.') * 1

L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)

for i in range(W):
    if i == 0:
        L[:, i] = M[:, i]
        R[:, W - i - 1] = M[:, W - i - 1]
    else:
        L[:, i] = (L[:, i - 1] + 1) * M[:, i]
        R[:, W - i - 1] = (R[:, W - i] + 1) * M[:, W - i - 1]

for i in range(H):
    if i == 0:
        U[i, :] = M[i, :]
        D[H - i - 1, :] = M[H - i - 1, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * M[i, :]
        D[H - i - 1, :] = (D[H - i, :] + 1) * M[H - i - 1, :]

print((max(np.max(L + R + D + U - 3), 0)))


import numpy as np

h, w  = map(int,input().split())
sn = [[0]*w for i in range(h)]
 
for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == '.':
            sn[i][j] = 1
sn = np.array(sn)
score = np.zeros_like(sn)
total = np.zeros_like(sn)

score[0] += sn[0]
for i in range(1, h):
    score[i] = (score[i-1] + sn[i]) * sn[i]
total += score

score[h-1] = sn[h-1]
for i in range(h-2, -1, -1):
    score[i] = (score[i+1] + sn[i]) * sn[i]
total += score

score[:,0] = sn[:,0]
for i in range(1, w):
    score[:,i] = (score[:,i-1] + sn[:,i]) * sn[:,i]
total += score

score[:,w-1] = sn[:,w-1]
for i in range(w-2, -1, -1):
    score[:,i] = (score[:,i+1] + sn[:,i]) * sn[:,i]
total += score
    
print(total.max()-3)

import numpy as np
H, W = map(int, input().split())
S = np.zeros((H,W))
for i in range(H):
    Si = np.array([int(s == '.') for s in input()])
    S[i] = Si
    
top = S.copy()
bottom = S.copy()
left = S.copy()
right = S.copy()

for i in range(1, H):
    top[i] = (top[i-1] + 1) * S[i]
    bottom[-i-1] = (bottom[-i] + 1) * S[-i-1]

for j in range(1, W):
    left[:,j] = (left[:,j-1] + 1) * S[:,j]
    right[:,-j-1] = (right[:,-j] + 1) * S[:,-j-1]

print(np.max((top + bottom + left + right - 3).astype(np.int)))

import numpy as np
H,W = map(int,input().split())
L = np.zeros((H,W),int)
R = np.zeros((H,W),int)
D = np.zeros((H,W),int)
U = np.zeros((H,W),int)
S = np.array([list(input()) for h in range(H)])=="."
 
for h in range(H):
  U[h] = S[h]*(U[h-1]+1)
  D[-h-1] = S[-h-1]*(D[-h]+1)
 
for w in range(W):
  L[:,w] = S[:,w]*(L[:,w-1]+1)
  R[:,-w-1] = S[:,-w-1]*(R[:,-w]+1)
 
print(np.max(U+D+L+R)-3)

import numpy as np
H,W=map(int,input().split(' '))
maze = [list(input()) for i in range(H)]
maze = (np.array(maze) == '.')*1
L=np.zeros((H,W),dtype=int)
R=np.zeros((H,W),dtype=int)
U=np.zeros((H,W),dtype=int)
D=np.zeros((H,W),dtype=int)
for i in range(W):
    if i==0:
        L[:,i]=maze[:,i]
        R[:,W-i-1]=maze[:,W-i-1]
    else:
        L[:,i]=(L[:,i-1]+1)*maze[:,i]
        R[:,W-i-1]=(R[:,W-i]+1)*maze[:,W-i-1]
for i in range(H):
    if i==0:
        U[i,:]=maze[i,:]
        D[H-i-1,:]=maze[H-i-1,:]
    else:
        U[i,:]=(U[i-1,:]+1)*maze[i,:]
        D[H-i-1,:]=(D[H-i]+1)*maze[H-i-1,:]
print(max(np.max(U+D+L+R-3),0))

import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = list(map(int, read().split()))
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy()
    up = s.copy()
    down = s.copy()
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print(((left + right + up + down).max() - 3))


def __starting_point():
    main()

__starting_point()

import numpy as np

H, W = map(int, input().split())
S_list = [list(input()) for _ in range(H)]
S_list=(np.array(S_list) ==".")*1

L = np.zeros((H, W), int)
R = np.zeros((H, W), int)
U = np.zeros((H, W), int)
D = np.zeros((H, W), int)

for w in range(W):
    if w == 0:
        L[:,w] = S_list[:,w]
        R[:,W-w-1] = S_list[:,W-w-1]
    else:
        L[:,w] = (L[:,w-1]+1) * S_list[:,w]
        R[:,W-w-1] = (R[:,W-w]+1) * S_list[:,W-w-1]

for h in range(H):
    if h == 0:
        U[h,:] = S_list[h,:]
        D[H-h-1,:] = S_list[H-h-1,:]
    else:
        U[h,:] = (U[h-1,:]+1) * S_list[h,:]
        D[H-h-1,:] = (D[H-h,:]+1) * S_list[H-h-1,:]
        
ans = max(np.max(L+R+U+D-3), 0)

print(ans)

import numpy as np

H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
S = np.array(S)
S = (S == '.') * 1

R = np.array([[0 for i in range(W)] for n in range(H)])
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(W):
    if i == 0:
        L[:, 0] = S[:, 0]
        R[:, W - 1] = S[:, W - 1]
    else:
        L[:, i] = L[:, i - 1] * S[:, i] + S[:, i]
        R[:, W - i - 1] = R[:, W - i] * S[:, W - i - 1] + S[:, W - i - 1]
for i in range(H):
    if i == 0:
        U[i] = S[i]
        D[H - 1] = S[H - 1]
    else:
        U[i] = U[i - 1] * S[i] + S[i]
        D[H - i - 1] = D[H - i] * S[H - i - 1] + S[H - i - 1]

print(np.max(R + L + U + D) - 3)

import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])
S = np.where(S==".", 1, 0)

L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)

for i in range(H):
    D[-i-1] = (D[-i]+1)*S[-i-1]
    U[i] = (U[i-1]+1)*S[i]
    
for i in range(W):
    L[:, i] = (L[:, i-1]+1)*S[:, i]
    R[:, -i-1] = (R[:, -i]+1)*S[:, -i-1]
    
print (np.max(L+R+D+U)-3)

import numpy as np
H,W = map(int,input().split())
S=np.array([list(input().rstrip("\n")) for _ in range(H)]) == '.'
D = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)
for i in range(H):# 上下
  U[i] = (U[i-1] + 1) * S[i]
  D[-i-1] = (D[-i] + 1) * S[-i-1]
for i in range(W):# 左右
  L[:,i] = (L[:,i-1] + 1) * S[:,i]
  R[:,-i-1] = (R[:,-i] + 1) * S[:,-i-1]
print(np.max(U+D+L+R)-3)

"""
参考
blog名  ベスパリブ    #プログラミングを主とした日記・備忘録です
URL     https://takeg.hatenadiary.jp/entry/2019/09/10/234417
id:     takeg
"""
# 初期入力
H,W = (int(x) for x in input().split())
S = [list(input()) for i in range(H)]
import numpy as np
S_np = (np.array(S) ==".")*1 #文字を数字に変換 Trueの所のみ演算、Falseは０


#置いたマス(i,j)から4方向探す
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
D = np.zeros((H,W),dtype=int)
for i in range(W):
    # if S_int[i,j] ==0:これはいらない？⇒*S_npで１or０をかけてるから不要
    if i == 0: 
        L[:,i]      = S_np[:,i]
        R[:,W-i-1]  = S_np[:,W-i-1]
    else:
        L[:,i]      = (L[:,i-1] +1) * S_np[:,i]
        R[:,W-i-1]  = (R[:,W-i] +1) * S_np[:,W-i-1]

for i in range(H):
    if i == 0: 
        D[i,:]      = S_np[i,:]
        U[H-i-1,:]  = S_np[H-i-1,:]
    else:
        D[i,:]      = (D[i-1,:] +1) * S_np[i,:]
        U[H-i-1,:]  = (U[H-i,:] +1) * S_np[H-i-1,:]

#各方向を位置ごとに足す(numpyなら足すだけで行列の和) 
light = L + R + D + U -3 #基準点を4方向＋１してるからー３
light_max = np.max(light)
print(light_max)

from itertools import product
import numpy as np

h, w = list(map(int, input().split()))
notwall = []
for _ in range(h):
    s = input()
    notwall.append([int(c == '.') for c in s])

notwall = np.array(notwall)


def getll():
    ls = np.zeros((h, w + 1), dtype=int)

    for i in range(w):
        ls[:, i + 1] = (ls[:, i] + 1) * notwall[:, i]

    ls = ls[:, 1:]
    return ls


def getlr():
    ls = np.zeros((h, w + 1), dtype=int)

    for i in range(w - 1, -1, -1):
        ls[:, i] = (ls[:, i + 1] + 1) * notwall[:, i]

    ls = ls[:, :-1]
    return ls


def getlu():
    ls = np.zeros((h + 1, w), dtype=int)

    for i in range(h):
        ls[i + 1, :] = (ls[i, :] + 1) * notwall[i, :]

    ls = ls[1:, :]
    return ls


def getld():
    ls = np.zeros((h + 1, w), dtype=int)

    for i in range(h - 1, -1, -1):
        ls[i, :] = (ls[i + 1, :] + 1) * notwall[i, :]

    ls = ls[:-1, :]
    return ls


ll = getll()
lr = getlr()
lu = getlu()
ld = getld()

m = max([0, np.max(ll + lr + lu + ld) - 3])

print(m)



import numpy as np

h, w = list(map(int, input().split()))
s = np.empty((h, w), dtype='i8')
for i in range(h):
    s[i] = [i == '.' for i in list(input())]

right = np.copy(s)
left = np.copy(s)
for i in range(1, w):
    right[:, -i-1] = (right[:, -i] + 1) * s[:, -i-1]
    left[:, i] = (left[:, i-1] + 1) * s[:, i]
up = np.copy(s)
down = np.copy(s)
for i in range(1, h):
    up[i] = (up[i-1] + 1) * s[i]
    down[-i-1] = (down[-i] + 1) * s[-i-1]

print((np.max(right + left + up + down) - 3))


import sys
import numpy as np
sys.setrecursionlimit(10**9)
H, W = list(map(int, input().split()))
S = [list('#' * (W + 2))]
for _ in range(H):
    S.append(list('#' + input() + '#'))
S.append(list('#' * (W + 2)))
S = np.array(S)
# print(S)

north = np.zeros_like(S, dtype='int')
for w in range(1, W + 1):
    north[:, w] = north[:, w - 1] + 1
    north[:, w][S[:, w - 1] == '#'] = 0
    north[:, w][S[:, w] == '#'] = 0

south = np.zeros_like(S, dtype='int')
for w in range(W, 0, -1):
    south[:, w] = south[:, w + 1] + 1
    south[:, w][S[:, w + 1] == '#'] = 0
    south[:, w][S[:, w] == '#'] = 0

east = np.zeros_like(S, dtype='int')
for h in range(1, H + 1):
    east[h, :] = east[h - 1, :] + 1
    east[h, :][S[h - 1] == '#'] = 0
    east[h, :][S[h, :] == '#'] = 0

west = np.zeros_like(S, dtype='int')
for h in range(H, 0, -1):
    west[h, :] = west[h + 1, :] + 1
    west[h, :][S[h + 1] == '#'] = 0
    west[h, :][S[h, :] == '#'] = 0
# print(west)

ans = north + south + east + west
print((ans.max() + 1))


import numpy as np
H ,W = map(int,input().split())

maze = [[] for _ in range(H)]
for i in range(H):
    maze[i] = np.array(list(input())) == "."
maze = np.array(maze)

up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)

for i in range(H):
    up[i] = (up[i-1] + 1)*maze[i]
    down[-(i+1)] = (down[-i] + 1)*maze[-(i+1)] 
    
#print(up)
#print(down)

for i in range(W):
    right[:, i] = (right[:, i-1] + 1)*maze[:, i]
    left[:, -(i+1)] = (left[:, -i] + 1)*maze[:, -(i+1)]

print(np.max(up+down+right+left)-3)

import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w)) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(int(np.max(left+right+up+down)-3))

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()

S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])

U = np.zeros((H, W), np.int32)
D = np.zeros((H, W), np.int32)
L = np.zeros((H, W), np.int32)
R = np.zeros((H, W), np.int32)

for h in range(H-1):
    U[h+1] = (U[h] + 1) * S[h]
    D[H-h-2] = (D[H-h-1] + 1) * S[H-h-1]
for w in range(W-1):
    L[:, w+1] = (L[:, w] + 1) * S[:, w]
    R[:, W-w-2] = (R[:, W-w-1] + 1) * S[:, W-w-1]


print((((U + D + L + R) * S).max() + 1))


import numpy as np
h, w = map(int, input().split())
grid = np.array([list(input()) for _ in range(h)], dtype="str")

hgrid = np.zeros((h, w), dtype="int")

for hi in range(h):
    hdot = np.array(grid[hi] == ".", dtype="int")
    hgrid[hi] = hgrid[hi-1] * hdot + hdot
    
for hi in range(h-2, -1, -1):
    hi_1 = np.minimum(hgrid[hi+1], hgrid[hi] * hgrid[hi+1])
    hgrid[hi] = np.maximum(hgrid[hi], hi_1)
    
wgrid = np.zeros((h, w), dtype="int")

for wi in range(w):
    wdot = np.array(grid[:, wi] == ".", dtype="int")
    wgrid[:, wi] = wgrid[:, wi-1] * wdot + wdot
    
for wi in range(w-2, -1, -1):
    wi_1 = np.minimum(wgrid[:, wi+1], wgrid[:, wi] * wgrid[:, wi+1])
    wgrid[:, wi] = np.maximum(wgrid[:, wi], wi_1)

print(np.max(wgrid + hgrid) - 1)

import sys
import numpy as np 

h, w = map(int, sys.stdin.readline().split())
grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(h)], dtype='U')
grid = np.pad(grid, 1, mode='constant')

def main():
    cnt = np.zeros((h+2, w+2))
    cnt[grid == '.'] = np.inf
    
    l = cnt.copy()
    r = cnt.copy()
    u = cnt.copy()
    d = cnt.copy()

    for i in range(1, w+1):
        l[1:h+1, i] = np.minimum(l[1:h+1, i], l[1:h+1, i-1]+1)
        i = w + 1 - i
        r[1:h+1, i] = np.minimum(r[1:h+1, i], r[1:h+1, i+1]+1)
    
    for i in range(1, h+1):
        u[i, 1:w+1] = np.minimum(u[i, 1:w+1], u[i-1, 1:w+1]+1)
        i = h + 1 - i
        d[i, 1:w+1] = np.minimum(d[i, 1:w+1], d[i+1, 1:w+1]+1)
    
    res = np.maximum(l + r + u + d - 3, 0).astype(np.int64)
    return np.amax(res)

def __starting_point():
    ans = main()
    print(ans)
__starting_point()

# 初期入力
H,W = (int(x) for x in input().split())
S = [list(input()) for i in range(H)]
import numpy as np
S_np = (np.array(S) ==".")*1 #文字を数字に変換 Trueの所のみ演算、Falseは０


#置いたマス(i,j)から4方向探す
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
D = np.zeros((H,W),dtype=int)
for i in range(W):
    # if S_int[i,j] ==0:これはいらない？⇒*S_npで１or０をかけてるから不要
    if i == 0: 
        L[:,i]      = S_np[:,i]
        R[:,W-i-1]  = S_np[:,W-i-1]
    else:
        L[:,i]      = (L[:,i-1] +1) * S_np[:,i]
        R[:,W-i-1]  = (R[:,W-i] +1) * S_np[:,W-i-1]

for i in range(H):
    if i == 0: 
        D[i,:]      = S_np[i,:]
        U[H-i-1,:]  = S_np[H-i-1,:]
    else:
        D[i,:]      = (D[i-1,:] +1) * S_np[i,:]
        U[H-i-1,:]  = (U[H-i,:] +1) * S_np[H-i-1,:]

#各方向を位置ごとに足す(numpyなら足すだけで行列の和) 
light = L + R + D + U -3 #基準点を4方向＋１してるからー３
light_max = np.max(light)
print(light_max)

#写経AC
import numpy as np
H,W = list(map(int,input().split()))
L = np.zeros((H,W),int)
R = np.zeros((H,W),int)
D = np.zeros((H,W),int)
U = np.zeros((H,W),int)
S = np.array([list(input()) for h in range(H)])=="."

for h in range(H):
  U[h] = S[h]*(U[h-1]+1)
  D[-h-1] = S[-h-1]*(D[-h]+1)

for w in range(W):
  L[:,w] = S[:,w]*(L[:,w-1]+1)
  R[:,-w-1] = S[:,-w-1]*(R[:,-w]+1)

print((np.max(U+D+L+R)-3))


import numpy as np
from copy import deepcopy


def main():
    height, width = list(map(int, input().split()))
    grid = [list(input()) for _ in range(height)]
    grid = (np.array(grid) == ".") * 1
    left = np.zeros((height, width), dtype=int)
    right = deepcopy(left)
    upper = deepcopy(left)
    down = deepcopy(left)

    for i in range(height):
        if i == 0:
            upper[i] = grid[i]
        else:
            upper[i] = (upper[i - 1] + 1) * grid[i]

    for i in range(width):
        if i == 0:
            left[:, i] = grid[:, i]
        else:
            left[:, i] = (left[:, i - 1] + 1) * grid[:, i]

    for i in range(width - 1, -1, -1):
        if i == width - 1:
            right[:, i] = grid[:, i]
        else:
            right[:, i] = (right[:, i + 1] + 1) * grid[:, i]

    for i in range(height - 1, -1, -1):
        if i == height - 1:
            down[i] = grid[i]
        else:
            down[i] = (down[i + 1] + 1) * grid[i]

    print((np.max(left + right + upper + down - 3)))


def __starting_point():
    main()


__starting_point()

import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w)) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(int(np.max(left+right+up+down)-3))

import numpy as np
H,W = map(int,input().split())
HL=list(range(H))
WL=list(range(W))
Gd = np.array([list(input()) for _ in HL])
Gd = np.where(Gd=='.', 1, 0)
L=np.zeros((H,W),dtype=np.int64)
R=np.zeros((H,W),dtype=np.int64)
U=np.zeros((H,W),dtype=np.int64)
D=np.zeros((H,W),dtype=np.int64)

for w in WL:
  R[:,w]=(R[:,w-1]+1)*Gd[:,w]
  L[:,-w-1]=(L[:,-w]+1)*Gd[:,-w-1]
for h in HL:
  D[h,:]=(D[h-1,:]+1)*Gd[h,:]
  U[-h-1,:]=(U[-h,:]+1)*Gd[-h-1,:]
print(np.max(D+U+L+R-3))

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
up = np.array([[1 if x == '.' else 0 for x in row] for row in S])
down = up.copy()
right = up.copy()
left = up.copy()
S = up.copy()
for i in range(H-1):
    up[i+1] += up[i]
    up[i+1] *= S[i+1]
for i in range(H-1, 0, -1):
    down[i-1] += down[i]
    down[i-1] *= S[i-1]
for i in range(W-1):
    left[:, i+1] += left[:, i]
    left[:, i+1] *= S[:, i+1]
for i in range(W-1, 0, -1):
    right[:, i-1] += right[:, i]
    right[:, i-1] *= S[:, i-1]

answer = (up + down + left + right).max() - 3
print(answer)


import numpy as np

h,w=map(int,input().split())
g = np.array([list(input()) for _ in range(h)])
g = np.where(g=='.',1,0)

l = np.zeros((h,w),dtype=np.int)
r = np.zeros((h,w),dtype=np.int)
u = np.zeros((h,w),dtype=np.int)
d = np.zeros((h,w),dtype=np.int)

for i in range(w):
  l[:,i] = (l[:,i-1]+1)*g[:,i]
  r[:,-i-1] = (r[:,-i]+1)*g[:,-i-1]

for i in range(h):
  u[i,:]=(u[i-1,:]+1)*g[i,:]
  d[-i-1,:]=(d[-i,:]+1)*g[-i-1,:]

print(np.max(l+r+u+d)-3)

import numpy as np

h, w = list(map(int, input().split()))
s = np.array([list(input()) for _ in range(h)]) == '.'

L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)

for i in range(h):
    D[i] = (D[i-1]+1) * s[i]
    U[-i-1] = (U[-i]+1) * s[-i-1]

for i in range(w):
    R[:, i] = (R[:, i-1]+1) * s[:, i]
    L[:, -i-1] = (L[:, -i]+1) * s[:, -i-1]


print((np.max(D+U+R+L)-3))


import numpy as np
 
H, W = map(int, input().split())
S_list = [list(input()) for _ in range(H)]
S_list=(np.array(S_list) ==".")*1
 
L = np.zeros((H, W), int) # i,jより左のランプをてらせる数
R = np.zeros((H, W), int)
U = np.zeros((H, W), int)
D = np.zeros((H, W), int)
 
for w in range(W):
    if w == 0: 
        L[:,w] = S_list[:,w] # 一番左であれば、Lは1, 他の行も同じ
        R[:,W-w-1] = S_list[:,W-w-1] # 一番右であれば、Rは1, 他の行も同じ
    else:
        L[:,w] = (L[:,w-1]+1) * S_list[:,w] # Lは一つ左のものに1を加えたもの, 他の行も同じ
        R[:,W-w-1] = (R[:,W-w]+1) * S_list[:,W-w-1] # Rは一つ右のものに1を加えたもの, 他の行も同じ
 
for h in range(H):
    if h == 0:
        U[h,:] = S_list[h,:]
        D[H-h-1,:] = S_list[H-h-1,:]
    else:
        U[h,:] = (U[h-1,:]+1) * S_list[h,:]
        D[H-h-1,:] = (D[H-h,:]+1) * S_list[H-h-1,:]
        
ans = max(np.max(L+R+U+D-3), 0) # 行列のH,Wの中で最大のものをとる
 
print(ans)

#learnt about numpy from this code thank you nohtaray
#source: https://atcoder.jp/contests/abc129/submissions/5850116
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

H, W = list(map(int, sys.stdin.readline().split()))

S = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == '.'
ups = np.zeros((H, W), dtype=int)
downs = np.zeros((H, W), dtype=int)
rights = np.zeros((H, W), dtype=int)
lefts = np.zeros((H, W), dtype=int)

for h in range(1, H):
    ups[h] = (ups[h - 1] + 1) * S[h - 1]
for h in reversed(list(range(H - 1))):
    downs[h] = (downs[h + 1] + 1) * S[h + 1]
for w in range(1, W):
    lefts[:, w] = (lefts[:, w - 1] + 1) * S[:, w - 1]
for w in reversed(list(range(W - 1))):
    rights[:, w] = (rights[:, w + 1] + 1) * S[:, w + 1]
print((((ups + downs + lefts + rights) * S).max() + 1))



# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()

S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])

U = np.zeros((H, W), np.int32)
D = np.zeros((H, W), np.int32)
L = np.zeros((H, W), np.int32)
R = np.zeros((H, W), np.int32)

for h in range(H-1):
    U[h+1] = (U[h] + 1) * S[h]
    D[H-h-2] = (D[H-h-1] + 1) * S[H-h-1]
for w in range(W-1):
    L[:, w+1] = (L[:, w] + 1) * S[:, w]
    R[:, W-w-2] = (R[:, W-w-1] + 1) * S[:, W-w-1]


print((((U + D + L + R) * S).max() + 1))


import numpy as np

H,W=map(int,input().split())
S=np.array([list(input()) for _ in range(H)]) == "."

ups=np.zeros((H,W),dtype=int)
downs=np.zeros((H,W),dtype=int)
rights=np.zeros((H,W),dtype=int)
lefts=np.zeros((H,W),dtype=int)

for i in range(1,H):
    ups[i,:]=(ups[i-1,:]+1)*S[i-1,:]

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

for i in range(1,W):
    rights[:,i]=(rights[:,i-1]+1)*S[:,i-1]

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

ans=((ups+downs+lefts+rights)*S).max()+1
print(ans)

import numpy as np


def main():
    H, W = list(map(int, input().split(' ')))
    field = np.array([list(input()) for _ in range(H)])
    field = np.where(field == '#', 0, 1)
    left, right, up, down = [np.zeros((H, W)) for _ in range(4)]
    for w in range(W):
        left[:, w] = (left[:, w-1] + 1) * field[:, w]
        right[:, -w-1] = (right[:, -w] + 1) * field[:, -w-1]
    for h in range(H):
        up[h, :] = (up[h-1, :] + 1) * field[h, :]
        down[-h-1, :] = (down[-h, :] + 1) * field[-h-1, :]
    s = left + right + up + down - 3
    print(int(np.max(s)))


def __starting_point():
    main()
__starting_point()

#!/usr/bin/env python3
import numpy as np

h, w = list(map(int, input().split()))

s = np.array([list(input()) for _ in range(h)]) == "."

ups = np.zeros((h, w), dtype=int)
downs = np.zeros((h, w), dtype=int)
rights = np.zeros((h, w), dtype=int)
lefts = np.zeros((h, w), dtype=int)

for i in range(1, h):
    ups[i, :] = (ups[i-1]+1)*s[i-1]

for i in reversed(list(range(h-1))):
    downs[i, :] = (downs[i+1]+1)*s[i+1]

for i in range(1, w):
    rights[:, i] = (rights[:, i-1]+1)*s[:, i-1]

for i in reversed(list(range(w-1))):
    lefts[:, i] = (lefts[:, i+1]+1)*s[:, i+1]

ans = (((ups+downs+lefts+rights)*s).max()+1)
print(ans)


# data_w = []
# data_w_index = []
# data_h = []
# data_h_index = []

# for i in range(h):
#     count = 0
#     index = 0
#     data_w_index_tmp = []
#     data_w_tmp = []
#     for j in range(len(s[i])):
#         # print(s[i][j][0])
#         # print(count)
#         # print(index)
#         if s[i][j] == ".":
#             count += 1
#             data_w_index_tmp.append(index)
#         else:
#             data_w_tmp.append(count)
#             data_w_index_tmp.append(-1)
#             count = 0
#             index += 1
#     data_w_tmp.append(count)
#     # data_w_index_tmp.append(index)

#     data_w_index.append(data_w_index_tmp)
#     data_w.append(data_w_tmp)

# print(data_w)
# print(data_w_index)

# for i in range(w):
#     count = 0
#     index = 0
#     data_h_index_tmp = []
#     data_h_tmp = []
#     for j in range(len(s)):
#         # print(s[i][j][0])
#         # print(count)
#         # print(index)
#         if s[j][i] == ".":
#             count += 1
#             data_h_index_tmp.append(index)
#         else:
#             data_h_tmp.append(count)
#             data_h_index_tmp.append(-1)
#             count = 0
#             index += 1
#     data_h_tmp.append(count)
#     # data_h_index_tmp.append(index)

#     data_h_index.append(data_h_index_tmp)
#     data_h.append(data_h_tmp)

# # print(data_h)
# # print(data_h_index)

# ans = 0
# for i in range(w):
#     for j in range(h):
#         index_h = data_h_index[i][j]
#         index_w = data_w_index[j][i]
#         if index_h != 1:
#             ans_tmp = data_h[i][index_h]+data_w[j][index_w]-1
#             ans = max(ans, ans_tmp)
# print(ans)


import numpy as np

H, W = list(map(int, input().split()))
G = []
for _ in range(H):
    G.append([1 if x == '.' else 0 for x in input()])
G = np.array(G)

North = np.cumsum(np.ones_like(G), axis=0)
North *= (1 - G)
North = np.maximum.accumulate(North, axis=0) * G

South = np.cumsum(np.ones_like(G), axis=0)
South *= np.flipud(1 - G)
South = np.maximum.accumulate(South, axis=0)
South = (H - np.flipud(South)) * G

West = np.cumsum(np.ones_like(G), axis=1)
West *= (1 - G)
West = np.maximum.accumulate(West, axis=1) * G

East = np.cumsum(np.ones_like(G), axis=1)
East *= np.fliplr(1 - G)
East = np.maximum.accumulate(East, axis=1)
East = (W - np.fliplr(East)) * G

print((np.amax(South - North + East - West) - 1))


from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    h,w=map(int,readline().split())
    grid=[readline().strip() for _ in range(h)]
    grid2=np.zeros((h,w),dtype="int64")
    for i in range(h):
        for j in range(w):
            if grid[i][j]==".":
                grid2[i][j]=1
            else:
                grid2[i][j]=0

    up=np.zeros((h,w),dtype="int64")
    up[0]=grid2[0]
    for i in range(1,h):
        up[i]=(up[i-1]+1)*grid2[i]
    
    down=np.zeros((h,w),dtype="int64")
    down[-1]=grid2[-1]
    for i in range(h-2,-1,-1):
        down[i]=(down[i+1]+1)*grid2[i]
    
    left=np.zeros((h,w),dtype="int64")
    left[:,0]=grid2[:,0]
    for i in range(1,w):
        left[:,i]=(left[:,i-1]+1)*grid2[:,i]
    
    right=np.zeros((h,w),dtype="int64")
    right[:,-1]=grid2[:,-1]
    for i in range(w-2,-1,-1):
        right[:,i]=(right[:,i+1]+1)*grid2[:,i]

    ans=(up+down+left+right-3).max()
    print(ans)
    
def __starting_point():
    main()
__starting_point()

import numpy as np

h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

s=np.array(s)
s=np.where(s=='.',1,0)

L=np.zeros((h,w),dtype=np.int)
R=np.zeros((h,w),dtype=np.int)
U=np.zeros((h,w),dtype=np.int)
D=np.zeros((h,w),dtype=np.int)

for i in range(w):
 L[:,i]=(L[:,i-1]+1)*s[:,i]
 R[:,-i-1]=(R[:,-i]+1)*s[:,-i-1]
for i in range(h):
 U[i]=(U[i-1]+1)*s[i]
 D[-i-1]=(D[-i]+1)*s[-i-1]

ans=np.max(L+R+U+D)-3
print(ans)

import numpy
H,W = map(int,input().split())
S = numpy.array([[1 if i == '.' else 0 for i in input().strip()] for _ in range(H)])
S = numpy.array([S, S])

for w in range(1, W):
    S[0, :, w] += S[0, :, w] * S[0, :, w - 1]
for w in range(W - 2, -1, -1):
    S[0, :, w] = (S[0, :, w] != 0) * numpy.maximum(S[0, :, w], S[0, :, w + 1])
for h in range(1, H):
    S[1, h] += S[1, h] * S[1, h - 1]
for h in range(H - 2, -1, -1):
    S[1, h] = (S[1, h] != 0) * numpy.maximum(S[1, h], S[1, h + 1])

S = S[0]+S[1]
print(numpy.max(S)-1)

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S], np.bool)
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]

answer = ((up + down + left + right) * S).max() + 1
print(answer)


def main(): 
  import numpy as np 
  h,w=map(int,input().split())
  grid=np.array([list(input()) for i in range(h)])
  grid=np.where(grid=='.',1,0)
    
  left=np.zeros((h,w),dtype=np.int64)
  right=np.zeros((h,w),dtype=np.int64)
  up=np.zeros((h,w),dtype=np.int64)
  down=np.zeros((h,w),dtype=np.int64)
  
  for i in range(w):
    left[:,i]=(left[:,i-1]+1)*grid[:,i]
    right[:,-i-1]=(right[:,-i]+1)*grid[:,-i-1]
  for i in range(h):
    up[i]=(up[i-1]+1)*grid[i]
    down[-i-1]=(down[-i]+1)*grid[-i-1]
  
  print(np.max(left+right+up+down)-3)
  
def __starting_point():
  main()
__starting_point()

import numpy as np
H,W = map(int,input().split())
L = np.zeros((H,W),int)
R = np.zeros((H,W),int)
D = np.zeros((H,W),int)
U = np.zeros((H,W),int)
S = np.array([list(input()) for h in range(H)])=="."

for h in range(H):
  U[h] = S[h]*(U[h-1]+1)
  D[-h-1] = S[-h-1]*(D[-h]+1)

for w in range(W):
  L[:,w] = S[:,w]*(L[:,w-1]+1)
  R[:,-w-1] = S[:,-w-1]*(R[:,-w]+1)

print(np.max(U+D+L+R)-3)

#写経の写経
import numpy as np
H,W = list(map(int,input().split()))
L = np.zeros((H,W),int)
R = np.zeros((H,W),int)
D = np.zeros((H,W),int)
U = np.zeros((H,W),int)
S = np.array([list(input()) for h in range(H)])=="."

for h in range(H):
  U[h] = S[h]*(U[h-1]+1)
  D[-h-1] = S[-h-1]*(D[-h]+1)

for w in range(W):
  L[:,w] = S[:,w]*(L[:,w-1]+1)
  R[:,-w-1] = S[:,-w-1]*(R[:,-w]+1)

print((np.max(U+D+L+R)-3))



import numpy as np


def main():
    h, w = list(map(int, input().split()))
    s = np.array([[i == "." for i in input()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy()
    up = s.copy()
    down = s.copy()
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print(((left + right + up + down).max() - 3))


def __starting_point():
    main()

__starting_point()

# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]

answer = ((up + down + left + right) * S).max() + 1
print(answer)


import numpy as np
def main():
    h, w = map(int, input().split())
    s = np.array([list(input()) for _ in range(h)])
    t = np.zeros((h+2, w+2))
    t[1:-1, 1:-1][s == "."] = 1
    row = np.zeros((h+2, w+2))
    col = np.zeros((w+2, h+2))
    for i in range(1, h+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        row[i, idx[:-1]+1] += dif-1
        row[i, idx[1:]] -= dif-1
        row[i] = np.cumsum(row[i])
    t = t.T
    for i in range(1, w+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        col[i, idx[:-1]] += dif-2
        col[i, idx[1:]] -= dif-2
        col[i] = np.cumsum(col[i])
    col = col.T
    cost = np.add(row, col)
    print(int(np.max(cost)))

def __starting_point():
    main()
__starting_point()

#import sys
#input = sys.stdin.buffer.readline
import numpy as np

def main():
    H,W = list(map(int,input().split()))
    S = np.array([list(input()) for _ in range(H)]) == '.' #'.'に一致するならTrueしなければFalse

    up = np.zeros((H,W), dtype=int)
    down = np.zeros((H,W), dtype=int)
    left = np.zeros((H,W), dtype=int)
    right = np.zeros((H,W), dtype=int)
    
    for i in range(H-1):
        up[i+1,:] = (up[i,:] + 1) * S[i,:] #npの変数名[k,l]でk行l列を取り出す
    for i in range(H-1):                   #:なら全部をそれぞれについて見ていく
        down[H - 2 - i,:] = (down[H - 1 - i,:] + 1) * S[H - 1 - i,:]
    for i in range(W-1):
        left[:,i+1] = (left[:,i] + 1) * S[:,i]
    for i in range(W-1):
        right[:,W - 2 - i] = (right[:,W - 1 - i] + 1) * S[:,W - 1 - i]
        
    print((((up+down+left+right)*S).max()+1)) #カケザンデ要素ごとの掛け算可能
    
def __starting_point():
    main()

__starting_point()

import numpy as np
h,w = map(int,input().split())
ar = np.array([list(input()) for _ in range(h)]) == '.'
#print(ar)
l = np.zeros((h,w),dtype=int)
r = np.zeros((h,w),dtype=int)
u = np.zeros((h,w),dtype=int)
d = np.zeros((h,w),dtype=int)

for i in range(h):
  u[i] = (u[i-1]+1)*ar[i]
  #print(u)
  d[-i-1] = (d[-i]+1)*ar[-i-1]
  #print(d)
  
for j in range(w):
  l[:,j] = (l[:,j-1]+1)*ar[:,j]
  #print(l)
  r[:,-j-1] = (r[:,-j]+1)*ar[:,-j-1]
  #print(r)
print(np.max(u+d+l+r)-3)

import numpy as np
H,W = list(map(int,input().split()))
S = np.array([list(input()) for _ in range(H)])
S = np.where(S=='.',1,0)


L = np.zeros((H,W),dtype=np.int)
R = np.zeros((H,W),dtype=np.int)
U = np.zeros((H,W),dtype=np.int)
D = np.zeros((H,W),dtype=np.int)

for i in range(W):
    L[:,i] = (L[:,i-1]+1)*S[:,i]
    R[:,-i-1] = (R[:,-i]+1)*S[:,-i-1]
for j in range(H):
    U[j,:] = (U[j-1,:]+1)*S[j,:]
    D[-j-1,:] = (D[-j,:]+1)*S[-j-1,:]

print((np.max(L+R+U+D)-3))


import numpy as np

H, W = list(map(int, input().split()))
G = []
for _ in range(H):
    G.append([1 if x == '.' else 0 for x in input()])
G = np.array(G)
HWOnes = np.ones_like(G)

North = np.cumsum(np.ones_like(G), axis=0)
North *= (1 - G)
North = np.maximum.accumulate(North, axis=0) * G

South = np.cumsum(np.ones_like(G), axis=0)
South *= np.flipud(1 - G)
South = np.maximum.accumulate(South, axis=0)
South = (H - np.flipud(South)) * G

West = np.cumsum(np.ones_like(G), axis=1)
West *= (1 - G)
West = np.maximum.accumulate(West, axis=1) * G

East = np.cumsum(np.ones_like(G), axis=1)
East *= np.fliplr(1 - G)
East = np.maximum.accumulate(East, axis=1)
East = (W - np.fliplr(East)) * G

print((np.amax(South - North + East - West - 1)))


import numpy as np
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
li = [[0 if s[i][j] == "#" else 1 for j in range(w)] for i in range(h)]
l, r, u, d = np.array(li), np.array(li), np.array(li), np.array(li)
for i in range(1, h):
    u[i] *= (u[i - 1] + 1)
    d[-i - 1] *= (d[-i] + 1)
for i in range(1, w):
    l[:, i] *= (l[:, i - 1] + 1)
    r[:, -i - 1] *= (r[:, -i] + 1)
print((l + r + u + d - 3).max())

import numpy as np


H, W = list(map(int, input().split()))
field = [[c == "." for c in input()] for _ in range(H)]
field = np.array(field, dtype=np.int16)

u = field.copy()
d = field.copy()
l = field.copy()
r = field.copy()

for i in range(1, H):
    u[i] = (u[i - 1] + 1) * u[i]
    d[-i - 1] = (d[-i] + 1) * d[-i - 1]

for j in range(1, W):
    l[:, j] = (l[:, j - 1] + 1) * l[:, j]
    r[:, -j - 1] = (r[:, -j] + 1) * r[:, -j - 1]

print(((u + d + l + r - 3).max()))


# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = np.array(['#' * (W+2)] + ['#' + sr() + '#' for _ in range(H)] + ['#' * (W+2)])
S = np.array([[x == '.' for x in row] for row in S])
S = S.astype(np.int16)
left = S.copy(); right = S.copy(); up = S.copy(); down = S.copy()
for i in range(1, W+1):
    left[:, i] += left[:, i-1]
    left[:, i] *= S[:, i]
for i in range(W, 0, -1):
    right[:, i] += right[:, i+1]
    right[:, i] *= S[:, i]
for i in range(1, H+1):
    up[i, :] += up[i-1, :]
    up[i, :] *= S[i, :]
for i in range(H, 0, -1):
    down[i, :] += down[i+1, :]
    down[i, :] *= S[i, :]

answer = (left + right + up + down - 3).max()
print(answer)


import numpy as np
H, W=map(int, input().split())
S=np.array([list(input()) for _ in range(H)])
S=np.where(S==".",1,0 )

left=np.zeros((H, W))
right=np.zeros((H, W))
top=np.zeros((H, W))
bottom=np.zeros((H, W))

for i in range(W):
  if i==0:
    left[:,i]=S[:,i]
    right[:,-i-1]=S[:,-i-1]
  else:
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
    
for i in range(H):
  if i==0:
    top[i,:]=S[i,:]
    bottom[-1-i,:]=S[-i-1,:]
  else:
    top[i,:]=(top[i-1,:]+1)*S[i,:]
    bottom[-1-i,:]=(bottom[-i,:]+1)*S[-i-1,:]
    
ans=left+top+right+bottom-3
    

print(int(ans.max()))

import numpy as np
H,W = map(int,input().split())
Map=[list(input()) for h in range(H)]
Map=[[1 if s=='.' else 0 for s in Map[h]] for h in range(H)]
Map=np.array(Map,dtype=int)
L=Map.copy()
R=Map.copy()
U=Map.copy()
D=Map.copy()
for w in range(1,W):
    L[:,w]=(L[:,w-1]+1)*Map[:,w]
    R[:,-(1+w)]=(R[:,-w]+1)*Map[:,-(1+w)]
for h in range(1,H):
    U[h,:]=(U[h-1,:]+1)*Map[h,:]
    D[-(1+h),:]=(D[-h,:]+1)*Map[-(1+h),:]
print((L+R+U+D).max()-3)

import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = list(map(int, read().split()))
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = np.zeros((h, w), dtype=int)
    right = np.zeros((h, w), dtype=int)
    up = np.zeros((h, w), dtype=int)
    down = np.zeros((h, w), dtype=int)
    left[:, 0] = s[:, 0]
    right[:, -1] = s[:, -1]
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    up[0] = s[0]
    down[-1] = s[-1]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print(((left + right + up + down).max() - 3))


def __starting_point():
    main()

__starting_point()

import numpy as np
h,w = map(int,input().split())
ar = np.array([list(input()) for _ in range(h)]) == '.'
l = np.zeros((h,w),dtype=int)
r = np.zeros((h,w),dtype=int)
u = np.zeros((h,w),dtype=int)
d = np.zeros((h,w),dtype=int)
for i in range(h):
  u[i, :] = (u[i-1]+1)*ar[i]
  d[-i-1, :] = (d[-i]+1)*ar[-i-1]

for j in range(w):
  l[:,j] = (l[:,j-1]+1)*ar[:,j]
  r[:,-j-1] = (r[:,-j]+1)*ar[:,-j-1]
print(np.max(u+d+l+r)-3)

import sys
import numpy as np
input = sys.stdin.readline
h,w = map(int,input().split())
s = (np.array([list(input().strip()) for _ in range(h)])==".").astype(np.int)
l,r,u,d = s.copy(),s.copy(),s.copy(),s.copy()
for i in range(1,w):
  l[:,i] *= l[:,i-1] + 1
  r[:,w-i-1] *= r[:,w-i] + 1

for i in range(1,h):
  u[i] *= u[i-1] + 1
  d[h-i-1] *= d[h-i] + 1
print(max([max(i) for i in l+r+u+d-3]))

import numpy as np

H, W = map(int,input().split())
S = [list(str(input())) for _ in range(H)]
S = np.array(S)
S = (S == '.') * 1

R = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(W):
    if i == 0:
        L[:, 0] = S[:, 0]
        R[:, W - 1] = S[:, W - 1]
    else:
        L[:, i] = L[:, i - 1] * S[:, i] + S[:, i]
        R[:, W - i - 1] = R[:, W - i] * S[:, W - i - 1] + S[:, W - i - 1]
for i in range(H):
    if i == 0:
        U[i] = S[i]
        D[H - 1] = S[H - 1]
    else:
        U[i] = U[i - 1] * S[i] + S[i]
        D[H - i - 1] = D[H - i] * S[H - i - 1] + S[H - i - 1]

print(np.max(R + L + U + D) - 3)

import numpy as np
h, w = map(int, input().split())
arr = np.array([list(input()) for _ in range(h)]) == "."

l = np.zeros((h, w), dtype=int)
r = np.zeros((h, w), dtype=int)
u = np.zeros((h, w), dtype=int)
d = np.zeros((h, w), dtype=int)

for i in range(h):
    u[i] = (u[i - 1] + 1) * arr[i]
    d[- i - 1] = (d[- i] + 1) * arr[- i - 1]

for j in range(w):
    l[:, j] = (l[:, j-1] + 1) * arr[:, j]
    r[:, - j - 1] = (r[:, - j] + 1) * arr[:, - j - 1]

print(np.max(u + d + l + r) - 3)

# D - Lamp
import numpy as np

h, w = map(int, input().split())

# 0: 障害物または壁 1: 通路
# 上下左右の壁の分を加味して+2したグリッドを用意する。
g = np.zeros((h+2,w+2),dtype=np.int64)
for i in range(h):
    grid = np.array(list(input()))
    g[i+1, 1:w+1] = (grid=='.')

# 横について考える
gW = np.copy(g)
gW = np.ravel(gW)
tWLeft = np.arange((w+2)*(h+2))
tWRight = np.copy(tWLeft)

tWLeft[gW==1] = 0
tWRight[gW[::-1]==1] = 0

np.maximum.accumulate(tWLeft, out=tWLeft)
np.maximum.accumulate(tWRight, out=tWRight)

tWRight = len(tWRight) - 1 - tWRight[::-1]

tW = tWRight-tWLeft-1
tW[gW==0] = 0
tW = tW.reshape(h+2, w+2)

# 縦について考える
gH = np.copy(g.T)
gH = np.ravel(gH)
tHLeft = np.arange((w+2)*(h+2))
tHRight = np.copy(tHLeft)

tHLeft[gH==1] = 0
tHRight[gH[::-1]==1] = 0

np.maximum.accumulate(tHLeft, out=tHLeft)
np.maximum.accumulate(tHRight, out=tHRight)

tHRight = len(tHRight) - 1 - tHRight[::-1]

tH = tHRight-tHLeft-1
tH[gH==0] = 0
tH = tH.reshape(w+2, h+2).T

#print(tW)
#print(tH)
print(np.max(tW+tH-1))


'''
# 横について考える
tblW = np.zeros((h, w),dtype=np.int64)
for i in range(h):
    for j in range(w):
        if grid[i, j]=='#' or tblW[i, j]>0:
            continue
        else:
            cnt = 1
            while j+cnt<w and grid[i, j+cnt]!='#':
                cnt += 1
            tblW[i, j:j+cnt] = cnt
print(tblW)
    
# 縦について考える
tblH = np.zeros((h, w),dtype=np.int64)
for j in range(w):
    for i in range(h):
        if grid[i, j]=='#' or tblH[i, j]>0:
            continue
        else:
            cnt = 1
            while i+cnt<h and grid[i+cnt, j]!='#':
                cnt += 1
            tblH[i:i+cnt, j] = cnt
print(tblH)

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

print(ans)
'''

def main():
    import sys
    import numpy as np

    def input(): return sys.stdin.readline().rstrip()

    h, w = map(int, input().split())
    g = np.zeros((h, w), dtype=int)
    for i in range(h):
        g[i] = [int(s == '.') for s in input()]
    
    L = g.copy()
    R = g.copy()
    U = g.copy()
    D = g.copy()
    
    for i in range(1,h):
        U[i] = (U[i-1]+1)*g[i]
        D[~i] = (D[~i+1]+1)*g[~i]
    for j in range(1, w):
        L[:, j] = (L[:, j-1]+1)*g[:,j]
        R[:, ~j] = (R[:, ~j+1]+1)*g[:, ~j]
     
    ans = np.max(L+R+U+D-3)
    print(ans)
            
                
def __starting_point():
    main()
__starting_point()

import numpy as np

H, W = list(map(int, input().split()))
S = [list(input()) for _ in range(H)]
S = np.array(S) == "."

L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(H):
    D[i] = (D[i-1]+1) * S[i]
    U[-i-1] = (U[-i]+1) * S[-i-1]

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

print((np.max(L+R+U+D)-3))


import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w),dtype=np.int64) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(int(np.max(left+right+up+down)-3))

def main():
    NEG = -10**6
    H, W = list(map(int, input().split()))
    S = [input() for _ in range(H)]
    T = [[NEG] * W for _ in range(H)]
    for w in range(W):
        b = NEG
        for h in range(H):
            if S[h][w] == '.':
                if b == NEG:
                    b = h
            else:
                if b != NEG:
                    for j in range(b, h):
                        T[j][w] = h - b
                    b = NEG
        if b != NEG:
            for j in range(b, h + 1):
                T[j][w] = h + 1 - b
    m = 0
    for s, t in zip(S, T):
        b = NEG
        for i in range(len(s)):
            if s[i] == '#':
                if b != NEG:
                    m = max(m, i - b - 1 + max(t[b:i]))
                    b = NEG
            else:
                if b == NEG:
                    b = i
        if b != NEG:
            m = max(m, i - b + max(t[b:i + 1]))
    print(m)

main()


import numpy as np

h, w = map(int, input().split())
s = [input() for _ in range(h)]

t = np.zeros((h, w), dtype=np.int32)
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            t[i][j] = 1

l = np.zeros((h, w), dtype=np.int32)
r = np.zeros((h, w), dtype=np.int32)
u = np.zeros((h, w), dtype=np.int32)
d = np.zeros((h, w), dtype=np.int32)

for i in range(w):
    if i == 0:
        l[:, i] = t[:, i]
    else:
        l[:, i] = (l[:, i-1] + 1) * t[:, i]

for i in range(w-1, -1, -1):
    if i == w-1:
        r[:, i] = t[:, i]
    else:
        r[:, i] = (r[:, i+1] + 1) * t[:, i]

for i in range(h):
    if i == 0:
        u[i] = t[i]
    else:
        u[i] = (u[i-1] + 1) * t[i]

for i in range(h-1, -1, -1):
    if i == h-1:
        d[i] = t[i]
    else:
        d[i] = (d[i+1] + 1) * t[i]

lrud = l+r+u+d-3
print(np.max(lrud))

import numpy as np

H, W = list(map(int, input().split(' ')))

S = np.array([[int(c == '.') for c in input()] for _ in range(H)])

up = S.copy()
down = S.copy()
left = S.copy()
right = S.copy()

for i in range(1, H):
    up[i] = (up[i - 1] + 1) * up[i]
    down[-i - 1] = (down[-i] + 1) * down[-i - 1]

for i in range(1, W):
    left[:, i] = (left[:, i - 1] + 1) * left[:, i]
    right[:, -i - 1] = (right[:, -i] + 1) * right[:, -i - 1]

print((np.max(up + down + left + right) - 3))


import numpy as np

def lamp(s):
    h = len(s)
    w = s.size//h
    A = np.zeros((h,w),np.int64)
    for i in range(1,w):
        A[:,i] = np.where(s[:,i-1]==".", A[:,i-1] + 1, 0)
    return A

H,W = map(int,input().split())
S = np.array([[*input()] for _ in range(H)])

L = lamp(S)
R = lamp(S[:,::-1])[:,::-1]
U = lamp(S.T).T
D = lamp(S.T[:,::-1])[:,::-1].T

LRUD = L+R+U+D
print(LRUD[S == "."].max().max()+1)

from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    h,w=map(int,readline().split())
    grid=[readline().strip() for _ in range(h)]
    grid=[[1 if grid[i][j]=="." else 0 for j in range(w)] for i in range(h)]
    grid=np.array(grid,dtype=np.int64)

    up=np.zeros((h,w),dtype="int64")
    up[0]=grid[0]
    for i in range(1,h):
        up[i]=(up[i-1]+1)*grid[i]
    
    down=np.zeros((h,w),dtype="int64")
    down[-1]=grid[-1]
    for i in range(h-2,-1,-1):
        down[i]=(down[i+1]+1)*grid[i]
    
    left=np.zeros((h,w),dtype="int64")
    left[:,0]=grid[:,0]
    for i in range(1,w):
        left[:,i]=(left[:,i-1]+1)*grid[:,i]
    
    right=np.zeros((h,w),dtype="int64")
    right[:,-1]=grid[:,-1]
    for i in range(w-2,-1,-1):
        right[:,i]=(right[:,i+1]+1)*grid[:,i]

    ans=(up+down+left+right-3).max()
    print(ans)
    
def __starting_point():
    main()
__starting_point()

import numpy as np
H ,W = list(map(int,input().split()))

maze = [[] for _ in range(H)]
for i in range(H):
    maze[i] = np.array(list(input())) == "."
maze = np.array(maze)

up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)

for i in range(H):
    up[i] = (up[i-1] + 1)*maze[i]
    down[-(i+1)] = (down[-i] + 1)*maze[-(i+1)] 
    
#print(up)
#print(down)

for i in range(W):
    right[:, i] = (right[:, i-1] + 1)*maze[:, i]
    left[:, -(i+1)] = (left[:, -i] + 1)*maze[:, -(i+1)]

print((np.max(up+down+right+left)-3))


# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S], np.bool)
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
    #行列の列を取り出す時の記法
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]


answer = ((up + down + left + right) * S).max() + 1
#自身を数えないことで特殊な場合をなくしている
print(answer)


H,W=list(map(int,input().split()))
import numpy as np
m=np.array([[0 if i=="#" else 1 for i in input()] for i in range(H)])
l,r,u,d=np.zeros((4,H,W))
for i in range(H):
   u[i]=(u[i-1]+1)*m[i]
   d[-i-1]=(d[-i]+1)*m[-i-1]
for i in range(W):
   r[:,i]=(r[:,i-1]+1)*m[:,i]
   l[:,-i-1]=(l[:,-i]+1)*m[:,-i-1]
print(int(np.max(u+r+l+d))-3)

import numpy as np
H, W = map(int,input().split())
l = np.zeros((H,W), dtype=int)
r = np.zeros((H,W), dtype=int)
d = np.zeros((H,W), dtype=int)
u = np.zeros((H,W), dtype=int)
s = np.array([list(input()) for _ in range(H)]) == "."
for i in range(H):
    u[i] = (u[i-1]+1)*s[i]
    d[-i-1] = (d[-i]+1)*s[-i-1]
for i in range(W):
    l[:, i] = (l[:, i-1]+1)*s[:, i]
    r[:, -i-1] = (r[:, -i]+1)*s[:, -i-1]
print(np.max(u+d+l+r)-3)

import sys
import numpy as np
def main():
    input = sys.stdin.readline
    h, w = map(int, input().split())
    s = np.array([list(input().rstrip()) for _ in range(h)])
    t = np.zeros((h+2, w+2))
    t[1:-1, 1:-1][s == "."] = 1
    row = np.zeros((h+2, w+2))
    col = np.zeros((w+2, h+2))
    for i in range(1, h+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        row[i, idx[:-1]+1] += dif-1
        row[i, idx[1:]] -= dif-1
        row[i] = np.cumsum(row[i])
    t = t.T
    for i in range(1, w+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        col[i, idx[:-1]] += dif-2
        col[i, idx[1:]] -= dif-2
        col[i] = np.cumsum(col[i])
    col = col.T
    cost = np.add(row, col)
    print(int(np.max(cost)))

def __starting_point():
    main()
__starting_point()

import numpy as np

h, w = map(int, input().split())
S = list(list(input()) for _ in range(h))
S = np.array(S)
S_int = np.zeros_like(S, dtype=int)
S_int[S=='.'] = 1

def getLR(d, width, height):
  L = np.zeros_like(d)
  R = L.copy()
  L[:][0] = 0
  R[:][-1] = 0
  for i in range(1, width):
    ridx = width - 1 - i
    L[:,i] = d[:,i] * (L[:,i-1] + d[:,i-1])
    R[:,ridx] = d[:,ridx] * (R[:,ridx+1] + d[:,ridx+1])
  return L, R

L, R = getLR(S_int, w, h)
U, D = getLR(S_int.T, h, w)
print((L+R+U.T+D.T).max() + 1)

#import math
#import itertools
import numpy as np
#from collections import deque
# sys.setrecursionlimit(10 ** 6)
#MOD = 10 ** 9 + 7
#INF = 10 ** 9
#PI = 3.14159265358979323846

INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))

def do():
    h,w=INTM()
    ban=np.zeros((h,w),dtype=np.int16)
    for i in range(h):
        s=STR()
        for i1 in range(len(s)):
            if s[i1]==".":
                ban[i][i1]=1

    left =np.zeros((h,w),dtype=np.int16)
    right=np.zeros((h,w),dtype=np.int16)
    up   =np.zeros((h,w),dtype=np.int16)
    down =np.zeros((h,w),dtype=np.int16)
    #print(up)
    for i in range(w):
        i2=w-1-i
        if i==0:
            left[:,i]=ban[:,i]
            right[:,i2]=ban[:,i2]
        else:
            left[:,i]=ban[:,i]*(left[:,i-1]+1)
            right[:,i2]=ban[:,i2]*(right[:,i2+1]+1)
    
    for i in range(h):
        i2=h-1-i
        if i==0:
            up[i,:]=ban[i,:]
            down[i2,:]=ban[i2,:]
        else:
            up[i,:]=ban[i,:]*(up[i-1,:]+1)
            down[i2,:]=ban[i2,:]*(down[i2+1,:]+1)
    

    anslist=down+up+right+left
    ans=0
    for i in anslist:
        ans=max(ans,max(i))
    print(ans-3)


def __starting_point():
    do()
__starting_point()

import numpy as np
H,W=list(map(int, input().split()))
S=[]
for h in range(H):
    s=list(input())
    S.append(s)
S=np.array(S)
ruit=np.zeros((H,W))
ruit[0,:]=np.where(S[0,:]==".",1,0)
ruil=np.zeros((H,W))
ruil[:,0]=np.where(S[:,0]==".",1,0)
ruir=np.zeros((H,W))
ruir[:,-1]=np.where(S[:,-1]==".",1,0)
ruib=np.zeros((H,W))
ruib[-1,:]=np.where(S[-1,:]==".",1,0)

for h in range(1,H):
    nowt=np.where(S[h,:]==".",1,0)
    ruit[h,:]=(ruit[h-1,:]+nowt)*nowt

    nowb=np.where(S[-(h+1),:]==".",1,0)
    ruib[-(h+1),:]=(ruib[-h,:]+nowb)*nowb

for w in range(1,W):
    nowl=np.where(S[:,w]==".",1,0)
    ruil[:,w]=(ruil[:,w-1]+nowl)*nowl
    nowr=np.where(S[:,-(w+1)]==".",1,0)
    ruir[:,-(w+1)]=(ruir[:,-w]+nowr)*nowr
#print(ruir)
#print(ruil)
#print(ruib)
print((int((ruit+ruib+ruil+ruir-3).max())))


    





#abc129d
import numpy as np
h,w=list(map(int,input().split()))
s=np.array([list(input()) for i in range(h)])=='.'
u=np.zeros((h,w),dtype=int)
d=np.zeros((h,w),dtype=int)
l=np.zeros((h,w),dtype=int)
r=np.zeros((h,w),dtype=int)
for i in range(h):
 u[i]=(u[i-1]+1)*s[i]
 d[-i-1]=(d[-i]+1)*s[-i-1]
for i in range(w):
 l[:,i]=(l[:,i-1]+1)*s[:,i]
 r[:,-i-1]=(r[:,-i]+1)*s[:,-i-1]
print((np.max(u+d+l+r-3)))


import numpy as np
h,w=list(map(int,input().split()))
s=[]
for _ in range(h):
    si=input()
    si=si.replace('.', '1')
    si=si.replace('#', '0')
    s.append(list(map(int,si)))
s=np.array(s)

left=np.zeros((h,w))
right=np.zeros((h,w))
up=np.zeros((h,w))
down=np.zeros((h,w))

for i in range(w):
    if(i==0):
        left[:,i]=s[:,i]
        right[:,w-i-1]=s[:,w-i-1]
    else:
        left[:,i]=(left[:,i-1]+1)*s[:,i]
        right[:,w-i-1]=(right[:,w-i]+1)*s[:,w-i-1]

for i in range(h):
    if(i==0):
        down[i,:]=s[i,:]
        up[h-i-1,:]=s[h-i-1,:]
    else:
        down[i,:]=(down[i-1,:]+1)*s[i,:]
        up[h-i-1,:]=(up[h-i,:]+1)*s[h-i-1,:]

ans=left+right+up+down-3
print((int(np.max(ans))))


#!/usr/bin/env python
# coding: utf-8

# In[1]:


import numpy as np


# In[2]:


H, W = list(map(int, input().split()))
S = np.ones((H, W), dtype=np.bool)
for i in range(H):
    S[i] = [s == "." for s in input()]


# In[3]:


up = np.zeros((H, W), dtype=np.int16)
down = np.zeros((H, W), dtype=np.int16)
left = np.zeros((H, W), dtype=np.int16)
right = np.zeros((H, W), dtype=np.int16)

# up
up[0, :] = S[0, :]
for h in range(1, H):
    up[h, :] = up[h - 1, :] + 1
    up[h, :] *= S[h, :]

# down
down[H - 1, :] = S[H - 1, :]
for h in reversed(list(range(0, H - 1))):
    down[h, :] = down[h + 1, :] + 1
    down[h, :] *= S[h, :]

# left
left[:, 0] = S[:, 0]
for w in range(1, W):
    left[:, w] = left[:, w - 1] + 1
    left[:, w] *= S[:, w]

# right
right[:, W - 1] = S[:, W - 1]
for w in reversed(list(range(0, W - 1))):
    right[:, w] = right[:, w + 1] + 1
    right[:, w] *= S[:, w]

ans = np.max(up + down + left + right - 3)
print(ans)


# In[ ]:






import numpy as np
def main():
    printl = lambda l: [print(x) for x in l]
    H, W = list(map(int, input().split()))
    A = np.array([[1 if i == '.' else 0 for i in input()] for _ in range(H)])
    L = np.zeros((H, W), dtype = np.int)
    R = np.zeros((H, W), dtype = np.int)
    U = np.zeros((H, W), dtype = np.int)
    D = np.zeros((H, W), dtype = np.int)
    L[:, 0] = A[:, 0]
    for w in range(1, W):
        L[:, w] = (L[:, w - 1] + 1) * A[:, w]
    R[:, W - 1] = A[:, W - 1]
    for w in range(W - 2, -1, -1):
        R[:, w] = (R[:, w + 1] + 1) * A[:, w]
    U[0, :] = A[0, :]
    for h in range(1, H):
        U[h, :] = (U[h - 1, :] + 1) * A[h, :]
    D[H - 1, :] = A[H - 1, :]
    for h in range(H - 2, -1, -1):
        D[h, :] = (D[h + 1, :] + 1) * A[h, :]
    print(np.max(L + R + U + D - 3))

def __starting_point():
    main()

__starting_point()

import numpy as np

H,W = map(int, input().split())
S = []
for h in range(H):
  S.append(list(input()))
G = np.array(S)
G = np.where(G == ".", 1, 0)

## 事前計算
## マスごとに、「そのマスにライトを設置した場合に照らせるマスの数」を上下左右の4配列で求める
L = np.zeros((H,W),dtype=int)
R = np.zeros((H,W),dtype=int)
U = np.zeros((H,W),dtype=int)
D = np.zeros((H,W),dtype=int)

for w in range(1,W):
  L[:,w] = (L[:,w-1]+1)*(G[:,w-1])
for w in range(W-1,0,-1):
  R[:,w-1] = (R[:,w]+1)*(G[:,w])
for h in range(1,H):
  U[h] = (U[h-1]+1)*(G[h-1])
for h in range(H-1,0,-1):
  D[h-1] = (D[h]+1)*(G[h])

ans = np.max((L+R+U+D)*G)+1
print(ans)

import numpy as np
h,w = map(int,input().split())
s = [[] for j in range(h)]
for i in range(h):
    tmp = input()
    for j in tmp:
        if j == '.':
            s[i].append(1)
        else:
            s[i].append(0)


L = np.zeros((h,w))
R = np.zeros((h,w))
U = np.zeros((h,w))
D = np.zeros((h,w))
s = np.array(s)

for i in range(w):
    L[:,i] = (L[:,i-1]+1)*s[:,i]
    R[:,-1-i] = (R[:,-i]+1)*s[:,-1-i]
    
for i in range(h):
    U[i,:] = (U[i-1,:]+1)*s[i,:]
    D[-1-i,:] = (D[-i,:]+1)*s[-i-1,:]
    
print(int(np.max(L+R+D+U-3)))

import numpy as np

H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
S = np.array(S)
S = (S == '.') * 1

R = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(W):
    if i == 0:
        L[:, 0] = S[:, 0]
        R[:, W - 1] = S[:, W - 1]
    else:
        L[:, i] = L[:, i - 1] * S[:, i] + S[:, i]
        R[:, W - i - 1] = R[:, W - i] * S[:, W - i - 1] + S[:, W - i - 1]
for i in range(H):
    if i == 0:
        U[i] = S[i]
        D[H - 1] = S[H - 1]
    else:
        U[i] = U[i - 1] * S[i] + S[i]
        D[H - i - 1] = D[H - i] * S[H - i - 1] + S[H - i - 1]

print(np.max(R + L + U + D) - 3)

import numpy as np


H, W = list(map(int, input().split()))
S = np.ones((H, W), dtype=np.bool)
for i in range(H):
    S[i] = [s == "." for s in input()]

up = np.zeros((H, W), dtype=np.int16)
down = np.zeros((H, W), dtype=np.int16)
left = np.zeros((H, W), dtype=np.int16)
right = np.zeros((H, W), dtype=np.int16)

# up
up[0, :] = S[0, :]
for h in range(1, H):
    up[h, :] = up[h - 1, :] + 1
    up[h, :] *= S[h, :]

# down
down[H - 1, :] = S[H - 1, :]
for h in reversed(list(range(0, H - 1))):
    down[h, :] = down[h + 1, :] + 1
    down[h, :] *= S[h, :]

# left
left[:, 0] = S[:, 0]
for w in range(1, W):
    left[:, w] = left[:, w - 1] + 1
    left[:, w] *= S[:, w]

# right
right[:, W - 1] = S[:, W - 1]
for w in reversed(list(range(0, W - 1))):
    right[:, w] = right[:, w + 1] + 1
    right[:, w] *= S[:, w]

ans = np.max(up + down + left + right - 3)
print(ans)


import numpy as np
h, w = list(map(int, input().split()))
arr = np.array([list(input()) for _ in range(h)]) == "."
# print(arr)
l = np.zeros((h, w), dtype=int)
r = np.zeros((h, w), dtype=int)
u = np.zeros((h, w), dtype=int)
d = np.zeros((h, w), dtype=int)

for i in range(h):
    u[i] = (u[i - 1] + 1) * arr[i] #arrがFalseだと0になる
    d[- i - 1] = (d[- i] + 1) * arr[- i - 1]

for j in range(w):
    l[:, j] = (l[:, j-1] + 1) * arr[:, j]
    r[:, - j - 1] = (r[:, - j] + 1) * arr[:, - j - 1]
# print(u)
print((np.max(u + d + l + r) - 3))