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

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines



























def main():
	h,w=map(int,input().split())
	S=[input().rstrip().decode('utf-8') 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 j==0:
				if S[i][j]==".":
					L[i][j]=1
			else:
				if S[i][j] == ".":
					L[i][j]=L[i][j-1]+1
	
	for i in reversed(range(h)):
		for j in reversed(range(w)):
			if j==w-1:
				if S[i][j]==".":
					R[i][j]=1
			else:
				if S[i][j] == ".":
					R[i][j]=R[i][j+1]+1
	
	for j in range(w):
		for i in range(h):
			if i==0:
				if S[i][j]==".":
					U[i][j]=1
			else:
				if S[i][j] == ".":
					U[i][j]=U[i-1][j]+1
	
	for j in reversed(range(w)):
		for i in reversed(range(h)):
			if i==h-1:
				if S[i][j]==".":
					D[i][j]=1
			else:
				if 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)
	
	
	
	
	
	
	
	
	
	
	



if __name__ == '__main__':
	main()

Solution (Python):
H, W=map(int, input().split())
frame=["".join(["
S=frame+["
score=[[0 for _ in range(W+2)] for _ in range(H+2)]
for i in range(H+2):
  sharp_j=0
  for j in range(W+2):
    if S[i][j]=="
      for k in range(sharp_j+1, j):
        score[i][k]+=j-sharp_j-1
      sharp_j=j
for j in range(W+2):
  sharp_i=0
  for i in range(H+2):
    if S[i][j]=="
      for k in range(sharp_i+1, i):
        score[k][j]+=i-sharp_i-2
      sharp_i=i
ans=0
for i in range(H+2):
  for j in range(W+2):
    ans=max(ans, score[i][j])
print(ans)

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

a = [[0]*w for _ in range(h)]
for i in range(h):
    k = 0
    for j in range(w):
        if s[i][j] == ".":
            k += 1
        else:
            k = 0
        a[i][j] += k
for i in range(h):
    k = 0
    for j in reversed(range(w)):
        if s[i][j] == ".":
            k += 1
        else:
            k = 0
        a[i][j] += k
for j in range(w):
    k = 0
    for i in range(h):
        if s[i][j] == ".":
            k += 1
        else:
            k = 0
        a[i][j] += k
for j in range(w):
    k = 0
    for i in reversed(range(h)):
        if s[i][j] == ".":
            k += 1
        else:
            k = 0
        a[i][j] += k
b = max([max(i) for i in a])
print(0 if b == 0 else b-3)

Solution (Python):
def search_right(h, w):
    if h < 0 or h >= H or w < 0 or w >= W or S[h][w] == "
        return
    if S[h][w] == "." and answer_right[h][w-1] > 0:
        answer_right[h][w] = answer_right[h][w-1]
        return

    for i in range(w, W):
        if S[h][i] == ".":
            answer_right[h][w] += 1
        else:
            break


def search_down(h, w):
    if h < 0 or h >= H or w < 0 or w >= W or S[h][w] == "
        return
    if S[h][w] == "." and answer_down[h-1][w] > 0:
        answer_down[h][w] = answer_down[h-1][w]
        return

    for i in range(h, H):
        if S[i][w] == ".":
            answer_down[h][w] += 1
        else:
            break

H, W = map(int, input().split())
S = [0] * H
answer_right = [[0] * W for _ in range(H)]
answer_down = [[0] * W for _ in range(H)]
answer = 0
for i in range(H):
    S[i] = input()
for h in range(H):
    for w in range(W):
        search_right(h, w)
        search_down(h, w)
        answer = max(answer, answer_down[h][w]+answer_right[h][w] - 1)

print(answer)

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

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

cntr=0
cntd=[0]*W
for i in range(H):
    temp=input()
    for j in range(W):
        if temp[j]!="
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
            cntr+=1
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j]=U[i-1][j]+1
            cntd[j]+=1
        else:
            for k in range(cntr):
                R[i][j-1-k]=k+1
            cntr=0
            for k in range(cntd[j]):
                D[i-1-k][j]=k+1
            cntd[j]=0
    if cntr!=0:
        for k in range(cntr):
            R[i][W - 1 - k] = k + 1
        cntr=0
for i in range(W):
    if cntd[i]!=0:
        for k in range(cntd[i]):
            D[H-1-k][i]=k+1

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

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

s=[[0]*W for i in range(H)]

for i in range(H):
    cnt = 0
    temp=input()

    for j in range(W):
        if temp[j]!="
            cnt+=1
        else:
            if j==0:
                continue
            else:
                for k in range(cnt):
                    s[i][j-(1+k)]=cnt
                cnt=0
    if cnt!=0:
        for k in range(cnt):
            s[i][W-1 - k] = cnt
        cnt = 0

ans=[]
mx=0
for i in range(W):
    cnt=0
    for j in range(H):
        if s[j][i]!=0:
            cnt+=1
            mx=max(mx,s[j][i])
        else:
            if j==0:
                continue
            else:
                ans.append(mx+cnt-1)
                cnt=0
                mx=0
    if cnt!=0:
        ans.append(mx+cnt-1)
        mx=0
print(max(ans))

Solution (Python):
H, W = map(int, input().split())
S = [input() for _ in range(H)]
l = [[0] * (W+2) for _ in range(H+2)]
u = [[0] * (W+2) for _ in range(H+2)]
r = [[0] * (W+2) for _ in range(H+2)]
d = [[0] * (W+2) for _ in range(H+2)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i-1][j-1] != '
            l[i][j] += l[i][j-1] + 1
            u[i][j] += u[i-1][j] + 1
        if S[-i][-j] != '
            r[-i-1][-j-1] += r[-i-1][-j] + 1
            d[-i-1][-j-1] += d[-i][-j-1] + 1

ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        ans = max(ans, l[i][j]+u[i][j]+r[i][j]+d[i][j]-3)

print(ans)

Solution (Python):
MOD = 10 ** 9 + 7










































def main():
    H, W = map(int, input().split())
    S = [None] * H
    w_score = [[0 for i in range(W)] for i in range(H)]
    h_score = [[0 for i in range(W)] for i in range(H)]
    stack = []

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

    for x in range(H):
        v = 0
        stack = []
        for y in range(W+1):
            if x >= 0 and x < H and y >= 0 and y < W and S[x][y] == '.':
                v += 1
                stack.append((x, y))
            else:
                if len(stack) == 0:
                    
                    stack = []
                elif len(stack) == 1:
                    first = stack.pop(0)
                    w_score[x][first[1]] = v
                    stack = []
                    v = 0
                else:
                    first = stack.pop(0)
                    last = stack.pop()
                    for y in range(first[1], last[1]+1):
                        w_score[x][y] = v
                    stack = []
                    v = 0

    for y in range(W):
        v = 0
        stack = []
        for x in range(H+1):
            if x >= 0 and x < H and y >= 0 and y < W and S[x][y] == '.':
                v += 1
                stack.append((x, y))
            else:
                if len(stack) == 0:
                    
                    stack = []
                elif len(stack) == 1:
                    first = stack.pop(0)
                    h_score[first[0]][y] = v
                    stack = []
                    v = 0
                else:
                    first = stack.pop(0)
                    last = stack.pop()
                    for x in range(first[0], last[0]+1):
                        h_score[x][y] = v
                    stack = []
                    v = 0

    ans = 0
    for x in range(H):
        for y in range(W):
            ans = max(ans, w_score[x][y] + h_score[x][y])

    print(ans-1)
    
    
    


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF = 10**18

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

def main():
    H, W = map(int, input().split())
    S = [list(input()) for i in range(H)]
    ans = 0
    memo_y = [[-INF]*W for i in range(H)]
    memo_x = [[-INF]*W for i in range(H)]
    for y in range(H):
        for x in range(W):
            c = 0
            if S[y][x] == '.':
                c += 1
                c_x = 0
                c_y = 0
                tmp_x = [x]
                tmp_y = [y]
                if memo_x[y][x] == -INF:
                    for i in range(1, x+1):
                        if S[y][x-i] == '.':
                            c_x += 1
                            tmp_x.append(i)
                        else:
                            break
                    for i in range(x+1, W):
                        if S[y][i] == '.':
                            c_x += 1
                            tmp_x.append(i)
                        else:
                            break
                    for i in tmp_x:
                        memo_x[y][i] = c_x
                else:
                    c_x += memo_x[y][x]
                if memo_y[y][x] == -INF:
                    for i in range(1, y+1):
                        if S[y-i][x] == '.':
                            c_y += 1
                            tmp_y.append(i)
                        else:
                            break
                    for i in range(y+1, H):
                        if S[i][x] == '.':
                            c_y += 1
                            tmp_y.append(i)
                        else:
                            break
                    for i in tmp_y:
                        memo_y[i][x] = c_y
                else:
                    c_y += memo_y[y][x]
                c += c_x + c_y
            ans = max(ans, c)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)


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


def main():
    H, W = map(int, input().split())
    S = [list(input()) for i in range(H)]
    ans = float(0)
    memo_y = [[-float('inf')]*W for i in range(H)]
    memo_x = [[-float('inf')]*W for i in range(H)]
    for y in range(H):
        for x in range(W):
            c = float(0)
            if S[y][x] == '.':
                c += float(1)
                c_x = float(0)
                c_y = float(0)
                tmp_x = [x]
                tmp_y = [y]
                if memo_x[y][x] == -float('inf'):
                    for i in range(1, x+1):
                        if S[y][x-i] == '.':
                            c_x += float(1)
                            tmp_x.append(i)
                        else:
                            break
                    for i in range(x+1, W):
                        if S[y][i] == '.':
                            c_x += float(1)
                            tmp_x.append(i)
                        else:
                            break
                    for i in tmp_x:
                        memo_x[y][i] = c_x
                else:
                    c_x += memo_x[y][x]
                if memo_y[y][x] == -float('inf'):
                    for i in range(1, y+1):
                        if S[y-i][x] == '.':
                            c_y += float(1)
                            tmp_y.append(i)
                        else:
                            break
                    for i in range(y+1, H):
                        if S[i][x] == '.':
                            c_y += float(1)
                            tmp_y.append(i)
                        else:
                            break
                    for i in tmp_y:
                        memo_y[i][x] = c_y
                else:
                    c_y += memo_y[y][x]
                c += c_x + c_y
            ans = max(ans, c)
    print(int(ans))


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)


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


def main():
    H, W = map(int, input().split())
    S = [list(input()) for i in range(H)]
    ans = 0
    memo_y = [[-1]*W for i in range(H)]
    memo_x = [[-1]*W for i in range(H)]
    for y in range(H):
        for x in range(W):
            c = 0
            if S[y][x] == '.':
                c += 1
                c_x = 0
                c_y = 0
                tmp_x = [x]
                tmp_y = [y]
                if memo_x[y][x] == -1:
                    for i in range(1, x+1):
                        if S[y][x-i] == '.':
                            c_x += 1
                            tmp_x.append(i)
                        else:
                            break
                    for i in range(x+1, W):
                        if S[y][i] == '.':
                            c_x += 1
                            tmp_x.append(i)
                        else:
                            break
                    for i in tmp_x:
                        memo_x[y][i] = c_x
                else:
                    c_x += memo_x[y][x]
                if memo_y[y][x] == -1:
                    for i in range(1, y+1):
                        if S[y-i][x] == '.':
                            c_y += 1
                            tmp_y.append(i)
                        else:
                            break
                    for i in range(y+1, H):
                        if S[i][x] == '.':
                            c_y += 1
                            tmp_y.append(i)
                        else:
                            break
                    for i in tmp_y:
                        memo_y[i][x] = c_y
                else:
                    c_y += memo_y[y][x]
                c += c_x + c_y
            ans = max(ans, c)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)


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


