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())
field = [input() for _ in range(h)]

hor = [[0 for _ in range(w)] for _ in range(h)]
ver = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    count = 0
    for j in range(w):
        if field[i][j] == '
            for k in range(j-count, j):
                hor[i][k] = count
            count = 0
            hor[i][j] = 0
        else:
            count += 1
    for k in range(w-count, w):
        hor[i][k] = count

for j in range(w):
    count = 0
    for i in range(h):
        if field[i][j] == '
            for k in range(i-count, i):
                ver[k][j] = count
            count = 0
            ver[i][j] = 0
        else:
            count += 1
    for k in range(h-count, h):
        ver[k][j] = count

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, hor[i][j] + ver[i][j] - 1)
print(ans)

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

nums = [[0] * w for _ in range(h)]
ans = 0

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

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

for i in range(h):
    ans = max(ans, max(nums[i]))

print(ans)

Solution (Python):

h,w=list(map(int,input().split()))
s=[[i for i in input() ] for _ in range(h)]

l=[[1 if s[h_i][w_i]=="." else 0 for w_i in range(w)] for h_i in range(h)]
r=[[1 if s[h_i][w_i]=="." else 0 for w_i in range(w)] for h_i in range(h)]
u=[[1 if s[h_i][w_i]=="." else 0 for w_i in range(w)] for h_i in range(h)]
d=[[1 if s[h_i][w_i]=="." else 0 for w_i in range(w)] for h_i in range(h)]
for h_i in range(h):
    for w_i in range(w):
        rev_w=w-w_i-1
        rev_h=h-h_i-1
        if s[h_i][w_i]!="
            l[h_i][w_i]+=l[h_i][w_i-1]
        if s[h_i][rev_w]!="
            r[h_i][rev_w]+=r[h_i][rev_w+1]
        if s[h_i][w_i]!="
            u[h_i][w_i]+=u[h_i-1][w_i]
        if s[rev_h][w_i]!="
            d[rev_h][w_i]+=d[rev_h+1][w_i]
ans=0
for h_i in range(h):
    for w_i in range(w):
        tmp=l[h_i][w_i]+r[h_i][w_i]+u[h_i][w_i]+d[h_i][w_i]-3
        ans=max(ans,tmp)

print(ans)

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


ans_w = [[0] * w for i in range(h)]
ans_h = [[0] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        cnt = 0
        if s[i][j] == '
        if ans_w[i][j] != 0: continue

        while j + cnt < w:
            if s[i][j + cnt] == '
            cnt += 1

        for k in range(cnt):
            ans_w[i][j + k] = cnt


for i in range(w):
    for j in range(h):
        cnt = 0
        if s[j][i] == '
        if ans_h[j][i] != 0: continue

        while j + cnt < h:
            if s[j + cnt][i] == '
            cnt += 1

        for k in range(cnt):
            ans_h[j + k][i] = cnt


out = 0
for i in range(h):
    for j in range(w):
        out = max(out, ans_h[i][j] + ans_w[i][j])

print(out - 1)

Solution (Python):
import sys

h,w=list(map(int,input().split()))
s=[]

left=[[0]*w for _ in range(h)]
right=[[0]*w for _ in range(h)]
up=[[0]*w for _ in range(h)]
down=[[0]*w for _ in range(h)]

for i in range(h):
    s.append([x for x in sys.stdin.readline().strip()])

for i in range(h):
    cntl=0
    cntr=0
    for jl in range(w):
        jr=w-jl-1

        if s[i][jl]=='
            cntl=0
        else:
            cntl+=1
        
        if s[i][jr]=='
            cntr=0
        else:
            cntr+=1
        
        left[i][jl]=cntl
        right[i][jr]=cntr

for j in range(w):
    cntu=0
    cntd=0
    for iu in range(h):
        id=h-iu-1

        if s[iu][j]=='
            cntu=0
        else:
            cntu+=1
        
        if s[id][j]=='
            cntd=0
        else:
            cntd+=1
        
        up[iu][j]=cntu
        down[id][j]=cntd
ret=0

for i in range(h):
    for j in range(w):
        ret=max(ret,left[i][j]+right[i][j]+up[i][j]+down[i][j]-3)

print(ret)

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

s = [input() for _ in range(h)]

x_inf = [[0 for i in range(w)] for j in range(h)]
y_inf = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    p = -1
    for j in range(w):
        if s[i][j]=="
            p = j
        else:
            x_inf[i][j] = p

for i in range(h):
    p = w
    for j in range(-1,-w-1,-1):
        if s[i][j]=="
            p = w+j
        else:
            x_inf[i][j] -= p-1

for i in range(w):
    p = -1
    for j in range(h):
        if s[j][i]=="
            p = j
        else:
            y_inf[j][i] = p

for i in range(w):
    p = h
    for j in range(h-1,-1,-1):
        if s[j][i]=="
            p = j
        else:
            y_inf[j][i] -= p-1
result = []
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            result.append(x_inf[i][j]+y_inf[i][j]+1)
print(-min(result))

Solution (Python):
H,W = map(int,input().split())
S = [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)]
for h in range(H):
    for w in range(W):
        if S[h][w]==".":
            if h==0:D[h][w]=1
            else:D[h][w]=D[h-1][w]+1
            if w==0:R[h][w]=1
            else:R[h][w]=R[h][w-1]+1
