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 numpy as np


def solve():
    H, W = list(map(int, input().split()))
    grid = []
    for i in range(H):
        s = input()
        grid.append(list(s))
    grid = (np.array(grid) == ".") * 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 w in range(W):
        if w == 0:
            L[:, w] = grid[:, w]
        else:
            L[:, w] = (L[:, w-1]+1) * grid[:, w]

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

    
    for h in range(H):
        if h == 0:
            U[h] = grid[h]
        else:
            U[h] = (U[h-1]+1) * grid[h]

    
    for h in range(H-1, -1, -1):
        if h == H-1:
            D[h] = grid[h]
        else:
            D[h] = (D[h+1]+1) * grid[h]

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


if __name__ == "__main__":
    solve()

Solution (Python):

import numpy as np

h, w = map(int, input().split())
s = [[] for _ in range(h)]
for i in range(h):
    s[i] = list(input())
s_0 = np.array(s)
s_90 = np.rot90(s_0)
s_180 = np.rot90(s_90)
s_270 = np.rot90(s_180)

c_0 = np.zeros(h*w).reshape(h,-1)
c_0[s_0 == '.'] = 1
c_90 = np.zeros(h*w).reshape(w,-1)
c_90[s_90 == '.'] = 1
c_180 = np.zeros(h*w).reshape(h,-1)
c_180[s_180 == '.'] = 1
c_270 = np.zeros(h*w).reshape(w,-1)
c_270[s_270 == '.'] = 1


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


for j in range(1, h):
    c_90[:, j] += c_90[:, j-1] * c_90[:, j]
c_90 = np.rot90(np.rot90(np.rot90(c_90)))


for j in range(1, w):
    c_180[:, j] += c_180[:, j-1] * c_180[:, j]
c_180 = np.rot90(np.rot90(c_180))


for j in range(1, h):
    c_270[:, j] += c_270[:, j-1] * c_270[:, j]
c_270 = np.rot90(c_270)


c = c_0 + c_90 + c_180 + c_270 - 3
print(int(c.max()))

Solution (Python):
H,W=map(int,input().split())
s=[]
for i in range(H):
    si=[]
    Si=input()
    for j in range(W):
        si.append(Si[j]=='.')
    s.append(si)


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


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


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


D=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in reversed(range(H)):
        if s[i][j]:
            if 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):
H,W=map(int,input().split())
s=[]
for i in range(H):
    si=[]
    Si=input()
    for j in range(W):
        si.append(Si[j]=='.')
    s.append(si)


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


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


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


D=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in reversed(range(H)):
        if i==H-1 and s[i][j]:
            D[i][j]=1
        elif s[i][j]:
            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):
H, W = map(int, input().split())


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

for row in range(H):
	S = list(map(str, input()))
	for column in range(W):
		if S[column] == "
			
			square[row][column] = -1
			
for row in range(H):
	done = [False for _ in range(W)]
	for column in range(W):
		if square[row][column] == -1: continue
		if done[column]: continue
		l = 1
		while column + l <= W - 1:
			if square[row][column + l] == -1: break
			l += 1
		for i in range(column, column + l):
			square[row][i] += l
			done[i] = True
			
for column in range(W):
	done = [False for _ in range(H)]
	for row in range(H):
		if square[row][column] == -1: continue
		if done[row]: continue
		l = 1
		while row + l <= H - 1:
			if square[row + l][column] == -1: break
			l += 1
		for i in range(row, row + l):
			square[i][column] += l
			done[i] = True

ret = 0			
for row in range(H):
	for column in range(W):
		ret = max(ret, square[row][column] - 1)
		
		
print(ret)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W = map(int,readline().split())
floor = np.frombuffer(read(),dtype='S1').reshape(H,-1)[:,:W] == b'.'

score = np.zeros((H,W),np.int32)

x = np.zeros((H,W),np.int32)
for n in range(1,H):
    x[n] = (1+x[n-1])*floor[n-1]
score += x

x[:] = 0
for n in range(H-1,0,-1):
    x[n-1] = (1+x[n])*floor[n]
score += x

x[:] = 0
for n in range(1,W):
    x[:,n] = (1+x[:,n-1])*floor[:,n-1]
score += x

x[:] = 0
for n in range(W-1,0,-1):
    x[:,n-1] = (1+x[:,n])*floor[:,n]
score += x

score *= floor
answer = score.max() + 1
print(answer)