def main():
    H, W = map(int, input().split())
    S = [list(input()) for i in range(H)]
    ans = 0
    memo_y = [[float(-1)]*W for i in range(H)]
    memo_x = [[float(-1)]*W for i in range(H)]
    for y in range(H):
        for x in range(W):
            c = 0
            if S[y][x] == '.':
                c += 1
                c_x = 0
                c_y = 0
                tmp_x = [x]
                tmp_y = [y]
                if memo_x[y][x] == float(-1):
                    for i in range(1, x+1):
                        if S[y][x-i] == '.':
                            c_x += 1
                            tmp_x.append(i)
                        else:
                            break
                    for i in range(x+1, W):
                        if S[y][i] == '.':
                            c_x += 1
                            tmp_x.append(i)
                        else:
                            break
                    for i in tmp_x:
                        memo_x[y][i] = c_x
                else:
                    c_x += memo_x[y][x]
                if memo_y[y][x] == float(-1):
                    for i in range(1, y+1):
                        if S[y-i][x] == '.':
                            c_y += 1
                            tmp_y.append(i)
                        else:
                            break
                    for i in range(y+1, H):
                        if S[i][x] == '.':
                            c_y += 1
                            tmp_y.append(i)
                        else:
                            break
                    for i in tmp_y:
                        memo_y[i][x] = c_y
                else:
                    c_y += memo_y[y][x]
                c += c_x + c_y
            ans = max(ans, c)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**9)


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