for h in range(H-1,-1,-1):
    for w in range(W-1,-1,-1):
        if S[h][w]==".":
            if h==H-1:U[h][w]=1
            else:U[h][w]=U[h+1][w]+1
            if w==W-1:L[h][w]=1
            else:L[h][w]=L[h][w+1]+1

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

Solution (Python):



def main():
  h, w = map(int, input().strip().split())
  maze = [list(input().strip()) for _ in range(h)]
  countw = [[0]*w for _ in range(h)]
  counth = [[0]*w for _ in range(h)]
  for i in range(h):
    l=r=0
    for j in range(w):      
      if maze[i][j] == '
        l=0
      else:
        l+=1
        countw[i][j] += l
      if maze[i][-(j+1)] == '
        r=0
      else:
        r+=1
        countw[i][-(j+1)] += r
        
  for j in range(w):
    t=b=0
    for i in range(h):
      if maze[i][j] == '
        t=0
      else:
        t+=1
        counth[i][j] += t
      if maze[-(i+1)][j] == '
        b=0
      else:
        b+=1
        counth[-(i+1)][j] += b
    
  max = -1
  for i in range(h):
    for j in range(w):
      score = counth[i][j] + countw[i][j]
      if max < score:
        max = score
  print(max-3)
  
if __name__=='__main__':
  main()

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

X = [[0] * W for _ in range(H)]
for i in range(H):
    start = 0
    cnt = 0
    for j in range(W):
        if s[i][j] == "." and j == W - 1:
            cnt += 1
            for k in range(start, W):
                if s[i][k] == ".":
                    X[i][k] = cnt
        elif s[i][j] == ".":
            cnt += 1
        elif s[i][j] == "
            for k in range(start, j):
                if s[i][k] == ".":
                    X[i][k] = cnt
            start = j
            cnt = 0

Y = [[0] * W for _ in range(H)]
for i in range(W):
    start = 0
    cnt = 0
    for j in range(H):
        if s[j][i] == "." and j == H - 1:
            cnt += 1
            for k in range(start, H):
                if s[k][i] == ".":
                    Y[k][i] = cnt
        elif s[j][i] == ".":
            cnt += 1
        elif s[j][i] == "
            for k in range(start, j):
                if s[k][i] == ".":
                    Y[k][i] = cnt
            start = j
            cnt = 0

XY = []
for i in range(H):
    for j in range(W):
        XY.append(X[i][j] + Y[i][j] - 1)

print(max(XY))

Solution (Python):
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
cnt = [[1 for _ in range(W)] for _ in range(H)]
for h in range(H):
    ws = 0
    for w in range(W):
        if S[h][w] == "
            ws = 0
        else:
            cnt[h][w] += ws
            ws += 1
    ws = 0
    for w in range(W-1, -1, -1):
        if S[h][w] == "
            ws = 0
        else:
            cnt[h][w] += ws
            ws += 1

