Problem:
 Score : 400 points    Problem Statement 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 1 4 6
#..#..
.....#
....#.
#.#...      Sample Output 1 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.       Sample Input 2 8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#      Sample Output 2 13

Solution (Python):

import sys

def solve(H: int, W: int, S: "List[str]"):
    ss = [list(s) for s in S]
    answer = 0
    right = [[0]*W for _ in range(H)]
    left = [[0]*W for _ in range(H)]
    up = [[0]*W for _ in range(H)]
    down = [[0]*W for _ in range(H)]

    for h in range(H):
        for j in range(W):
            if ss[h][j] == ".":
                if j>0:
                    right[h][j] = 1+right[h][j-1]
                else:
                    right[h][j] += 1
            else:
                right[h][j] = 0

        for j in range(W-1,-1,-1):
            if ss[h][j] == ".":
                if j<W-1:
                    left[h][j] = 1+left[h][j+1]
                else:
                    left[h][j] += 1
            else:
                left[h][j] = 0
    for w in range(W):                
        for i in range(H-1,-1,-1):
            if ss[i][w] == '.':
                if i < H-1:
                    up[i][w] = 1 + up[i+1][w]
                else:
                    up[i][w] +=1
            else:
                up[i][w] = 0
        for i in range(0,H):
            if ss[i][w] == '.':
                if i > 0:
                    down[i][w] = 1 + down[i-1][w]
                else:
                    down[i][w] +=1
            else:
                down[i][w] = 0

    for i in range(H):
        for j in range(W):
            answer = max(answer,right[i][j]+left[i][j]+up[i][j]+down[i][j]-3)

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    S = [next(tokens) for _ in range(H)]  
    solve(H, W, S)

if __name__ == '__main__':
    main()

Solution (Python):
tmp = list(map(int, input().split()))
h = tmp[0]
w = tmp[1] 

s = ['None'] * (h + 1)
for i in range(h):
  s[i] = input()
  s[i] = s[i] + '
s[h] = '

ans = 0

sta = -1
cnt = 0
pt = [[0] * w for i in range(h)]
for i in range(h):
  for j in range(w+1):
    if s[i][j] == '
      if sta != -1:
        for k in range(sta, j):
          pt[i][k] = cnt
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

for i in range(w):
  for j in range(h+1):
    if s[j][i] == '
      if sta != -1:
        for k in range(sta, j):
          pt[k][i] += cnt - 1
          if pt[k][i] > ans:
            ans = pt[k][i]
      cnt = 0
      sta = -1
    else:
      if sta == -1:
        sta = j
      cnt += 1

print(ans)

Solution (Python):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]


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

for i in range(H):
  for j in range(W):
    if S[i][j] == "
      L[i][j] = 0
    elif j == 0:
      L[i][j] = 1
    else:
      L[i][j] = L[i][j - 1] + 1

for i in range(H):
  for j in reversed(range(W)):
    if S[i][j] == "
      R[i][j] = 0
    elif j == W - 1:
      R[i][j] = 1
    else:
      R[i][j] = R[i][j + 1] + 1

for i in range(H):
  for j in range(W):
    if S[i][j] == "
      U[i][j] = 0
    elif i == 0:
      U[i][j] = 1
    else:
      U[i][j] = U[i - 1][j] + 1

for i in reversed(range(H)):
  for j in range(W):
    if S[i][j] == "
      D[i][j] = 0
    elif i == H - 1:
      D[i][j] = 1
    else:
      D[i][j] = D[i + 1][j] + 1

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] - 3)

print(ans)