Solution (Python):
h,w=map(int,input().split())
data=[list(input()) for i in range(h)]
yoko=[[0]*w for i in range(h)]
for i in range(h):
	j=0
	while j <w:
		if data[i][j]=='
			j+=1
		else:
			start=j
			while j<w-1:
				j+=1
				if data[i][j]=='
					for k in range(start,j):
						yoko[i][k]=j-start-1
					j+=1
					break
			else:
				j+=1
				for k in range(start,j):
					yoko[i][k]=j-start-1
				j+=1



for j in range(w):
	i=0
	while i <h:
		if data[i][j]=='
			i+=1
		else:
			start=i
			while i<h-1:
				i+=1
				if data[i][j]=='
					for k in range(start,i):
						yoko[k][j]+=i-start-1
					i+=1
					break
			else:
				i+=1
				for k in range(start,i):
					yoko[k][j]+=i-start-1
				i+=1


for i in range(h):
	
	yoko[i]=max(yoko[i])
print(max(yoko)+1)

Solution (Python):
import numpy as np

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

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(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(R+L+U+D) - 3)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    u = [[0] * w for _ in range(h)]
    d = [[0] * w for _ in range(h)]
    l = [[0] * w for _ in range(h)]
    r = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):

            if i == 0:
                u[i][j] += 1 if s[i][j] != "
                d[-i-1][j] += 1 if s[-i-1][j] != "
            else:
                u[i][j] += 1 + u[i-1][j] if s[i][j] != "
                d[-i-1][j] += 1 + d[-i][j] if s[-i-1][j] != "

            if j == 0:
                l[i][j] += 1 if s[i][j] != "
                r[i][-j-1] += 1 if s[i][-j-1] != "
            else:
                l[i][j] += 1 + l[i][j-1] if s[i][j] != "
                r[i][-j-1] += 1 + r[i][-j] if s[i][-j-1] != "

    mt = 0
    for i in range(h):
        for j in range(w):
            t = u[i][j] + d[i][j] + r[i][j] + l[i][j] - 3
            mt = max(mt, t)
    print(mt)


if __name__ == '__main__':
    slove()

