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):
H, W = map(int, input().split())
S = [input() for i in range(H)]

h = []
v = []
for i in range(H):
    a = 0
    h.append([])
    v.append([])
    for j in range(W):
        if S[i][j] == '
            a = 0
        else:
            a += 1
        h[i].append(a)
    for j in range(W - 1, -1, -1):
        if S[i][j] == '
            a = 0
        else:
            if a == 0:
                a = h[i][j]
            h[i][j] = a

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

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, h[i][j] + v[i][j])
print(ans - 1)

Solution (Python):
import numpy as np


H, W = map(int, input().split())
grid = 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):
    down[i] = (down[i - 1] + 1) * grid[i]
    up[-i - 1] = (up[-i] + 1) * grid[-i - 1]

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

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

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

def pri(tbl, tbl2, tbl3, tbl4, n, m):
	for i in range(n):
		for j in range(m):
			print("{:2}".format(tbl[i][j]+tbl2[i][j]+tbl3[i][j]+tbl4[i][j]), end='')
		print('')
	print('')

def main():
	n, m = map(int, input().strip().split())
	v = []
	for i in range(n):
		v.append(input().strip())
	tbl = [[0] * m for _ in range(n)]
	tbl2 = [[0] * m for _ in range(n)]
	tbl3 = [[0] * m for _ in range(n)]
	tbl4 = [[0] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if v[i][j] == '
				tbl[i][j] = -1
			elif j == 0:
				continue
			else:
				tbl[i][j] = tbl[i][j-1] + 1
	
	for i in range(n):
		for j in range(m-1, -1, -1):
			if v[i][j] == '
				tbl2[i][j] = -1
			elif j == m-1:
				continue
			else:
				tbl2[i][j] = tbl2[i][j+1] + 1
	

	
	for j in range(m):
		for i in range(n):
			if v[i][j] == '
				tbl3[i][j] = -1
			elif i == 0:
				continue
			else:
				tbl3[i][j] = tbl3[i-1][j] + 1
	for j in range(m):
		for i in range(n-1, -1, -1):
			if v[i][j] == '
				tbl4[i][j] = -1
			elif i == n-1:
				continue
			else:
				tbl4[i][j] = tbl4[i+1][j] + 1
	
	
	
	ans = 0
	for i in range(n):
		for j in range(m):
			ans = max(ans, tbl[i][j]+tbl2[i][j]+tbl3[i][j]+tbl4[i][j])
	print(ans+1)

if __name__ == '__main__':
	main()

Solution (Python):
def larger(x, y):
	if x > y:
		return x
	return y

H, W = map(int, input().split())
field = []
for i in range(0, H):
	field.append(input())
upper = []
down = []
left = []
right = []
for i in range(0, H):
	lst1 = []
	lst2 = []
	lst3 = []
	lst4 = []
	for j in range(0, W):
		lst1.append(0)
		lst2.append(0)
		lst3.append(0)
		lst4.append(0)
	upper.append(lst1)
	down.append(lst2)
	left.append(lst3)
	right.append(lst4)
for i in range(0, H):
	cnt1 = 0
	cnt2 = 0
	for j in range(0, W):
		if field[i][j] == '
			cnt1 = 0
		else:
			left[i][j] = cnt1
			cnt1 += 1
		if field[i][-1-j] == '
			cnt2 = 0;
		else:
			right[i][-1-j] = cnt2
			cnt2 += 1
for i in range(0, W):
	cnt1 = 0
	cnt2 = 0
	for j in range(0, H):
		if field[j][i] == '
			cnt1 = 0
		else:
			upper[j][i] = cnt1
			cnt1 += 1
		if field[-1-j][i] == '
			cnt2 = 0
		else:
			down[-1-j][i] = cnt2
			cnt2 += 1
max = 0
for i in range(0, H):
	for j in range(0, W):
		if field[i][j] == '.':
			lamp = upper[i][j] + down[i][j] + left[i][j] + right[i][j] + 1
			max = larger(max, lamp)
print(max)

Solution (Python):
H,W=map(int,input().split())
S=[input() for i in range(H)]
A=[[0]*W for i in range(H)]
for i in range(H):
    k=0
    for j in range(W):
        if S[i][j]=="
            k=0
        else:
            k+=1
        A[i][j]=k
    for j in range(W-1,0,-1):
        if A[i][j-1]!=0 and A[i][j]!=0:
            A[i][j-1]=A[i][j]
B=[[0]*W for i in range(H)]
for j in range(W):
    k=0
    for i in range(H):
        if S[i][j]=="
            k=0
        else:
            k+=1
        B[i][j]=k
    for i in range(H-1,0,-1):
        if B[i][j]!=0 and B[i-1][j]!=0:
            B[i-1][j]=B[i][j]
ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,A[i][j]+B[i][j])
print(ans-1)

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

S = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if M[i][j] == ".":
            if j > 0:
                S[i][j] = S[i][j - 1] + 1
            else:
                S[i][j] = 1
    for j in range(W - 2, -1, -1):
        S[i][j] = max(S[i][j], S[i][j + 1]) * (1 if S[i][j] else 0)

T = [[0] * W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if M[i][j] == ".":
            if i > 0:
                T[i][j] = T[i - 1][j] + 1
            else:
                T[i][j] = 1
    for i in range(H - 2, -1, -1):
        T[i][j] = max(T[i][j], T[i + 1][j]) * (1 if T[i][j] else 0)

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, S[i][j] + T[i][j] - 1)
print(ans)

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


L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * 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

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

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

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


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

print(ans)

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

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * 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



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



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



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




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


print(ans)

Solution (Python):
H, W = map(int, input().split())
obs = [[False for _ in range(W)] for _ in range(H)]
for y in range(H):
    s = input()
    for x in range(W):
        obs[y][x] = (s[x] == '

inc_x = [[0 for _ in range(W)] for _ in range(H)]
cnt_x = [[0 for _ in range(W)] for _ in range(H)]
for y in range(H):
    for x in range(W):
        if obs[y][x]: 
            inc_x[y][x]= 0
        elif x == 0 or obs[y][x-1]:
            inc_x[y][x] = 1
        else:
            inc_x[y][x] = inc_x[y][x-1] + 1
    for x in reversed(range(W)):
        if obs[y][x]:
            cnt_x[y][x]= 0
        elif x == W-1 or obs[y][x+1]:
            cnt_x[y][x] = inc_x[y][x]
        else:
            cnt_x[y][x] += cnt_x[y][x+1]

inc_y = [[0 for _ in range(W)] for _ in range(H)]
cnt_y = [[0 for _ in range(W)] for _ in range(H)]
for x in range(W):
    for y in range(H):
        if obs[y][x]: 
            inc_y[y][x]= 0
        elif y == 0 or obs[y-1][x]:
            inc_y[y][x] = 1
        else:
            inc_y[y][x] = inc_y[y-1][x] + 1
    for y in reversed(range(H)):
        if obs[y][x]:
            cnt_y[y][x]= 0
        elif y == H-1 or obs[y+1][x]:
            cnt_y[y][x] = inc_y[y][x]
        else:
            cnt_y[y][x] += cnt_y[y+1][x]


cnt = [[cnt_x[y][x]+cnt_y[y][x]-1 for x in range(W)] for y in range(H)]
ans = max([max(cnt[y]) for y in range(H)])
print(ans)

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 = list(map(int, input().split()))
M = [['.' for w in range(W)] for h in range(H)]
for h in range(0, H):
    M[h] = list(input())

Yoko = [[0 for w in range(W)] for h in range(H)]
Tate = [[0 for w in range(W)] for h in range(H)]
for h in range(0, H):
    for w in range(0, W):
        if M[h][w] != '
            if w > 0 and M[h][w - 1] != '
                Yoko[h][w] = Yoko[h][w - 1]
            else:
                c = 0
                for d in range(w, W):
                    if M[h][d] == '
                        break
                    c += 1
                Yoko[h][w] = c
for w in range(0, W):
    for h in range(0, H):
        if M[h][w] != '
            if h > 0 and Tate[h - 1][w] > 0:
                Tate[h][w] = Tate[h - 1][w]
            else:
                c = 0
                for d in range(h, H):
                    if M[d][w] == '
                        break
                    c += 1
                Tate[h][w] = c
mx = 0
for w in range(0, W):
    for h in range(0, H):
        c = Yoko[h][w] + Tate[h][w] - 1
        if c > mx:
            mx = c
print(mx)

Solution (Python):






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

..
...



"""





field = np.ones((H, W))
field[S=='
lm, rm, um, dm = (field.copy() for _ in [0]*4)











for i in range(1, H):
    um[i] = (um[i-1]+1) * field[i]
    dm[-1-i] = (dm[-i]+1) * field[-1-i]
    
for i in range(1, W):
    lm[:, i] = (lm[:, i-1]+1) * field[:, i]
    rm[:, -1-i] = (rm[:, -i]+1) * field[:, -1-i]
    










print(int(np.max(um+dm+lm+rm)-3))

Solution (Python):
class Counter:
  def __init__(self):
    self.v = 0

  def increment(self):
    self.v += 1


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

M = [None] * H
MX = [None] * H
MY = [None] * H

for i in range(H):
  M[i] = [c == '.' for c in input().strip()]
  MX[i] = [None] * W
  MY[i] = [None] * W

max_size = 0

for i in range(H):
  for j in range(W):
    if not M[i][j]: continue

    if MX[i][j] is None:
      tmp = Counter()
      for x in range(j, W):
        if not M[i][x]: break
        MX[i][x] = tmp
        tmp.increment()

    if MY[i][j] is None:
      tmp = Counter()
      for y in range(i, H):
        if not M[y][j]: break
        MY[y][j] = tmp
        tmp.increment()

    size = MX[i][j].v + MY[i][j].v - 1
    max_size = max(max_size, size)

print(max_size)

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

s = [0] * H

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


L = [[0 for _ in range(W+2)] for _ in range(H+2)]
R = [[0 for _ in range(W+2)] for _ in range(H+2)]
U = [[0 for _ in range(W+2)] for _ in range(H+2)]
D = [[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-1][j-1] == '
            L[i][j] = 0
            U[i][j] = 0
        else :
            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] = 0
            D[-i-1][-j-1] = 0
        else :
            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) :
        point = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        if ans < point :
            ans = point

print(ans)

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

seq = 0
w_bright_cell = [[0]*W for i in range(H)]
for i in range(H):
    seq = 0
    for j in range(W):
        if Ss[i][j] == "
            seq = 0
            w_bright_cell[i][j] = -1
            continue
        seq += 1
        w_bright_cell[i][j] = seq
    
    obstacle_flag = True
    for j in range(W-1, -1, -1):
        if w_bright_cell[i][j] == -1:
            obstacle_flag = True
            continue
        if obstacle_flag:
            obstacle_flag = False
            seq = w_bright_cell[i][j]
            continue
        w_bright_cell[i][j] = seq

seq = 0
h_bright_cell = [[0]*W for i in range(H)]
for j in range(W):
    seq = 0
    for i in range(H):
        if Ss[i][j] == "
            seq = 0
            h_bright_cell[i][j] = -1
            continue
        seq += 1
        h_bright_cell[i][j] = seq

    obstacle_flag = True
    for i in range(H-1, -1, -1):
        if h_bright_cell[i][j] == -1:
            obstacle_flag = True
            continue
        if obstacle_flag:
            obstacle_flag = False
            seq = h_bright_cell[i][j]
            continue
        h_bright_cell[i][j] = seq

now_max = 0
for i in range(H):
    for j in range(W):
        h = h_bright_cell[i][j]
        w = w_bright_cell[i][j]
        now_max = max((now_max, h+w))

print(now_max-1)

Solution (Python):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
leftbeam = [[0 for _ in range(w)] for _ in range(h)]
rightbeam = [[0 for _ in range(w)] for _ in range(h)]
downbeam = [[0 for _ in range(w)] for _ in range(h)]
upbeam = [[0 for _ in range(w)] for _ in range(h)]

def can_light(y, x):
    return (0 <= y < h) and (0 <= x < w) and s[y][x] == '.'

for y in range(h):
    beamlen = 0
    for x in range(w):
        if can_light(y, x):
            beamlen += 1
        else:
            beamlen = 0
        leftbeam[y][x] = beamlen

for y in range(h):
    beamlen = 0
    for x in range(w):
        if can_light(y, w - x - 1):
            beamlen += 1
        else:
            beamlen = 0
        rightbeam[y][w - x - 1] = beamlen


for x in range(w):
    beamlen = 0
    for y in range(h):
        if can_light(y, x):
            beamlen += 1
        else:
            beamlen = 0
        downbeam[y][x] = beamlen

for x in range(w):
    beamlen = 0
    for y in range(h):
        if can_light(h - y - 1, x):
            beamlen += 1
        else:
            beamlen = 0
        upbeam[h - y - 1][x] = beamlen

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, leftbeam[y][x] + rightbeam[y][x]
                     + downbeam[y][x] + upbeam[y][x] - 3)

print(ans)

Solution (Python):
def main():
    h,w = map(int,input().split())
    a = {}
    for i in range(h):
        a[i] = input()
    ans = 0
    L = []
    R = []
    D = []
    U = []
    for x in range(h):
        L.append([])
        R.append([])
        for y in range(w):
            if a[x][y] == "
                L[x].append(0)
            elif y == 0:
                L[x].append(1)
            else:
                L[x].append(L[x][y-1]+1)
        for y in range(w-1,-1,-1):
            if a[x][y] == "
                R[x].append(0)
            elif y == w-1:
                R[x].append(1)
            else:
                R[x].append(R[x][w-y-2]+1)
        R[x].reverse()
    for y in range(w):
        D.append([])
        U.append([])
        for x in range(h):
            if a[x][y] == "
                U[y].append(0)
            elif x == 0:
                U[y].append(1)
            else:
                U[y].append(U[y][x-1]+1)
        for x in range(h-1,-1,-1):
            if a[x][y] == "
                D[y].append(0)
            elif x == h-1:
                D[y].append(1)
            else:
                D[y].append(D[y][h-x-2]+1)
        D[y].reverse()

    for x in range(h):
        for y in range(w):
            ans = max(ans, R[x][y]+L[x][y]+U[y][x]+D[y][x]-3)
            
    print(ans)
main()

Solution (Python):
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
s = [[j for j in input()] for i in range(h)]
d_2y = [[0] * w for i in range(h)]
d_2t = [[0] * w for i in range(h)]
d_2w = [[0] * w for i in range(h)]
for i in range(h):
  c = 0
  for j in range(w):
    if s[i][j] == '
      c = 0
    else:
      c += 1
    d_2y[i][j] = c
for i in range(h):
  for j in range(w-2,-1,-1):
    if s[i][j] == '
      continue
    else:
      d_2y[i][j] = max(d_2y[i][j+1],d_2y[i][j])
for i in range(w):
  c = 0
  for j in range(h):
    if s[j][i] == '
      c = 0
    else:
      c += 1
    d_2t[j][i] = c
for i in range(w):
  for j in range(h-2,-1,-1):
    if s[j][i] == '
      d_2t[j][i] = 0
    else:
      d_2t[j][i] = max(d_2t[j][i],d_2t[j+1][i])
m = 0
for i in range(h):
  for j in range(w):
    d_2w[i][j] = d_2y[i][j] + d_2t[i][j]
  m = max(m,max(d_2w[i]))
print(m-1)

Solution (Python):
H, W = map(int, input().split())
maze = [input() for i in range(H)]
dp_holi = [[0] * W for i in range(H)]
dp_ver = [[0] * W for i in range(H)]



for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            if j - 1 < 0 or maze[i][j -1] == "
                tmp = 0
                flag = False
                for k in maze[i][j:]:
                    if k == ".":
                        tmp += 1
                        flag = True
                    else:
                        dp_holi[i][j] = tmp
                        break
                if flag:
                    dp_holi[i][j] = tmp
            elif maze[i][j - 1] == ".":
                dp_holi[i][j] += dp_holi[i][j - 1]


for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            if i - 1 < 0 or maze[i -1][j] == "
                tmp = 0
                flag = False
                for k in range(i, H):
                    if maze[k][j] == ".":
                        tmp += 1
                        flag = True
                    else:
                        dp_ver[i][j] += tmp
                        flag = False
                        break
                if flag:
                    dp_ver[i][j] += tmp
            elif i - 1 < 0:
                continue
            elif maze[i - 1][j] == ".":
                dp_ver[i][j] += dp_ver[i - 1][j]

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, dp_holi[i][j] + dp_ver[i][j] - 1)
print(ans)

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

DPL = [[0 for _ in range(W+2)] for _ in range(H+2)]
DPR = [[0 for _ in range(W+2)] for _ in range(H+2)]
DPU = [[0 for _ in range(W+2)] for _ in range(H+2)]
DPD = [[0 for _ in range(W+2)] for _ in range(H+2)]

for h in range(1, H+1):
    for w in range(1, W+1):
        if Field[h][w] == '
            DPL[h][w] = 0
        else:
            DPL[h][w] = DPL[h][w-1] + 1
for h in range(1, H+1):
    for w in range(1, W+1):
        if Field[h][W-w+1] == '
            DPR[h][W-w+1] = 0
        else:
            DPR[h][W-w+1] = DPR[h][W-w+1+1] + 1
for h in range(1, H+1):
    for w in range(1, W+1):
        if Field[h][w] == '
            DPU[h][w] = 0
        else:
            DPU[h][w] = DPU[h-1][w] + 1   
for h in range(1, H+1):
    for w in range(1, W+1):
        if Field[H-h+1][w] == '
            DPD[H-h+1][w] = 0
        else:
            DPD[H-h+1][w] = DPD[H-h+1+1][w] + 1 
ans = 0          
for h in range(1, H+1):
    for w in range(1, W+1):
        ans = max(ans,DPL[h][w]+DPR[h][w]+DPU[h][w]+DPD[h][w])
print(ans-3)

Solution (Python):



H,W = list(map(int,input().split()))
Lamp = [list(input()) for _ in range(H)]
field = [[True for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
            if Lamp[i][j] == '
                field[i][j] = False
L = [[1 for _ in range(W)] for _ in range(H)]
R = [[1 for _ in range(W)] for _ in range(H)]
U = [[1 for _ in range(W)] for _ in range(H)]
D = [[1 for _ in range(W)] for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if field[i][j]:
            if i-1 >= 0:
                if field[i-1][j]:
                    D[i][j] = D[i-1][j]+1
            if j-1 >= 0:
                if field[i][j-1]:
                    L[i][j] = L[i][j-1]+1
for i in range(H)[::-1]:
    for j in range(W)[::-1]:
        if field[i][j]:
            if i+1 < H:
                if field[i+1][j]:
                    U[i][j] = U[i+1][j]+1
            if j+1 < W:
                if field[i][j+1]:
                    R[i][j] = R[i][j+1]+1

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

Solution (Python):
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

H, W = nl()
grid = []
for i in range(H):
    grid.append(s())

ups = [[0]*W for j in range(H)]
downs = [[0]*W for j in range(H)]
lefts = [[0]*W for j in range(H)]
rights = [[0]*W for j in range(H)]

for col in range(W):
    p = 0
    for row in range(H):
        if grid[row][col] == '
            p = 0
        else:
            p += 1
        ups[row][col] = p

    p = 0
    for row in range(H-1, -1, -1):
        if grid[row][col] == '
            p = 0
        else:
            p += 1
        downs[row][col] = p

for row in range(H):
    p = 0
    for col in range(W):
        if grid[row][col] == '
            p = 0
        else:
            p += 1
        lefts[row][col] = p

    p = 0
    for col in range(W-1, -1, -1):
        if grid[row][col] == '
            p = 0
        else:
            p += 1
        rights[row][col] = p

res = 0
for row in range(H):
    for col in range(W):
        res = max(res, ups[row][col] + downs[row][col] + lefts[row][col] + rights[row][col] -3)
print(res)

Solution (Python):
import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'
T=np.zeros((H,W),dtype=int)
B=np.zeros((H,W),dtype=int)
L=np.zeros((H,W),dtype=int)
R=np.zeros((H,W),dtype=int)

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

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

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

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

na=((T+B+L+R)*S).max()+1

print(na)

Solution (Python):
h,w=map(int,input().split())
s=[list(input())for _ in range(h)]
score=[[0]*w for _ in range(h)]
ans=0
range_w=range(w)
range_h=range(h)
for i in range_h:
  tmp_1=0
  tmp_2=0
  for j in range_w:
    if s[i][j]=="
      tmp_1=0
    else:
      tmp_1+=1
    score[i][j]+=tmp_1
    
    if s[i][-j-1]=="
      tmp_2=0
    else:
      tmp_2+=1
    score[i][-j-1]+=tmp_2
    
for j in range_w:
  tmp_3=0
  tmp_4=0
  for i in range_h:
    if s[i][j]=="
      tmp_3=0
    else:
      tmp_3+=1
    score[i][j]+=tmp_3
    
    if s[-i-1][j]=="
      tmp_4=0
    else:
      tmp_4+=1
    score[-i-1][j]+=tmp_4-3
for i in range(h):
  for j in range(w):
    ans=max(ans,score[i][j])
print(ans)

Solution (Python):
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


h, w = MI()
s = [IS() 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 i in range(h):
    for j in range(w):
        if s[i][j] == '
            L[i][j] = 0
        else:
            if j == 0:
                L[i][j] = 1
            elif j > 0:
                L[i][j] = L[i][j - 1] + 1

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

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

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






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

Solution (Python):
H, W = map(int, input().split())
Ss = [input() for _ in range(H)]
L = [[0]*W for _ in range(H)]
R = [[0]*W for _ in range(H)]
D = [[0]*H for _ in range(W)]
U = [[0]*H for _ in range(W)]
for i in range(H):
    for j in range(W):
        if Ss[i][j] == '.':
            if j == 0:
                L[i][0] = 1
            else:
                L[i][j] = L[i][j-1] + 1
        if Ss[i][-j-1] == '.':
            if j == 0:
                R[i][-1] = 1
            else:
                R[i][-j-1] = R[i][-j] + 1
                
for j in range(W):
    for i in range(H):
        if Ss[i][j] == '.':
            if i == 0:
                U[j][0] = 1
            else:
                U[j][i] = U[j][i-1]+1
        if Ss[-i-1][j] == '.':
            if i == 0:
                D[j][-1] = 1
            else:
                D[j][-i-1] = D[j][-i] + 1

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

Solution (Python):
from itertools import takewhile

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

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

for i, j in ((i, j) for i in range(H) for j in range(W) if S[i][j] == '.'):
    if x[i][j] == 0:
        w = len(list(takewhile(lambda k: S[i][k] == '.', range(j, W))))
        for k in range(j, j + w):
            x[i][k] = w
    if y[i][j] == 0:
        h = len(list(takewhile(lambda k: S[k][j] == '.', range(i, H))))
        for l in range(i, i + h):
            y[l][j] = h

ans = max(
    x[i][j] + y[i][j] - 1
    for i in range(H)
    for j in range(W)
)

print(ans)

Solution (Python):

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

for _ in range(H):
    a = input()
    S.append(list(a))
 
maxlamp = 0

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





 

for _h in range(H):
    for _w in range(W):
        if S[_h][_w] != '
            if _w == 0:
                L[_h][_w] = 1
            elif _w > 0:
                L[_h][_w] = L[_h][_w-1] + 1
    
            if _h == 0:
                U[_h][_w] = 1
            elif _h > 0:
                U[_h][_w] = U[_h-1][_w] + 1
 
for _h in range(H-1,-1,-1):
    for _w in range(W-1,-1,-1):
        if S[_h][_w] != '
            if _w == W-1:
                R[_h][_w] = 1
            elif _w < W-1:
                R[_h][_w] = R[_h][_w+1] + 1
 
            if _h == H-1:
                D[_h][_w] = 1
                
            elif _h < H-1:
                D[_h][_w] = D[_h+1][_w] + 1
        
            tmp = L[_h][_w] + R[_h][_w] + U[_h][_w] + D[_h][_w] - 3
            maxlamp = max(maxlamp,tmp)
 
print(maxlamp)