Solution (Python):
def main():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]

    m = [[0] + [0 if e == "
    m.append([0] * (w + 2))
    m.insert(0, [0] * (w + 2))

    m_t = [[m[i][j] for i in range(h+2)] for j in range(w+2)]

    lr = []
    for i in range(h + 2):
        sm = 0
        row = []
        for j in range(w + 2):
            if m[i][j]:
                sm += 1
            else:
                row += [sm] * sm + [0]
                sm = 0

        lr.append(row)

    ud = []
    for i in range(w + 2):
        sm = 0
        row = []
        for j in range(h + 2):
            if m_t[i][j]:
                sm += 1
            else:
                row += [sm] * sm + [0]
                sm = 0

        ud.append(row)

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):


H,W=map(int,input().split())
S=[]
ans=0

for _ in range(H):
    S.append(list(input()))

l=[[0]*W for _ in range(H)]

for h in range(H):
    count=0
    start=0
    for i in range(W):
        if S[h][i]=="
            count=0
            start=i+1
        else:
            count+=1
            l[h][i]+=count

for h in range(H):
    count=0
    start=W-1
    for i in range(W)[::-1]:
        if S[h][i]=="
            count=0
            start=i
        else:
            count+=1
            l[h][i]+=count

for w in range(W):
    count=0
    start=0
    for i in range(H):
        if S[i][w]=="
            count=0
            start=i+1
        else:
            count+=1
            l[i][w]+=count

for w in range(W):
    count=0
    start=H-1
    for i in range(H)[::-1]:
        if S[i][w]=="
            count=0
            start=i
        else:
            count+=1
            l[i][w]+=count
            ans=max(ans,l[i][w])

print(ans-3)

Solution (Python):
H, W = map(int, input().split())
s, ans = [], 0
dpr = [[0] * W for _ in range(H)]
dpl = [[0] * W for _ in range(H)]
dpd = [[0] * W for _ in range(H)]
dpu = [[0] * W for _ in range(H)]

for i in range(H):
    s.append(input())


for i in range(H):
    for j in reversed(range(W)):
        if j == W-1 and s[i][j] == '.':
            dpr[i][j] = 1
        elif s[i][j] == '
            dpr[i][j] = 0
        else:
            dpr[i][j] = dpr[i][j+1] + 1


for i in range(H):
    for j in range(0, W):
        if j == 0 and s[i][j] == '.':
            dpl[i][j] = 1
        elif s[i][j] == '
            dpl[i][j] = 0
        else:
            dpl[i][j] = dpl[i][j-1] + 1


for i in reversed(range(H)):
    for j in range(W):
        if i == H-1 and s[i][j] == '.':
            dpd[i][j] = 1
        elif s[i][j] == '
            dpd[i][j] = 0
        else:
            dpd[i][j] = dpd[i+1][j] + 1


for i in range(0, H):
    for j in range(W):
        if i == 0 and s[i][j] == '.':
            dpu[i][j] = 1
        elif s[i][j] == '
            dpu[i][j] = 0
        else:
            dpu[i][j] = dpu[i-1][j] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        cnt = dpr[i][j] + dpl[i][j] + dpd[i][j] + dpu[i][j] - 3
        ans = max(ans, cnt)

print(ans)

Solution (Python):
h, w = map(int, input().split())
area = [[0] * w for _ in range(h)]
s = [input() for _ in range(h)]

for i, row in enumerate(s):
    cnt = 0
    for j, x in enumerate(row):
        if x == "
            for k in range(j-cnt, j): area[i][k] = cnt
            cnt = 0
        else: cnt += 1
    for k in range(w-cnt, w): area[i][k] = cnt

for i in range(w):
    cnt = 0
    for j in range(h):
        x = s[j][i]
        if x == "
            for k in range(j-cnt, j): area[k][i] += cnt - 1
            cnt = 0
        else: cnt += 1
    for k in range(h-cnt, h): area[k][i] += cnt - 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, area[i][j])

print(ans)

Solution (Python):
import numpy as np
import sys
line = sys.stdin.readline

H, W = map(int, line().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = (np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == '.') * 1
left = np.zeros((H + 2, W + 2), np.int32)
right = np.zeros((H + 2, W + 2), np.int32)
up = np.zeros((H + 2, W + 2), np.int32)
down = np.zeros((H + 2, W + 2), np.int32)


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

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

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

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

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

Solution (Python):
import numpy as np
import sys
def main():
    line = sys.stdin.readline

    H, W = map(int, line().split())
    grid = np.zeros((H + 2, W + 2), np.int32)
    grid[1:-1, 1:-1] = (np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == '.') * 1
    left = np.zeros((H + 2, W + 2), np.int32)
    right = np.zeros((H + 2, W + 2), np.int32)
    up = np.zeros((H + 2, W + 2), np.int32)
    down = np.zeros((H + 2, W + 2), np.int32)

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

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

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
import sys
line = sys.stdin.readline

H, W = map(int, line().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = (np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == '.') * 1
left = np.zeros((H + 2, W + 2), np.int32)
right = np.zeros((H + 2, W + 2), np.int32)
up = np.zeros((H + 2, W + 2), np.int32)
down = np.zeros((H + 2, W + 2), np.int32)


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

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

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

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

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

Solution (Python):
import sys
h, w = [int(i) for i in sys.stdin.readline().split()]
s_ls = []
for y in range(h):
    s = input()
    s_ls.append(s)
r_ij = [[0 for i in range(w)] for j in range(h)]
l_ij = [[0 for i in range(w)] for j in range(h)]
d_ij = [[0 for i in range(w)] for j in range(h)]
u_ij = [[0 for i in range(w)] for j in range(h)]
for y in range(h):
    for x in range(w):
        if s_ls[y][x] == "
            continue
        r_ij[y][x] = r_ij[y][max(0, x-1)] + 1
        d_ij[y][x] = d_ij[max(0, y-1)][x] + 1
for y in range(h-1,-1,-1):
    for x in range(w-1,-1,-1):
        if s_ls[y][x] == "
            continue
        l_ij[y][x] = l_ij[y][min(w-1, x+1)] + 1
        u_ij[y][x] = u_ij[min(y+1, h-1)][x] + 1

best = -1e10
for y in range(h):
    for x in range(w):
        res = r_ij[y][x] + l_ij[y][x] + u_ij[y][x] + d_ij[y][x] - 3
        if res > best:
            best = res
print(best)

Solution (Python):
H,W = map(int,input().split())
field = [list(input()) for _ in range(H)]


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


for h in range(H):
  for w in range(W-1,-1,-1):
    if field[h][w] == "
      R[h][w] = 0
    elif w == W-1:
      R[h][w] = 1
    else:
      R[h][w] = R[h][w+1] + 1

for h in range(H-1,-1,-1):
  for w in range(W):
    if field[h][w] == "
      D[h][w] = 0
    elif h == H-1:
      D[h][w] = 1
    else:
      D[h][w] = D[h+1][w] + 1


ans = 0
for h in range(H):
  for w in range(W):
    if field[h][w] == "
      L[h][w] = 0
    elif w == 0:
      L[h][w] = 1
    else:
      L[h][w] = L[h][w-1] + 1
    if field[h][w] == "
      U[h][w] = 0
    elif h == 0:
      U[h][w] = 1
    else:
      U[h][w] = U[h-1][w] + 1
    ans = max(ans,L[h][w] + R[h][w] + D[h][w] + U[h][w] - 3)

print(ans)

Solution (Python):
import numpy as np
import sys
buf = sys.stdin.buffer

H, W = map(int, buf.readline().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = (np.array(list(map(list, buf.read().decode('utf-8').split()))).reshape(H, W) == '.') * 1
grid_v = grid.T

right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid < 1, np.arange(W + 2), 10 ** 10)).copy(), axis=1))
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10)).copy(), axis=1)).T

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