def main():
    H, W = map(int, input().split())
    S = [list(input()) for i in range(H)]
    ans = 0
    memo_y = [[-1]*W for i in range(H)]
    memo_x = [[-1]*W for i in range(H)]
    for y in range(H):
        for x in range(W):
            c = 0
            if S[y][x] == '.':
                c += 1
                c_x = 0
                c_y = 0
                tmp_x = [x]
                tmp_y = [y]
                if memo_x[y][x] == -1:
                    for i in range(1, x+1):
                        if S[y][x-i] == '.':
                            c_x += 1
                            tmp_x.append(i)
                        else:
                            break
                    for i in range(x+1, W):
                        if S[y][i] == '.':
                            c_x += 1
                            tmp_x.append(i)
                        else:
                            break
                    for i in tmp_x:
                        memo_x[y][i] = c_x
                else:
                    c_x += memo_x[y][x]
                if memo_y[y][x] == -1:
                    for i in range(1, y+1):
                        if S[y-i][x] == '.':
                            c_y += 1
                            tmp_y.append(i)
                        else:
                            break
                    for i in range(y+1, H):
                        if S[i][x] == '.':
                            c_y += 1
                            tmp_y.append(i)
                        else:
                            break
                    for i in tmp_y:
                        memo_y[i][x] = c_y
                else:
                    c_y += memo_y[y][x]
                c += c_x + c_y
            ans = max(ans, c)
    print(ans)


