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):
def main():
  _max = max
  h, w = map(int, input().split())
  s = [input() + '
  s.append('

  rt = [[-1] * w for _ in range(h)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    ystart = -1
    for j in range(w + 1):
      if si[j] == '
        if ystart != -1:
          for k in range(ystart, j):
            rt[i][k] += j - ystart
          ystart = -1
        if tstart[j] != -1:
          for k in range(tstart[j], i):
            rt[k][j] += i - tstart[j]
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tstart[j] == -1:
          tstart[j] = i

  print(_max(_max(l) for l in rt))

main()

Solution (Python):
def main():
  h, w = map(int, input().split())
  s = [input() + '
  s.append('

  yoko = [[0] * w for _ in range(h)]
  tate = [[0] * w for _ in range(h)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    ystart = -1
    for j in range(w + 1):
      if si[j] == '
        if ystart != -1:
          for k in range(ystart, j):
            yoko[i][k] = j - ystart
          ystart = -1
        if tstart[j] != -1:
          for k in range(tstart[j], i):
            tate[k][j] = i - tstart[j]
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tstart[j] == -1:
          tstart[j] = i

  result = 0
  for i in range(h):
    yokoi = yoko[i]
    tatei = tate[i]
    for j in range(w):
      t = yokoi[j] + tatei[j] - 1
      if t > result:
        result = t

  print(result)

main()

Solution (Python):
h, w = map(int, input().split())
s = [input() + '
s.append('

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

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

result = 0
for i in range(h):
  for j in range(w):
    t = yoko[i][j] + tate[i][j] - 1
    if t > result:
      result = t

print(result)

Solution (Python):
h, w = map(int, input().split())
s = [input() + '
s.append('

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  start = -1
  for j in range(w + 1):
    if si[j] == '
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

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

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Solution (Python):
h, w = map(int, input().split())
s = [input() + '
s.append('

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  jj = -1
  for j in range(w):
    if si[j] == '.':
      start = j
      jj = j + 1
      break
  if jj == -1:
    continue
  for j in range(jj, w + 1):
    if si[j] == '
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  jj = -1
  for j in range(h):
    if s[j][i] == '.':
      start = j
      jj = j + 1
      break
  if jj == -1:
    continue
  for j in range(jj, h + 1):
    if s[j][i] == '
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Solution (Python):
h, w = map(int, input().split())
s = [input() + '
s.append('

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  if si[0] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, w + 1):
    if si[j] == '
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Solution (Python):
h, w = map(int, input().split())
s = [input() + '
s.append('

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  if s[i][0] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, w + 1):
    if s[i][j] == '
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j
result = 0
for i in range(h):
  for j in range(w):
    t = yoko[i][j] + tate[i][j] - 1
    if t > result:
      result = t

print(result)

Solution (Python):
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()

range_W = range(W)
range_H = 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]
res = [[0] * W for _ in range_H]
grid = []

append = grid.append
for i in range_H:
    row = list(" ".join(input()).split())
    append(row)

def solve():
    ans = 0
    for i in range_H:
        for j in range_W:
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)

            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

if __name__ == "__main__":
    print(solve())

Solution (Python):
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()

range_W = range(W)
range_H = 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]
res = [[0 for _ in range_W] for _ in range_H]
grid = []

append = grid.append
for i in range_H:
    row = list(" ".join(input()).split())
    append(row)

def solve():
    ans = 0
    for i in range_H:
        for j in range_W:
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)

            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

if __name__ == "__main__":
    print(solve())

Solution (Python):


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

t=0
for i in range(h):
	t=0
	for j in range(w):
		if s[i][j]==".":
			t+=1
		else:
			t=0
		x[i][j]=t
for i in range(h):
	for j in range(1,w):
		if x[i][w-j-1]==0:
			continue
		elif x[i][w-j]==0:
			continue
		else:
			x[i][w-j-1]=x[i][w-j]

t=0
for j in range(w):
	t=0
	for i in range(h):
		if s[i][j]==".":
			t+=1
		else:
			t=0
		y[i][j]=t
for j in range(w):
	for i in range(1,h):
		if y[h-i-1][j]==0:
			continue
		elif y[h-i][j]==0:
			continue
		else:
			y[h-i-1][j]=y[h-i][j]

z=[[x[i][j]+y[i][j] for j in range(w)] for i in range(h)]
res=0
for t in z:
	res=max(res,max(t))
print(max(0,res-1))

Solution (Python):
import sys, math, heapq
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()



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)]
res = [[0 for _ in range(W)] for _ in range(H)]
grid = []

for i in range(H):
    row = list(" ".join(input()).split())
    grid.append(row)

def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)
 
            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

if __name__ == "__main__":
    print(solve())

Solution (Python):
h,w=map(int,input().split())
s=[list(input()) for _ in range(h)]
l=[[0]*w for _ in range(h)]
r=[[0]*w for _ in range(h)]
u=[[0]*w for _ in range(h)]
d=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j]=="
            continue
        if j==0:
            l[i][j]=1
        else:
            l[i][j]=l[i][j-1]+1
        if j==w-1:
            r[i][j]=1
        else:
            r[i][j]=r[i][j+1]+1
        if 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]=="
            continue
        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):
        ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(ans)

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

l = np.zeros((H,W))
l[:,-1] = S[:,-1]
r = np.zeros((H,W))
r[:,0] = S[:,0]
u = np.zeros((H,W))
u[-1] = S[-1]
d = np.zeros((H,W))
d[0] = S[0]

for i in range(W-2,-1,-1):
  l[:,i] = (l[:,i+1]+1)*S[:,i]
for i in range(1,W):
  r[:,i] = (r[:,i-1]+1)*S[:,i]
for i in range(H-2,-1,-1):
  u[i] = (u[i+1]+1)*S[i]
for i in range(1,H):
  d[i] = (d[i-1]+1)*S[i]

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

Solution (Python):

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


trailLeft = np.zeros((H, W), dtype=int)
trailRight = np.zeros((H, W), dtype=int)
trailUp = np.zeros((H, W), dtype=int)
trailDown = np.zeros((H, W), dtype=int)

for i in range(H):
    if i == 0:
        trailUp[i] = S[i]
        trailDown[H - i - 1] = S[H - i - 1] * 1
    else:
        trailUp[i] = (trailUp[i - 1] + 1) * S[i]
        trailDown[H - i - 1] = (trailDown[H - i] + 1) * S[H - i - 1]

for j in range(W):
    if j == 0:
        trailLeft[:, j] = S[:, j]
        trailRight[:, W - j - 1] = S[:, W - j - 1] * 1
    else:
        trailLeft[:, j] = (trailLeft[:, j - 1] + 1) * S[:, j]
        trailRight[:, W - j - 1] = (trailRight[:, W - j] + 1) * S[:, W - j - 1]

print(np.max(trailLeft + trailRight + trailUp + trailDown - 3))

Solution (Python):
from itertools import product
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)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
for i, j in product(range(h),range(w)):
    l = S[i][j]
    r = S[i][w-1-j]
    u = S[i][j]
    d = S[h-1-i][j]
    if l == ".": L[i][j] = L[i][max(0, j-1)]+1
    if r == ".": R[i][w-1-j] = R[i][min(w-1, w-j)]+1
    if u == ".": U[i][j] = U[max(0, i-1)][j]+1
    if d == ".": D[h-1-i][j] = D[min(h-1, h-i)][j]+1
A = [L[i][j]+R[i][j]+U[i][j]+D[i][j]-3 for i, j in product(range(h), range(w))]
print(max(A))

Solution (Python):
import numpy as np

H, W = map(int, input().split())
mat = np.array([[0 if v == "

l, r = np.zeros((H, W)), np.zeros((H, W))
for w in range(W):
    l[:, w] = (l[:, w-1] + 1) * mat[:, w]
    r[:, -w-1] = (r[:, -w] + 1) * mat[:, -w-1]

u, d = np.zeros((H, W)), np.zeros((H, W))
for h in range(H):
    u[h, :] = (u[h - 1, :] + 1) * mat[h, :]
    d[-h - 1, :] = (d[-h, :] + 1) * mat[-h - 1, :]

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

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

Solution (Python):
h,w=map(int, input().split())
s=list(list(input()) for i in range(h))
ans=0
dpL=[[0]*(w) for i in range(h)]
dpR=[[0]*(w) for i in range(h)]
dpU=[[0]*(w) for i in range(h)]
dpD=[[0]*(w) for i in range(h)]

for i in range(h):
    for j in range(w):
        
        if s[i][j]=='.':
            if j==0:
                dpL[i][j]=1
            else:
                dpL[i][j]=dpL[i][j-1]+1
        else:
            continue
            
for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j]=='.':
            if j==w-1:
                dpR[i][j]=1
            else:
                dpR[i][j]=dpR[i][j+1]+1
        else:
            continue
            
for i in range(w):
    for j in range(h):
        if s[j][i]=='.':
            if j==0:
                dpU[j][i]=1
            else:
                dpU[j][i]=dpU[j-1][i]+1
        else:
            continue
            
for i in range(w):
    for j in range(h-1,-1,-1):
        if s[j][i]=='.':
            if j==h-1:
                dpD[j][i]=1
            else:
                dpD[j][i]=dpD[j+1][i]+1
        else:
            continue

for i in range(h):
    for j in range(w):
        x=dpU[i][j]+dpD[i][j]+dpR[i][j]+dpL[i][j]-3
        if x>ans:
            ans=x
print(ans)

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

H, W = map(int, input().split())
S = [[1 if a == '.' else 0 for a in list(input())]  for _ in range(H)]

def main():
    R = copy.deepcopy(S)
    for h in range(H):
        s = 0
        for w in range(W):
            if R[h][w] == 1:
                s += 1
                R[h][w] = s
            else:
                s = 0
        l = 0
        for w in range(W-1, -1, -1):
            if R[h][w] > 0:
                l = max(l, R[h][w])
                R[h][w] = l
            else:
                l = 0

    L = copy.deepcopy(S)
    for w in range(W):
        s = 0
        for h in range(H):
            if L[h][w] == 1:
                s += 1
                L[h][w] = s
            else:
                s = 0
        l = 0
        for h in range(H-1, -1, -1):
            if L[h][w] > 0:
                l = max(l, L[h][w])
                L[h][w] = l
            else:
                l = 0
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, L[h][w]+R[h][w]-1)
    print(ans)

if __name__ == "__main__":
    main()

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

grid = [input() for i in range(h)]

L = [[0 for i in range(w)] for j in range(h)]
R = [[0 for i in range(w)] for j in range(h)]
D = [[0 for i in range(w)] for j in range(h)]
U = [[0 for i in range(w)] for j in range(h)]


for i in range(h):
    for j in range(w):
        if grid[i][j] == "
            L[i][j] = 0
            U[i][j] = 0
        else:
            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 grid[i][j] == "
            R[i][j] = 0
            D[i][j] = 0
        else:
            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 grid[i][j] == "
            continue
        tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        ans = max(ans, tmp)

print(ans)

Solution (Python):

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H)]
U = [[0 for i in range(W)] for j in range(H)]
 
for i in range(H):
    for j in range(W):
        if S[i][j] == '
            continue
        elif j == 0:
            L[i][j] = 1
        elif L[i][j - 1] == 0:
            L[i][j] = 1            
        else:
            L[i][j] = L[i][j - 1] + 1
            
    for j in range(W - 1, -1, -1):
        if S[i][j] == '
            continue
        elif j == W - 1:
            R[i][j] = 1
        elif L[i][j + 1] == 0:
            R[i][j] = 1            
        else:
            R[i][j] = R[i][j + 1] + 1

for j in range(W):
    for i in range(H):
        if S[i][j] == '
            continue
        elif i == 0:
            D[i][j] = 1
        elif L[i - 1][j] == 0:
            D[i][j] = 1            
        else:
            D[i][j] = D[i - 1][j] + 1
            
    for i in range(H - 1, -1, -1):
        if S[i][j] == '
            continue
        elif i == H - 1:
            U[i][j] = 1
        elif L[i + 1][j] == 0:
            U[i][j] = 1            
        else:
            U[i][j] = U[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] + D[i][j] + U[i][j] - 3))