Solution (Python):
import numpy as np
import sys
line = sys.stdin.readline

H, W = map(int, line().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = (np.array([list(line().rstrip()) for _ in range(H)]).reshape(H, W) == '.') * 1
grid_v = grid.T

right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid < 1, np.arange(W + 2), 10 ** 10)).copy(), axis=1))
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10)).copy(), axis=1)).T

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

Solution (Python):
import numpy as np
import sys
buf = sys.stdin.buffer

H, W = map(int, buf.readline().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = np.where(np.array(list(map(list, buf.read().decode('utf-8').split()))).reshape(H, W) == '.', 1, 0)
grid_v = grid.T

right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid < 1, np.arange(W + 2), 10 ** 10)).copy(), axis=1))
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.fliplr(np.minimum.accumulate(np.fliplr(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10)).copy(), axis=1)).T

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

Solution (Python):
import sys
from itertools import accumulate
input = sys.stdin.readline
def inputs():return [int(x) for x in input().split()]
H,W = inputs()
meiro = [tuple(input()) for i in range(H)]

imosw = [[0]*(W) for _ in range(H)]
imosh = [[0]*(H) for _ in range(W)]
for i in range(H):
    cnt=0
    for j in range(W):
        if meiro[i][j]=="
            if cnt!=0:
                imosw[i][j]-=cnt
                imosw[i][j-cnt]+=cnt
            cnt = 0
        else:
            cnt+=1
    if cnt!=0:
    	imosw[i][W-1-cnt+1]+=cnt
    imosw[i][:]=list(accumulate(imosw[i]))
for j in range(W):
    cnt= 0
    imos=[0]*H
    for i in range(H):
        if meiro[i][j]=="
            if cnt!=0:
                imos[i]-=cnt
                imos[i-cnt]+=cnt
            cnt = 0
        else:
            cnt+=1
    if cnt!=0:
    	imos[H-1-cnt+1]+=cnt
    imosh[j]=list(accumulate(imos))
    
ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans,imosw[i][j]+imosh[j][i]-1)
print(ans)

Solution (Python):
H, W = map(int, input().split())
grid = [input() for _ in range(H)]

left   = [[0] * 2005 for i in range(2005)]
right  = [[0] * 2005 for i in range(2005)]
top    = [[0] * 2005 for i in range(2005)]
bottom = [[0] * 2005 for i in range(2005)]

for h in range(H):
	cur = 0
	for w in range(W):
		if grid[h][w] == '
			left[h][w] = -1
			cur = 0
		else:
			left[h][w] = cur
			cur += 1
	cur = 0
	for w in range(W-1, -1, -1):
		if grid[h][w] == '
			right[h][w] = -1
			cur = 0
		else:
			right[h][w] = cur
			cur += 1