if __name__ == '__main__':
    main()

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


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):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]
 
for i in range(W):
    left[:, i] = (left[:, i-1] + 1) * S[:, i]
    right[:, -i-1] = (right[:, -i] + 1) * S[:, -i-1]

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

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    h, w = list(map(int, readline().split()))
    s = [list(str(readline().rstrip().decode('utf-8'))) for _ in range(h)]
    ul = [[0] * w for _ in range(h)]
    dl = [[0] * w for _ in range(h)]
    ll = [[0] * w for _ in range(h)]
    rl = [[0] * w for _ in range(h)]

    for i in range(h):
        for j in range(w):
            if i == 0:
                ul[i][j] = 1 if s[i][j] != "
                dl[-i-1][j] = 1 if s[-i-1][j] != "
            else:
                ul[i][j] = 1 + ul[i-1][j] if s[i][j] != "
                dl[-i-1][j] = 1 + dl[-i][j] if s[-i-1][j] != "
            if j == 0:
                ll[i][j] = 1 if s[i][j] != "
                rl[i][-j-1] = 1 if s[i][-j-1] != "
            else:
                ll[i][j] = 1 + ll[i][j-1] if s[i][j] != "
                rl[i][-j-1] = 1 + rl[i][-j] if s[i][-j-1] != "
    mt = 0
    for i in range(h):
        for j in range(w):
            mt = max(mt, ul[i][j] + dl[i][j] + ll[i][j] + rl[i][j] - 3)
    print(mt)


if __name__ == '__main__':
    solve()

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

sll = []
for _ in range(h):
    sl = list(input())
    sll.append(sl)

yoko = [[] for i in range(h)]
for idx, sl in enumerate(sll):
    point = 0
    for s in sl:
        if s == "
            if point > 0:
                for _ in range(point):
                    yoko[idx].append(point)
            yoko[idx].append(0)
            point = 0
        else:
            point += 1
    if point > 0:
        for _ in range(point):
            yoko[idx].append(point)


tate = [[0 for i in range(w)] for i in range(h)]
for i in range(w):
    point = 0
    for idx,sl in enumerate(sll):
        if sl[i] == "
            if point > 0:
                for j in range(1, point+1):
                    tate[idx-j][i] = point
            tate[idx][i] = 0
            point = 0
        else:
            point += 1
    if point > 0:
        for j in range(1, point+1):
            tate[idx-j+1][i] = point


ans = 0
for yokol, tatel in zip(yoko,tate):
    for y, t in zip(yokol, tatel):
        if y+t > ans:
            ans = y+t