Solution (Python):
def main():
    from sys import stdin
    from builtins import range

    readline = stdin.readline

    H, W = map(int, readline().split())
    S = [readline()[:-1] + '

    S.append('
    ft = [[i] * i for i in range(100)]
    yoko = [[0] * W for _ in range(H)]
    for i in range(H):
        start = -1
        si = S[i]
        yokoi = yoko[i]
        for j in range(W + 1):
            if si[j] == '
                if start != -1:
                    t = j - start
                    if t < 100:
                        yokoi[start:j] = ft[t]
                    else:
                        yokoi[start:j] = [t] * t
                    start = -1
            else:
                if start == -1:
                    start = j

    result = 0
    for i in range(W):
        start = -1
        for j in range(H + 1):
            if S[j][i] == '
                if start != -1:
                    t = yoko_max + j - start - 1
                    if t > result:
                        result = t
                    start = -1
            else:
                yji = yoko[j][i]
                if start == -1:
                    start = j
                    yoko_max = yji
                else:
                    if yji > yoko_max:
                        yoko_max = yji
    print(result)


main()

Solution (Python):
H, W = map(int,input().split())

L = [input() for i in range(H)]
count = [i*W for i in [[0]]*H]
for i in range(H):
    start = 0
    end = 1
    seq = 0
    for j in range(W):
        if L[i][j]=='.':
            seq+=1
            end+=1
            if j==W-1:
                count[i][start:W]=[seq for k in range(W-start)]
            
        else:
            end=j
            count[i][start:end]=[seq for k in range(end-start)]
            if not W-1==j:
                start=j+1
            seq=0
L = list(map(list, (zip(*L))))
count = list(map(list, (zip(*count))))
for i in range(W):
    start = 0
    end = 1
    seq = 0
    for j in range(H):
        if L[i][j]=='.':
            seq+=1
            end+=1
            if j==H-1:
                for n in range(H-start):
                    count[i][start+n]+=seq
        else:
            end=j
            for n in range(end-start):
                count[i][start+n]+=seq
            if not H-1==j:
                start=j+1
            seq=0
num_max=0
for i in range(W):
    for j in range(H):
        if num_max<count[i][j]:
            num_max=count[i][j]
print(num_max-1)

Solution (Python):
def main():
    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):
        cnt = 0
        for j in range(W):
            if S[i][j] == '
                cnt = 0
                continue
            else:
                cnt += 1
                L[i][j] = cnt

    for i in range(H):
        cnt = 0
        for j in range(W-1, -1, -1):
            if S[i][j] == '
                cnt = 0
                continue
            else:
                cnt += 1
                R[i][j] = cnt

    for j in range(W):
        cnt = 0
        for i in range(H):
            if S[i][j] == '
                cnt = 0
                continue
            else:
                cnt += 1
                U[i][j] = cnt

    for j in range(W):
        cnt = 0
        for i in range(H-1,-1,-1):
            if S[i][j] == '
                cnt = 0
                continue
            else:
                cnt += 1
                D[i][j] = cnt

    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '
                continue
            tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            ans = max(ans,tmp)

    print(ans)

main()

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

    left = [[0] * W for _ in range(H)]
    right = [[0] * W for _ in range(H)]
    up = [[0] * W for _ in range(H)]
    down = [[0] * W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 1
                else:
                    left[i][j] = left[i][j-1] + 1

    for i in range(H):
        for j in range(W-1,-1,-1):
            if S[i][j] == '.':
                if j == W-1:
                    right[i][j] = 1
                else:
                    right[i][j] = right[i][j+1] + 1

    for j in range(W):
        for i in range(H):
            if S[i][j] == '.':
                if i == 0:
                    down[i][j] = 1
                else:
                    down[i][j] = down[i-1][j] + 1

    for j in range(W):
        for i in range(H-1,-1,-1):
            if S[i][j] == '.':
                if i == H - 1:
                    up[i][j] = 1
                else:
                    up[i][j] = up[i+1][j] + 1

    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '
                continue
            ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3)

    print(ans)

main()

Solution (Python):
import numpy as np

h,w=map(int,input().split())
s=np.array([[(1 if x=='.' else 0) for x in list(input())] for y in range(h)])

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

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

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

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

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

for h in range(H):
    start = 0
    while start < W:
        while start < W and S[h][start] == '
            start += 1
        end = start
        while end < W and S[h][end] == '.':
            end += 1
        for i in range(start,end):
            A[h][i] += end - start
        start = end

for w in range(W):
    start = 0
    while start < H:
        while start < H and S[start][w] == '
            start += 1
        end = start
        while end < H and S[end][w] == '.':
            end += 1
        for i in range(start,end):
            A[i][w] += end - start
        start = end

ans = max(max(max(A[i]) for i in range(H)) - 1, 0)
print(ans)

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

l = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if j == 0:
      if s[i][j] == '
        l[i][j] = 0
      else:
        l[i][j] = 1
    else:
      if s[i][j] == '
        l[i][j] = 0
      else:
        l[i][j] = l[i][j-1] + 1

r = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w-1, -1, -1):
    if j == w-1:
      if s[i][j] == '
        r[i][j] = 0
      else:
        r[i][j] = 1
    else:
      if s[i][j] == '
        r[i][j] = 0
      else:
        r[i][j] = r[i][j+1] + 1

u = [[0 for i in range(w)] for j in range(h)]
for j in range(w):
  for i in range(h):
    if i == 0:
      if s[i][j] == '
        u[i][j] = 0
      else:
        u[i][j] = 1
    else:
      if s[i][j] == '
        u[i][j] = 0
      else:
        u[i][j] = u[i-1][j] + 1

d = [[0 for i in range(w)] for j in range(h)]
for j in range(w):
  for i in range(h-1, -1, -1):
    if i == h-1:
      if s[i][j] == '
        d[i][j] = 0
      else:
        d[i][j] = 1
    else:
      if s[i][j] == '
        d[i][j] = 0
      else:
        d[i][j] = d[i+1][j] + 1

ans = 0
for i in range(h):
  for j in range(w):
    a = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
    ans = max(ans, a)

print(ans)

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

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