print(ans)

Solution (Python):
h, w = map(int, input().split())
s=[]
for i in range(h):
    s.append(list(input()))
 
l=[[0 for i in range(w)] for j in range(h)]
r=[[0 for i in range(w)] for j in range(h)]
u=[[0 for i in range(w)] for j in range(h)]
d=[[0 for i in range(w)] for j in range(h)]
for y in range(h):
    for x in range(w):
        if s[y][x] == '.':
            if x == 0:
                l[y][x]=1
            else:
                l[y][x]=l[y][x-1]+1
        
        if s[y][w-x-1] == '.':
            if x == 0:
                r[y][w-x-1]=1
            else:
                r[y][w-x-1]=r[y][w-x]+1
 
        if s[y][x] == '.':
            if y == 0:
                u[y][x]=1
            else:
                u[y][x]=u[y-1][x]+1
        
        if s[h-y-1][x] == '.':
            if y == 0:
                d[h-y-1][x]=1
            else:
                d[h-y-1][x]=d[h-y][x]+1
 
ans=0
for y in range(h):
    for x in range(w):
        val=l[y][x]+r[y][x]+u[y][x]+d[y][x]-3
        ans=max(ans, val)
 
print(ans)

Solution (Python):

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

S = []

for i in range(H):

    s = input()
    S.append(list(s))