for w in range(W):
    hs = 0
    for h in range(H):
        if S[h][w] == "
            hs = 0
        else:
            cnt[h][w] += hs
            hs += 1
    hs = 0
    for h in range(H-1, -1, -1):
        if S[h][w] == "
            hs = 0
        else:
            cnt[h][w] += hs
            hs += 1
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, cnt[h][w])
print(ans)

Solution (Python):

import sys
input=sys.stdin.readline
h,w=map(int,input().split())
lists=[]
for i in range(h):
    b=list(input())
    lists.append(b)
    
right=[[0 for i in range(w)] for j in range(h)]
left=[[0 for i in range(w)] for j in range(h)]
up=[[0 for i in range(w)] for j in range(h)]
down=[[0 for i in range(w)] for j in range(h)]


for i in range(h):
    for j in range(w-1,-1,-1):
        if j==w-1:
            if lists[i][j]=="
                right[i][j]=0
            else:
                right[i][j]=1
        else:
            if lists[i][j+1]=="
                if lists[i][j]=="
                    right[i][j]=0
                else:
                    right[i][j]=1
            elif lists[i][j+1]==".":
                if lists[i][j]=="
                    right[i][j]=0
                else:
                    right[i][j]=right[i][j+1]+1



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



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

                

for i in range(w):
    for j in range(h-1,-1,-1):
        if j==h-1:
            if lists[j][i]=="
                down[j][i]=0
            else:
                down[j][i]=1
        else:
            if lists[j][i]=="
                down[j][i]=0
            else:
                down[j][i]=down[j+1][i]+1
                
maxi=0
for i in range(h):
    for j in range(w):
        maxi=max(maxi,right[i][j]+left[i][j]+up[i][j]+down[i][j]-3)
print(maxi)

Solution (Python):
H,W=map(int,input().split())
S=[]
for i in range(H):
    s=input()
    S.append(s)
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):
import numpy as np

h,w=map(int,input().split())
g = np.array([list(input()) for _ in range(h)])
g = np.where(g=='.',1,0)

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

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

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

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

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

data1=[[0 for i in range(0,W)] for i in range(0,H)]
data2=[[0 for i in range(0,W)] for i in range(0,H)]
for i in range(0,H):
    sequence=[]
    length=0
    for j in range(0,W):
        if S[i][j]=='.':
            sequence.append(j)
            length+=1
        else:
            for k in sequence:
                data1[i][k]=length
            sequence=[]
            length=0
    if sequence!=[]:
        for k in sequence:
            data1[i][k]=length

for i in range(0,W):
    sequence=[]
    length=0
    for j in range(0,H):
        if S[j][i]=='.':
            sequence.append(j)
            length+=1
        else:
            for k in sequence:
                data2[k][i]=length
            sequence=[]
            length=0
    if sequence!=[]:
        for k in sequence:
            data2[k][i]=length

ans=0
for i in range(0,H):
    for j in range(0,W):
        test=data1[i][j]+data2[i][j]-1
        if test>ans:
            ans=test
print(ans)

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce

import heapq
sys.setrecursionlimit(3000)






def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


















































import numpy as np
import sys

H, W = list(map(int, sys.stdin.readline().split()))
S = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == '.'
ups = np.zeros((H, W), dtype=int)
downs = np.zeros((H, W), dtype=int)
rights = np.zeros((H, W), dtype=int)
lefts = np.zeros((H, W), dtype=int)

for h in range(1, H):
    ups[h] = (ups[h - 1] + 1) * S[h - 1]
    downs[H - h - 1] = (downs[H - h] + 1) * S[H - h]
for w in range(1, W):
    lefts[:, w] = (lefts[:, w - 1] + 1) * S[:, w - 1]
    rights[:, W - w - 1] = (rights[:, W - w] + 1) * S[:, W - w]

print(((ups + downs + lefts + rights) * S).max() + 1)