R=[[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  if lamp[i][W-1]=="
  else: R[i][W-1]=1
  for j in range(1,W):
    if lamp[i][W-1-j]=="
    else: R[i][W-1-j]=R[i][W-j]+1

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

D=[[0 for _ in range(W)] for _ in range(H)]
for j in range(W):
  if lamp[H-1][j]=="
  else: D[H-1][j]=1
  for i in range(1,H):
    if lamp[H-1-i][j]=="
    else: D[H-1-i][j]=D[H-i][j]+1
ls=[]
for i in range(H):
  for j in range(W):
    ls.append(L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(max(ls))

Solution (Python):
import numpy as np
H, W = map(int, input().split())
s = np.array([list(input()) for _ in range(H)])=="."

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(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[:,-1-i] = (R[:,-i] + 1) * s[:,-i-1]
print(np.max(L+R+U+D - 3))

Solution (Python):
H,W = map(int,input().split())
height, width_max, ans = [0] * (W+1), [0] * (W+1), 0
for i in range(H):
    s = input() + '
    length = 0
    for j in range(W+1):
        if s[j] == '.':
            length += 1
            height[j] += 1
        else:
            if length > 0:
                for k in range(j-length, j):
                    if width_max[k] < length:
                        width_max[k] = length
                length = 0
            if height[j] > 0:
                temp = width_max[j] + height[j] - 1
                if ans < temp:
                    ans = temp
                width_max[j], height[j] = 0, 0
for j in range(W):
    if height[j] > 0:
        temp = width_max[j] + height[j] - 1
        if ans < temp:
            ans = temp
print(ans)

Solution (Python):
import numpy as np
H, W = map(int, input().split())
S = np.array([list(input()) for i in range(H)])=="."

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(H):
  U[i]= (U[i-1]+1)*S[i]
  D[-i-1]= (D[-i]+1)*S[-1-i]
for i in range(W):
  L[:,i]= (L[:,i-1]+1)*S[:,i]
  R[:,-1-i]= (R[:,-i]+1)*S[:,-i-1]
print (np.max(L+R+U+D-3))

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


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

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

    
    for i in reversed(range(H)):
        for j in reversed(range(W)):
            if S[i][j] != "
                if j == W-1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j+1] + 1
            
                if 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):
            if S[i][j] == "
                continue

            tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            ans = max(ans, tmp)

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
from functools import reduce
import sys
import numpy as np


mod = 10 ** 9 + 7
buffer = sys.stdin.buffer
h, w = map(int, buffer.readline().split())
s = np.frombuffer(buffer.read(h*(w+1)), dtype='B') == ord('.')
s = s.reshape((h, w+1))[:, :-1]
l = np.empty((h, w), dtype='i4')
r = np.empty((h, w), dtype='i4')
u = np.empty((h, w), dtype='i4')
d = np.empty((h, w), dtype='i4')
l[:, 0] = s[:, 0]
for i in range(1, w):
    l[:, i] = (l[:, i-1] + 1) * s[:, i]
r[:, -1] = s[:, -1]
for i in range(1, w):
    r[:, -1-i] = (r[:, -i] + 1) * s[:, -1-i]
u[0] = s[0]
for i in range(1, h):
    u[i] = (u[i-1] + 1) * s[i]
d[-1] = s[-1]
for i in range(1, h):
    d[-1-i] = (d[-i] + 1) * s[-1-i]
score = l + r + u + d - 3
print(int(score.max()))

Solution (Python):
import sys
input = sys.stdin.readline
 
 
def main():
    H, W = map(int, input().split())

    S = []
    for _ in range(H):
        S.append(list(input()[:-1]))
    
    U = [[0]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j]=='
                continue
            if i==0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1

    D = [[0]*W for _ in range(H)]
    for i in reversed(range(H)):
        for j in range(W):
            if S[i][j]=='
                continue
            if i==H-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1
    
    L = [[0]*W for _ in range(H)]
    for j in range(W):
        for i in range(H):
            if S[i][j]=='
                continue
            if j==0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1

    R = [[0]*W for _ in range(H)]
    for j in reversed(range(W)):
        for i in range(H):
            if S[i][j]=='
                continue
            if j==W-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1

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

 
if __name__ == '__main__':
    main()

Solution (Python):
h,w = map(int, input().split( ))

s = ["

for _ in range(h):
    inpt = input()
    s.append("
s.append("

dp1 = [[0 for j in range(w+2)] for i in range(h+2)]
dp2 = [[0 for j in range(w+2)] for i in range(h+2)]

dp3 = [[0 for j in range(w+2)] for i in range(h+2)]
dp4 = [[0 for j in range(w+2)] for i in range(h+2)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] != "
            dp1[i][j] = dp1[i-1][j] + 1
            dp3[i][j] = dp3[i][j-1] + 1
        if s[h+1-i][w+1-j] != "
            dp2[h+1-i][w+1-j] = dp2[h+1-i+1][w+1-j]+1
            dp4[h+1-i][w+1-j] = dp4[h+1-i][w+1-j+1]+1
            
dp5 = [[dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3 for j in range(w+2)] for i in range(h+2)]
mx = 0

for i in range(h+2):
    mx = max(mx,max(dp5[i]))
print(mx)

Solution (Python):
import sys
input=sys.stdin.readline

def main():
    H,W = map(int, input().split())
    
    S = []
    for _ in range(H):
        S.append(input().strip()+"
    S.append("

    
    grid_x = [[0]*(W+1) for _ in range(H)]
    for y in range(H):
        l = r = 0
        for x in range(W+1):
            if S[y][x] == "
                r = x
                for i in range(l,r):
                    grid_x[y][i] = r-l
                grid_x[y][x] = 0
                l = x+1

    
    grid_y = [[0]*W for _ in range(H+1)]
    for x in range(W):
        u = d = 0
        for y in range(H+1):
            if S[y][x] == "
                d = y
                for i in range(u,d):
                    grid_y[i][x] = d-u
                grid_y[y][x] = 0
                u = y+1

    ans = 0
    for y in range(H):
        for x in range(W):
            ans = max(ans, grid_x[y][x]+grid_y[y][x]-1)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline

def main():
    H,W = map(int, input().split())
    
    S = []
    for _ in range(H):
        S.append(input().strip())
 
    u = [[0]*W for _ in range(H)]
    d = [[0]*W for _ in range(H)]
    l = [[0]*W for _ in range(H)]
    r = [[0]*W for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if S[y][x] == "
                u[y][x] = l[y][x] = 0
            else:
                u[y][x] = 1 if y == 0 else u[y-1][x] + 1
                l[y][x] = 1 if x == 0 else l[y][x-1] + 1
    for y in range(H-1,-1,-1):
        for x in range(W-1,-1,-1):
            if S[y][x] == "
                d[y][x] = r[y][x] = 0
            else:
                d[y][x] = 1 if y == H-1 else d[y+1][x] + 1
                r[y][x] = 1 if x == W-1 else r[y][x+1] + 1
 
    ans = 0
    for y in range(H):
        for x in range(W):
            ans = max(ans, u[y][x] + d[y][x] + l[y][x] + r[y][x] - 3)
            
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):

def main():
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1 in range(H):
        for y1 in range(W):
            if S[x1][y1] == ".":  
                U[x1][y1] = U[x1 - 1][y1] + 1
                L[x1][y1] = L[x1][y1 - 1] + 1
            x2, y2 = -x1 - 1, -y1 - 1
            if S[x2][y2] == ".":  
                D[x2][y2] = D[x2 + 1][y2] + 1
                R[x2][y2] = R[x2][y2 + 1] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
import re


def solve(H: int, W: int, S: "List[str]"):

    
    L = [[0] * W for i in range(H)]
    R = [[0] * W for i in range(H)]
    U = [[0] * W for i in range(H)]
    D = [[0] * W for i 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
            elif(j >= 1):
                L[i][j] = L[i][j-1] + 1

            
            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 range(H-1,-1,-1):
        for j in range(W-1,-1,-1):
            
            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

            
            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)

    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):
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    L = [[0] * w for _ in range(h)]

    for i in range(h):
        for j in range(w):
            if i == 0:
                U[i][j] = 1 if s[i][j] != "
                D[-i-1][j] = 1 if s[-i-1][j] != "
            else:
                U[i][j] = 1 + U[i-1][j] if s[i][j] != "
                D[-i-1][j] = 1 + D[-i][j] if s[-i-1][j] != "
            if j == 0:
                L[i][j] = 1 if s[i][j] != "
                R[i][-j-1] = 1 if s[i][-j-1] != "
            else:
                L[i][j] = 1 + L[i][j-1] if s[i][j] != "
                R[i][-j-1] = 1 + R[i][-j] if s[i][-j-1] != "
    m_c = 0
    for i in range(h):
        for j in range(w):
            m_c = max(m_c, U[i][j] + D[i][j] + R[i][j] + L[i][j] - 3)
    print(m_c)


if __name__ == '__main__':
    slove()

Solution (Python):
import numpy as np
h,w = map(int,input().split())
S = np.array([list(input()) 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[-1-i]
for i in range(w):
  L[:,i]= (L[:,i-1]+1)*S[:,i]
  R[:,-1-i]= (R[:,-i]+1)*S[:,-i-1]
print(np.max(U+D+R+L)-3)

Solution (Python):
h,w = map(int,input().split())
raw = []
for _ in range(h):
  raw.append(input())
ans = [[0 for _ in range(w)] for _ in range(h)]


for x in range(h):
  tmp = 0
  for y in range(w):
    if raw[x][y] == '.':
      tmp += 1
    else:
      for j in range(tmp):
        ans[x][y-j-1] += tmp
      tmp = 0
  for j in range(tmp):
    ans[x][y-j] += tmp
for y in range(w):
  tmp = 0
  for x in range(h):
    if raw[x][y] == '.':
      tmp += 1
    else:
      for i in range(tmp):
        ans[x-i-1][y] += tmp
      tmp = 0
  for i in range(tmp):
    ans[x-i-1][y] += tmp
can = []
for x in range(h):
  can.append(max(ans[x]))
print(max(can)-1)