yoko = []

for i in range(H):

    num = 0
    now = []

    for j in range(W):

        if S[i][j] == ".":
            num += 1

        else:
            now += ([num] * num)
            num = 0
            now.append(0)

    now += [num] * num
    yoko.append(now)



tate = []

for j in range(W):

    num = 0
    now = []

    for i in range(H):

        if S[i][j] == ".":
            num += 1

        else:
            now += ([num]*num)
            num = 0
            now.append(0)

    now += [num] * num
    tate.append(now)

ans = 0

for i in range(H):

    for j in range(W):

        ans = max(ans , yoko[i][j] + tate[j][i] - 1)

print (ans)

Solution (Python):
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)]
top = [[0]*W for _ in range(H)]
bottom = [[0]*W for _ in range(H)]

for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j] == '
            cnt = 0
        else:
            cnt += 1
            top[i][j] = cnt
            
for j in range(W):
    cnt = 0
    for i in reversed(range(H)):
        if S[i][j] == '
            cnt = 0
        else:
            cnt += 1
            bottom[i][j] = cnt
            
for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j] == '
            cnt = 0
        else:
            cnt += 1
            left[i][j] = cnt
            
for i in range(H):
    cnt = 0
    for j in reversed(range(W)):
        if S[i][j] == '
            cnt = 0
        else:
            cnt += 1
            right[i][j] = cnt
                        
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,left[i][j]+right[i][j]+top[i][j]+bottom[i][j]-3)
        