Solution (Python):
from sys import stdin
h,w = map(int,stdin.readline().rstrip().split())
li = [stdin.readline().rstrip() 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)]
ma = 0
for i in range(h):
    for j in range(w):
        if li[i][j] == "
        elif 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):
        if li[i][w-j-1] == "
        elif w-j-1 == w-1:R[i][w-j-1] = 1
        else:R[i][w-j-1] = R[i][w-j]+1
for i in range(h):
    for j in range(w):
        if li[i][j] == "
        elif i == 0:U[i][j] = 1
        else:U[i][j] = U[i-1][j]+1
for i in range(h):
    for j in range(w):
        if li[h-i-1][j] == "
        elif h-i-1 == h-1:D[h-i-1][j] = 1
        else:D[h-i-1][j] = D[h-i][j]+1
for i in range(h):
    for j in range(w):
        point = L[i][j]+R[i][j]+D[i][j]+U[i][j]-3
        ma = max(ma,point)
print(ma)

Solution (Python):
H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]
 
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1
 
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            ans = max(ans,L[h][w]+U[h][w]+R[h][w]+D[h][w]-3)
 
print(ans)

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


L = np.zeros((H,W),dtype=np.int)
R = np.zeros((H,W),dtype=np.int)
U = np.zeros((H,W),dtype=np.int)
D = np.zeros((H,W),dtype=np.int)

for i in range(W):
    L[:,i] = (L[:,i-1]+1)*S[:,i]
    R[:,-i-1] = (R[:,-i]+1)*S[:,-i-1]
for j in range(H):
    U[j,:] = (U[j-1,:]+1)*S[j,:]
    D[-j-1,:] = (D[-j,:]+1)*S[-j-1,:]

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

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

def rotate(l_2d):
    l_2d = np.array(l_2d)
    return (l_2d.T).tolist()



done = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if done[i][j] == 1 or s[i][j] == "
            continue
        l = 0
        k = j
        while k < w:
            if s[i][k] == ".":
                l += 1
            else:
                break
            k += 1
        for o in range(l):
            cnt[i][j+o] += l
            done[i][j+o] = 1



done = [[0] * w for _ in range(h)]
for j in range(w):
    for i in range(h):
        if done[i][j] == 1 or s[i][j] == "
            continue
        l = 0
        k = i
        while k < h:
            if s[k][j] == ".":
                l += 1
            else:
                break
            k += 1
        for o in range(l):
            cnt[i+o][j] += l
            done[i+o][j] = 1

print(max(list(map(max, cnt))) - 1)

Solution (Python):
import sys
import math
import fractions
import bisect
import queue
import heapq
import collections
import itertools
sys.setrecursionlimit(4100000)

MOD = int(1e9+7)
PI = 3.14159265358979323846264338327950288
INF = 1e18

'''
1行のint=====================================
N, K = map(int, input().split())
N, M = map(int, input().split())
A, B = map(int, input().split())

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

L, R = map(int, input().split())

1行のstring=================================
S, T = input().split()

1行の整数配列================================
P = list(map(int,input().split()))

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
D = list(map(int,input().split()))

L = list(map(int,input().split()))
R = list(map(int,input().split()))

T = list(map(int,input().split()))

改行あり整数==================================
X = []
Y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    X.append(x1)
    Y.append(y1)

A = []
for i in range(N):
    a=int(input())
    A.append(a)

Pair = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    Pair.append((x1, y1))
    
2次元整数配列=====================================
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    A.append(tmp)


N行M列の初期化====================================
dp = [[VAL] * RETU for i in range(GYO)]

'''



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


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


for h in range(0, H):
    for w in range(1, W):

        if S[h][w-1] == "
            left[h][w] = 0
        else:
            left[h][w] = left[h][w-1] + 1


for h in range(0, H):
    for w in range(W-2, -1, -1):
        if S[h][w+1] == "
            right[h][w] = 0
        else:
            right[h][w] = right[h][w+1] + 1

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

for h in range(H-2, -1, -1):
    for w in range(0, W):
        if S[h+1][w] == "
            down[h][w] = 0
        else:
            down[h][w] = down[h+1][w] + 1