print(ans-1)

Solution (Python):
from numpy import*
h,w=map(int,input().split())
a=array([[0 if i!="." else 1 for i in input()]for j in range(h)])
e=zeros((4,h,w))
for i in range(h):
    e[0,i]=(e[0,i-1]+1)*a[i]
    e[1,-i-1]=(e[1,-i]+1)*a[-i-1]  
for i in range(w):
    e[2,:,i]=(e[2,:,i-1]+1)*a[:,i]
    e[3,:,-i-1]=(e[3,:,-i]+1)*a[:,-i-1] 
print(int(amax(sum(e, axis=0))-3))

Solution (Python):
import numpy as np
h,w=map(int,input().split())
a=np.array([[0 if i!="." else 1 for i in input()]for j in range(h)])
e=np.zeros((4,h,w))
for i in range(h):
    e[0,i]=(e[0,i-1]+1)*a[i]
    e[1,-i-1]=(e[1,-i]+1)*a[-i-1]  
for i in range(w):
    e[2,:,i]=(e[2,:,i-1]+1)*a[:,i]
    e[3,:,-i-1]=(e[3,:,-i]+1)*a[:,-i-1] 
print(int(np.amax(np.sum(e, axis=0))-3))

Solution (Python):
def main():
    h,w = map(int,input().split())
    s=[]
    for _ in range(h):
        s.append(list(input()))
    ans=[[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)]
    U=[[0 for _ in range(w)] for _ in range(h)]
    D=[[0 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if i==0:
                if s[i][j]==".":
                    U[i][j]=1
                else:
                    U[i][j]=0
            else:
                if s[i][j]==".":
                    U[i][j]=U[i-1][j]+1
                else:
                    U[i][j]=0
            if i==0:
                if s[h-1-i][j]==".":
                    D[h-1-i][j]=1
                else:
                    D[h-1-i][j]=0
            else:
                if s[h-1-i][j]==".":
                    D[h-1-i][j]=D[h-i][j]+1
                else:
                    D[h-1-i][j]=0
    
    
    for i in range(h):
        for j in range(w):
            if j==0:
                if s[i][j]==".":
                    L[i][j]=1
                else:
                    L[i][j]=0
            else:
                if s[i][j]==".":
                    L[i][j]=L[i][j-1]+1
                else:
                    L[i][j]=0
            if j==0:
                if s[i][w-1-j]==".":
                    R[i][w-1-j]=1
                else:
                    R[i][w-1-j]=0
            else:
                if s[i][w-1-j]==".":
                    R[i][w-1-j]=R[i][w-j]+1
                else:
                    R[i][w-1-j]=0
                    
    for i in range(h):
        for j in range(w):
            ans[i][j]=L[i][j]+R[i][j]+U[i][j]+D[i][j]
    a=1
    for i in range(len(ans)):
        b=max(ans[i])
        a=max(a,b)
    print(a-3)
    

if __name__ == "__main__":
    main()

Solution (Python):
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
field=[0]+["
field[0],field[-1]="
l,r,u,d=[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i 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 field[i][j]=="
    l[i][j]=l[i][j-1]+1
    u[i][j]=u[i-1][j]+1
for i in range(1,h+1)[::-1]:
  for j in range(1,w+1)[::-1]:
    if field[i][j]=="
    r[i][j]=r[i][j+1]+1
    d[i][j]=d[i+1][j]+1
ans=0
for i in range(h+2):
  for j in range(w+2):
    c=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
    if c>ans:ans=c
print(ans)

Solution (Python):
h,w = map(int,input().split())
s = ["
res = 0
l = [[0 for _ in range(w+2)] for _ in range(h+2)]
r = [[0 for _ in range(w+2)] for _ in range(h+2)]
d = [[0 for _ in range(w+2)] for _ in range(h+2)]
u = [[0 for _ in range(w+2)] for _ in range(h+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
       if s[i][j]==".":
           l[i][j]=l[i][j-1]+1 
           d[i][j]=d[i-1][j]+1 
for i in range(h,0,-1):
    for j in range(w,0,-1):
       if s[i][j]==".":
           r[i][j]=r[i][j+1]+1 
           u[i][j]=u[i+1][j]+1 


for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == ".":
            res = max(res,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
            if res == h+w-1:break

print(res)

Solution (Python):
h,w=map(int,input().split())
s=['
u=[[0]*(w+2) for _ in range(h+2)]
d=[[0]*(w+2) for _ in range(h+2)]
l=[[0]*(w+2) for _ in range(h+2)]
r=[[0]*(w+2) for _ in range(h+2)]
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]=='.':
      l[i][j]=l[i][j-1]+1
    if s[i][w+1-j]=='.':  
      r[i][w+1-j]=r[i][w+2-j]+1
for i in range(1,w+1):
  for j in range(1,h+1):
    if s[j][i]=='.':
      u[j][i]=u[j-1][i]+1
    if s[h+1-j][i]=='.':  
      d[h+1-j][i]=d[h+2-j][i]+1
m=0
for i in range(1,h+1):
  for j in range(1,w+1):
    m=max(m,u[i][j]+d[i][j]+l[i][j]+r[i][j]-3)
print(m)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    grid=[0]*h
    for i in range(h):
        grid[i]=input()
    Sl=[[0]*w for _ in range(h)]
    Sr=[[0]*w for _ in range(h)]
    Su=[[0]*w for _ in range(h)]
    Sd=[[0]*w for _ in range(h)]

    
    for i in range(h):
        cnt=0
        for j in range(w):
            if(grid[i][j]=='.'):
                cnt+=1
                Sl[i][j]=cnt
            else:
                cnt=0
                Sl[i][j]=cnt

    
    for i in range(h):
        cnt=0
        for j in range(w-1,-1,-1):
            if(grid[i][j]=='.'):
                cnt+=1
                Sr[i][j]=cnt
            else:
                cnt=0
                Sr[i][j]=cnt

    
    for j in range(w):
        cnt=0
        for i in range(h):
            if(grid[i][j]=='.'):
                cnt+=1
                Su[i][j]=cnt
            else:
                cnt=0
                Su[i][j]=cnt

    
    for j in range(w):
        cnt=0
        for i in range(h-1,-1,-1):
            if(grid[i][j]=='.'):
                cnt+=1
                Sd[i][j]=cnt
            else:
                cnt=0
                Sd[i][j]=cnt

    ans=0
    for i in range(h):
        for j in range(w):
            if(grid[i][j]=='
            ans=max(Sl[i][j]+Sr[i][j]+Su[i][j]+Sd[i][j]-3,ans)
    print(ans)
resolve()

Solution (Python):
def p_d():
    hb, wb = map(int, input().split())
    t = [input() for _ in range(hb)]
    lb = [[0] * (wb + 2) for _ in range(hb + 2)]
    rb = [[0] * (wb + 2) for _ in range(hb + 2)]
    ub = [[0] * (wb + 2) for _ in range(hb + 2)]
    db = [[0] * (wb + 2) for _ in range(hb + 2)]
    for h in range(1, hb + 1):
        for w in range(1, wb + 1):
            if t[h - 1][w - 1] != "
                lb[h][w] = lb[h][w - 1] + 1
                ub[h][w] = ub[h - 1][w] + 1
            if t[hb - h][wb - w] != "
                rb[hb - h + 1][wb - w + 1] = rb[hb - h + 1][wb - w + 2] + 1
                db[hb - h + 1][wb - w + 1] = db[hb - h + 2][wb - w + 1] + 1
    ans = 0
    for h in range(1, hb + 1):
        for w in range(1, wb + 1):
            tmp = lb[h][w] + rb[h][w] + ub[h][w] + db[h][w]
            ans = max(ans, tmp - 3)
    print(ans)
    
p_d()

Solution (Python):
H, W = map(int, input().split())
S = [[j for j in input()] for i in range(H)]
X = [[0 for j in range(W)] for i in range(H)]
Y = [[0 for j in range(W)] for i in range(H)]

for i in range(H):
    start = -1
    cnt = 0
    for j in range(W + 1):
        if j == W or S[i][j] == '
            for k in range(start + 1, j):
                X[i][k] = cnt
            cnt = 0
            start = j
        else:
            cnt += 1

for j in range(W):
    start = -1
    cnt = 0
    for i in range(H + 1):
        if i == H or S[i][j] == '
            for k in range(start + 1, i):
                Y[k][j] = cnt
            cnt = 0
            start = i
        else:
            cnt += 1

m = 0
for i in range(H):
    for j in range(W):
        m = max(m, X[i][j] + Y[i][j])

print(m - 1)