print(ans)

Solution (Python):
import numpy as np


def main():
    h, w = list(map(int, input().split()))
    grid = []
    for _ in range(h):
        grid.append(list(input()))

    grid = np.array(grid) == '.'
    

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

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

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

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

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

    score = ((U + D + L + R) * grid).max() + 1
    print(score)


main()

Solution (Python):
h,w=map(int, input().split())
s=[[0 for _ in range(w)] for _ in range(h)]
for j in range(h):
    s[j]=list(input())
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)]
max=0

for i in range(h):
    for j in range(w):
        if s[i][j]=='
            l[i][j]=0
            u[i][j]=0
        else:
            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 range(h-1,-1,-1):
    for j in range(w-1,-1,-1):
        if s[i][j]=='
            r[i][j]=0
            d[i][j]=0
        else:
            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
                   
for i in range(h):
    for j in range(w):        
        total=l[i][j]+r[i][j]+d[i][j]+u[i][j]

        if max<total:
            max=total

print(max-3)

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)
R = np.zeros((H, W), dtype=int)
L = 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(D + U + R + L) - 3)

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

l = [[0 for _ in range(w)] for _ in range(h)]
r = [[0 for _ in range(w)] for _ in range(h)]
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):
        l[i][j] = 0 if s[i][j] == '
    for j in range(w-1, -1, -1):
        r[i][j] = 0 if s[i][j] == '