for w in range(W):
	cur = 0
	for h in range(H):
		if grid[h][w] == '
			top[h][w] = -1
			cur = 0
		else:
			top[h][w] = cur
			cur += 1

	cur = 0
	for h in range(H-1, -1, -1):
		if grid[h][w] == '
			bottom[h][w] = -1
			cur = 0
		else:
			bottom[h][w] = cur
			cur += 1

ans = 0
for h in range(H):
	for w in range(W):
		if grid[h][w] == '.':
			ans = max(ans, left[h][w] + right[h][w] + top[h][w] + bottom[h][w] + 1)
print(ans)

Solution (Python):
H,W=map(int,input().split())
field=[list(input()) for _ in range(H)]

l=[[0]*W for _ in range(H)]
r=[[0]*W for _ in range(H)]
u=[[0]*W for _ in range(H)]
d=[[0]*W for _ in range(H)]

for j in range(H):
  for i in range(W):
    if field[j][i]==".":
      if i==0:
        l[j][i]=1
      else:
        l[j][i]=l[j][i-1]+1
      if j==0:
        u[j][i]=1
      else:
        u[j][i]=u[j-1][i]+1
        

for j in reversed(range(H)):
  for i in reversed(range(W)):
    if field[j][i]==".":
      if i==W-1:
        r[j][i]=1
      else:
        r[j][i]=r[j][i+1]+1
      if j==H-1:
        d[j][i]=1
      else:
        d[j][i]=d[j+1][i]+1

A=[]
for j in range(H):
  for i in range(W):
    A.append(l[j][i]+r[j][i]+d[j][i]+u[j][i]-3)

print(max(A))

Solution (Python):
from collections import deque
def solve():
  h,w = (int(i) for i in input().split())
  maze = []
  for i in range(h):
    tmp = input()
    maze.append(tmp)
  l = [[0]*w for _ in range(h)]
  r = [[0]*w for _ in range(h)]
  u = [[0]*w for _ in range(h)]
  d = [[0]*w for _ in range(h)]
  cur = 0
  for i in range(h):
    cur = 0
    for j in range(w):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      l[i][j] = cur
  for i in range(h):
    cur = 0
    for j in range(w-1,-1,-1):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      r[i][j] = cur
  for j in range(w):
    cur = 0
    for i in range(h):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      d[i][j] = cur
  for j in range(w):
    cur = 0
    for i in range(h-1,-1,-1):
      if maze[i][j] == ".":
        cur += 1
      else:
        cur = 0
      u[i][j] = cur      
  ans = 0
  for i in range(h):
    for j in range(w):
      now = l[i][j]+r[i][j]+u[i][j]+d[i][j] -3
      ans = max(now,ans)
  print(ans)
solve()

Solution (Python):
H,W = map(int, input().split())
S = [input() for _ in range(H)]

L = [[0]*W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "." and j > 0:
            L[i][j] = L[i][j-1]+1
        elif S[i][j] == ".":
            L[i][j] = 1
    for j in range(W-1, 0, -1):
        if L[i][j-1] > 0:
            L[i][j-1] = max(L[i][j-1], L[i][j])
            
L2 = [[0]*W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if S[i][j] == "." and i > 0:
            L2[i][j] = L2[i-1][j] + 1
        elif S[i][j] == ".":
            L2[i][j] = 1
    for i in range(H-1, 0, -1):
        if L2[i-1][j] > 0:
            L2[i-1][j] = max(L2[i-1][j], L2[i][j])
            
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, L[i][j]+L2[i][j]-1)
        
print(ans)

Solution (Python):




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

S = [list(input()) for _ in range(H)]

def trans(M):
    output_list = []
    for col in range(len(M[0])):
        tmp = []
        for row in range(len(M)):
            tmp.append(M[row][col])
        output_list.append(tmp)
    return output_list
            
def n_row_lighten(l):
    output_list = []
    left_block_idx = -1
    
    for idx in range(len(l)):
        if l[idx] == "
            right_block_idx = idx
            for _ in range(right_block_idx - left_block_idx - 1):
                output_list.append(right_block_idx - left_block_idx - 1)
            output_list.append(0)
            left_block_idx = right_block_idx
            
        if idx == len(l) - 1 and l[idx] == ".":
            right_block_idx = idx + 1
            for _ in range(right_block_idx - left_block_idx - 1):
                output_list.append(right_block_idx - left_block_idx - 1)
        
    return output_list        

def n_matrix_lighten(S):
    output_list = []
    for row in range(len(S)):
        output_list.append(n_row_lighten(S[row]))
    return output_list


ans = 0
tmp1 = n_matrix_lighten(S)
tmp2 = trans(n_matrix_lighten(trans(S)))

for row in range(H):
    for col in range(W):
        ans = max(ans, tmp1[row][col] + tmp2[row][col] - 1)

print(ans)