ans = 0
for h in range(H):
    for w in range(W):
        
        if S[h][w] == "
            continue

        ans = max(ans, right[h][w] + left[h][w] + up[h][w] + down[h][w] + 1)

print(ans)

Solution (Python):
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    H, W = read_values()
    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 h in range(H):
        for w in range(W):
            if S[h][w] == ".":
                X[h][w] = 1 if w == 0 else X[h][w - 1] + 1
                Y[h][w] = 1 if h == 0 else Y[h - 1][w] + 1

    res = 0
    for h in range(H - 1, -1, -1):
        for w in range(W - 1, -1, -1):
            if S[h][w] == "
                continue
            if w != W - 1:
                X[h][w] = max(X[h][w + 1], X[h][w]) 
            if h != H - 1:
                Y[h][w] = max(Y[h + 1][w], Y[h][w])
            res = max(res, X[h][w] + Y[h][w] - 1)
    print(res)

        
if __name__ == "__main__":
    main()

Solution (Python):
h, w = map(int, input().split())
s = ['']*(h+2)
s[0] = '
for i in range(1, h+1):
  s[i] = '
s[h+1] = '

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

Solution (Python):
import numpy as np
H,W = map(int,input().split())
HL=list(range(H))
WL=list(range(W))
Gd = np.array([list(input()) for _ in HL])
Gd = np.where(Gd=='.', 1, 0)
L=np.zeros((H,W),dtype=np.int64)
R=np.zeros((H,W),dtype=np.int64)
U=np.zeros((H,W),dtype=np.int64)
D=np.zeros((H,W),dtype=np.int64)

for w in WL:
  R[:,w]=(R[:,w-1]+1)*Gd[:,w]
  L[:,-w-1]=(L[:,-w]+1)*Gd[:,-w-1]
for h in HL:
  D[h,:]=(D[h-1,:]+1)*Gd[h,:]
  U[-h-1,:]=(U[-h,:]+1)*Gd[-h-1,:]
print(np.max(D+U+L+R-3))

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) ] 
u = [ [0]*w for _ in range(h) ] 
d = [ [0]*w for _ in range(h) ] 

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

for i in reversed(range(h)):
    for j in reversed(range(w)):
        
        if s[i][j]=="
            r[i][j] = 0
        elif j==(w-1):
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1
        
        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






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

print(M)

Solution (Python):
def main(): 
  import numpy as np 
  h,w=map(int,input().split())
  grid=np.array([list(input()) for i in range(h)])
  grid=np.where(grid=='.',1,0)
    
  left=np.zeros((h,w),dtype=np.int64)
  right=np.zeros((h,w),dtype=np.int64)
  up=np.zeros((h,w),dtype=np.int64)
  down=np.zeros((h,w),dtype=np.int64)
  
  for i in range(w):
    left[:,i]=(left[:,i-1]+1)*grid[:,i]
    right[:,-i-1]=(right[:,-i]+1)*grid[:,-i-1]
  for i in range(h):
    up[i]=(up[i-1]+1)*grid[i]
    down[-i-1]=(down[-i]+1)*grid[-i-1]
  
  print(np.max(left+right+up+down)-3)
  
if __name__=='__main__':
  main()

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

left=[[0]*w for _ in range(h)]
for i in range(h):
  cnt=0
  for j in range(w):
    if grid[i][j]=='.':
      cnt+=1
      left[i][j]=cnt
    else:
      cnt=0
      left[i][j]=cnt
      
right=[[0]*w for _ in range(h)]
for i in range(h):
  cnt=0
  for j in range(w):
    if grid[i][w-j-1]=='.':
      cnt+=1
      right[i][j]=cnt
    else:
      cnt=0
      right[i][j]=cnt

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

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

ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]=='.':
      tmp=left[i][j]+right[i][w-j-1]+up[i][j]+down[h-i-1][j]-3
      if tmp>ans:
        ans=tmp
    else:
      continue
print(ans)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
H,W=map(int,input().split())
S=[input() for i in range(H)]
y=[[0]*W for i in range(H)]
t=[[0]*W for i in range(H)]
for i,s in enumerate(S):
    n=0
    c=0
    for j in range(W):
        if s[j]==".":
            c+=1
        else:
            for k in range(n,j):
                y[i][k]=c
            c=0
            n=j+1
    for k in range(n,W):
        y[i][k]=c