for j in range(w):
    for i in range(h):
        u[i][j] = 0 if s[i][j] == '
    for i in range(h-1, -1, -1):
        d[i][j] = 0 if s[i][j] == '

m = 0
for i in range(h):
    for j in range(w):
        k = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        if k > m:
            m = k

print(m)

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
flag = [[False] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        flag[i][j] = s[i][j] == "."
a = [[0] * w for i in range(h)]
for i in range(h):
    count = 0
    for j in range(w):
        if flag[i][j]:
            count += 1
            a[i][j] = count
        else:
            count = 0
for i in range(h - 1, -1, -1):
    m = 0
    for j in range(w - 1, -1, -1):
        if flag[i][j]:
            if m:
                a[i][j] = m
            else:
                m = a[i][j]
        else:
            m = 0
b = [[0] * w for i in range(h)]
for j in range(w):
    count = 0
    for i in range(h):
        if flag[i][j]:
            count += 1
            b[i][j] = count
        else:
            count = 0
for j in range(w - 1, -1, -1):
    m = 0
    for i in range(h - 1, -1, -1):
        if flag[i][j]:
            if m:
                b[i][j] = m
            else:
                m = b[i][j]
        else:
            m = 0
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, a[i][j] + b[i][j] - 1)
print(ans)

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

for i in range(h):
  tmp = input()
  s.append(tmp)


l = [[0 for i in range(w)] for j 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
        continue
      l[i][j] = l[i][j-1] + 1

      

d = [[0 for i in range(w)] for j in range(h)]

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



r = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
  for j in range(w)[::-1]:

    if s[i][j] == "
      r[i][j] = 0
    else:
      if j == w-1:

        r[i][j] = 1
        continue
      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)[::-1]:
    if s[i][j] == "
      u[i][j] = 0
    else:
      if i == h-1:
        u[i][j] = 1
        continue
      u[i][j] = u[i+1][j] + 1





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

unko = []
for i in range(h):
  mm = max(l[i])
  unko.append(mm)

print(max(unko))

Solution (Python):
import numpy as np

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


vertical_1 = np.zeros((H, W), dtype=int)
vertical_1[:, 0] = grid[:, 0]
for i in range(1, W):
    vertical_1[:, i] = (vertical_1[:, i-1] + 1) * grid[:, i]


vertical_2 = np.zeros((H, W), dtype=int)
vertical_2[:, -1] = grid[:, -1]
for i in range(W-2, -1, -1):
    vertical_2[:, i] = (vertical_2[:, i+1] + 1) * grid[:, i]


down_1 = np.zeros((H, W), dtype=int)
down_1[0] = grid[0]
for i in range(1, H):
    down_1[i] = (down_1[i-1] + 1) * grid[i]


down_2 = np.zeros((H, W), dtype=int)
down_2[-1] = grid[-1]
for i in range(H-2, -1, -1):
    down_2[i] = (down_2[i+1] + 1) * grid[i]

print((vertical_1 + vertical_2 +  down_1 + down_2 - 3).max())

Solution (Python):
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]
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)]
LAMP = [[0]*W for i in range(H)]
ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "
      L[i][j] = 0
    elif j == 0:
      L[i][j] = 1
    else:
      L[i][j] = L[i][j-1] + 1
    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
    if S[i][j] != "
       ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)