for i in range(W):
    n=0
    c=0
    for j in range(H):
        if S[j][i]==".":
            c+=1
        else:
            for k in range(n,j):
                t[k][i]=c
            c=0
            n=j+1
    for k in range(n,H):
        t[k][i]=c
a=0
for i in range(H):
    for j in range(W):
        if a<y[i][j]+t[i][j]:
            a=y[i][j]+t[i][j]
print(a-1)

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

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(W):
    if S[0][i] == ".":
        U[0][i] = 1
    if S[H-1][i] == ".":
        D[H-1][i] = 1

for i in range(H):
    if S[i][0] == ".":
        L[i][0] = 1
    if S[i][W-1] == ".":
        R[i][W-1] = 1
     
for i in range(1,H):
    for j in range(W):
        if S[i][j] == "
            continue
        U[i][j] = U[i-1][j] + 1
for i in range(H-1)[::-1]:
    for j in range(W):
        if S[i][j] == "
            continue
        D[i][j] = D[i+1][j] + 1
for i in range(H):
    for j in range(1,W):
        if S[i][j] == "
            continue
        L[i][j] = L[i][j-1] + 1
for i in range(H):
    for j in range(W-1)[::-1]:
        if S[i][j] == "
            continue
        R[i][j] = R[i][j+1] + 1
        
ans = 0

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

Solution (Python):
import numpy as np

h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

s=np.array(s)
s=np.where(s=='.',1,0)

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

for i in range(w):
 L[:,i]=(L[:,i-1]+1)*s[:,i]
 R[:,-i-1]=(R[:,-i]+1)*s[:,-i-1]
for i in range(h):
 U[i]=(U[i-1]+1)*s[i]
 D[-i-1]=(D[-i]+1)*s[-i-1]

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

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

dw = [[0]*W for _ in range(H)]
dh = [[0]*W for _ in range(H)]
maze = [[0]*W for _ in range(H)]

for h in range(H):
    s = input()
    c = 0
    for w, ss in enumerate(s):
        maze[h][w] = ss
        if ss == ".":
            c += 1
            dw[h][w] = c
        else:
            c = 0

for w in range(W):
    c = 0
    for h in range(H):
        ss = maze[h][w]
        if ss == ".":
            c += 1
            dh[h][w] = c
        else:
            c = 0

for h in range(H):
    m = 0
    for w in range(W)[::-1]:
        if dw[h][w] == 0:
            m = 0
        else:
            m = max(m, dw[h][w])
            dw[h][w] = m

for w in range(W):
    m = 0
    for h in range(H)[::-1]:
        if dh[h][w] == 0:
            m = 0
        else:
            m = max(m, dh[h][w])
            dh[h][w] = m

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, dh[h][w]+dw[h][w]-1)

print(ans)

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


Left = [[0] * W for _ in range(H)]
for h in range(H):
    cnt = 0
    for w in range(W):
        if field[h][w] == '
            cnt = 0
        else:
            cnt += 1
        Left[h][w] = cnt


Right = [[0] * W for _ in range(H)]
for h in range(H):
    cnt = 0
    for w in range(W-1, -1, -1):
        if field[h][w] == '
            cnt = 0
        else:
            cnt += 1
        Right[h][w] = cnt


Up = [[0] * W for _ in range(H)]
for w in range(W):
    cnt = 0
    for h in range(H):
        if field[h][w] == '
            cnt = 0
        else:
            cnt += 1
        Up[h][w] = cnt


Down = [[0] * W for _ in range(H)]
for w in range(W):
    cnt = 0
    for h in range(H-1, -1, -1):
        if field[h][w] == '
            cnt = 0
        else:
            cnt += 1
        Down[h][w] = cnt


ans = -1
for h in range(H):
    for w in range(W):
        ans = max(ans, Left[h][w] + Right[h][w] + Up[h][w] + Down[h][w] - 3)
print(ans)