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())
grid = [['
for i in range(h):
  grid.append(['
grid.append(['

ud = [[0 for j in range(w+2)] for i in range(h+2)]
lr = [[0 for j in range(w+2)] for i in range(h+2)]

for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '

    if ud[i-1][j] > 0:
      ud[i][j] = ud[i-1][j]
    else:
      cnt = 0
      d = i
      while grid[d][j] != '
        cnt += 1
        d += 1
      ud[i][j] = cnt

    if lr[i][j-1] > 0:
      lr[i][j] = lr[i][j-1]
    else:
      cnt = 0
      r = j
      while grid[i][r] != '
        cnt += 1
        r += 1
      lr[i][j] = cnt

ans = 0
for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '
    cnt = ud[i][j] + lr[i][j] - 1
    ans = max(ans, cnt)
    
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=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(H):
    D[-i-1] = (D[-i]+1)*S[-i-1]
    U[i] = (U[i-1]+1)*S[i]
    
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(L+R+D+U)-3)

Solution (Python):
import numpy as np


H, W = map(int, input().split())
S = np.ones((H, W), dtype=np.bool)
for i in range(H):
    S[i] = [s == "." for s in input()]

up = np.zeros((H, W), dtype=np.int16)
down = np.zeros((H, W), dtype=np.int16)
left = np.zeros((H, W), dtype=np.int16)
right = np.zeros((H, W), dtype=np.int16)


up[0, :] = S[0, :]
for h in range(1, H):
    up[h, :] = up[h - 1, :] + 1
    up[h, :] *= S[h, :]


down[H - 1, :] = S[H - 1, :]
for h in reversed(range(0, H - 1)):
    down[h, :] = down[h + 1, :] + 1
    down[h, :] *= S[h, :]


left[:, 0] = S[:, 0]
for w in range(1, W):
    left[:, w] = left[:, w - 1] + 1
    left[:, w] *= S[:, w]


right[:, W - 1] = S[:, W - 1]
for w in reversed(range(0, W - 1)):
    right[:, w] = right[:, w + 1] + 1
    right[:, w] *= S[:, w]

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

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

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]

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

    _h = H-1-h
    _w = W-1-w
    
    if _h+1 <= H-1:
      if S[_h+1][_w] == "
        down[_h][_w] = 0
      else:
        down[_h][_w] = down[_h+1][_w] + 1
    
    if _w+1 <= W-1:
      if S[_h][_w+1] == "
        right[_h][_w] = 0
      else:
        right[_h][_w] = right[_h][_w+1] + 1

ans = 0
for h in range(H):
  for w in range(W):
    if S[h][w] == "
      continue
    masu = 1
    masu += up[h][w]
    masu += down[h][w]
    masu += left[h][w]
    masu += right[h][w]
    if masu > ans:
      ans = masu

print(ans)

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

up = [[0 for w in range(W)] for h in range(H)]
down = [[0 for w in range(W)] for h in range(H)]
left = [[0 for w in range(W)] for h in range(H)]
right = [[0 for w in range(W)] for h in range(H)]


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


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


ans = 0
for h in range(H):
    for w in range(W):
        masu = -3
        masu += up[h][w]
        masu += down[h][w]
        masu += left[h][w]
        masu += right[h][w]
        if masu > ans:
            ans = masu

print(ans)

Solution (Python):
def resolve():
    h, w = map(int, input().split())
    s = [list(input()) for i in range(h)]
    L= [[0 for i in range(w)] for j in range(h)]
    M= [[0 for i in range(w)] for j in range(h)]
    bom=0
    a=[]
    ans=0
    for  i in range(h):
        for j in range(w):
            if s[i][j]==".":
                bom += 1
                a.append(j)
            else:
                for k in a:
                    L[i][k]=bom
                bom=0
                a=[]
        for k in a:
            L[i][k] = bom
        bom=0
        a=[]
    for j in range(w):
        for i in range(h):
            if s[i][j]==".":
                bom += 1
                a.append(i)
            else:
                for k in a:
                    M[k][j]=bom
                bom=0
                a=[]
        for k in a:
            M[k][j] = bom
        bom=0
        a=[]

    for i in range(h):
        for j in range(w):
            ans=max(ans,L[i][j]+M[i][j]-1)
    print(ans)
resolve()

Solution (Python):
h, w = map(int, input().split())
t = ["
s = [["
s.append(t)
s.insert(0, t)
dp_n = [[0] * (w + 2) for _ in range(h + 2)]
dp_s = [[0] * (w + 2) for _ in range(h + 2)]
dp_e = [[0] * (w + 2) for _ in range(h + 2)]
dp_w = [[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] == ".":
            dp_n[i][j] += dp_n[i - 1][j] + 1
        if s[h + 1 - i][j] == ".":
            dp_s[h + 1 - i][j] += dp_s[h + 2 - i][j] + 1
for j in range(1, w + 1):
    for i in range(1, h + 1):
        if s[i][j] == ".":
            dp_w[i][j] += dp_w[i][j - 1] + 1
        if s[i][w + 1 - j] == ".":
            dp_e[i][w + 1 - j] += dp_e[i][w + 2 - j] + 1
ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        c = dp_n[i][j] + dp_s[i][j] + dp_e[i][j] + dp_w[i][j] - 3
        if c > ans:
            ans = c
print(ans)

Solution (Python):
h,w = map(int,input().split())
field = [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)] 

for i in range(h):
    for j in range(w):
        if field[i][j] == "
            l[i][j] = 0
        
        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)[::-1]:
        if field[i][j] == "
            r[i][j] = 0
        
        elif 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):
        if field[i][j] == "
            d[i][j] = 0
        
        elif i == 0:
            d[i][j] = 1
        
        else:
            d[i][j] = d[i-1][j] + 1
    
for j in range(w):
    for i in range(h)[::-1]:
        if field[i][j] == "
            u[i][j] = 0
        
        elif i == h-1:
            u[i][j] = 1
        
        else:
            u[i][j] = u[i+1][j] + 1
        
max_light = 0       
for i in range(h):
    for j in range(w):
        n_light = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        
        max_light = max(max_light,n_light)

print(max_light)

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

H, W = map(int, input().split())
S = [list(input()[:-1]) 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):
    if S[i][0]=='.':
        L[i][0] = 1

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

for i in range(H):
    if S[i][W-1]=='.':
        R[i][W-1] = 1

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

for i in range(W):
    if S[0][i]=='.':
        U[0][i] = 1

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

for i in range(W):
    if S[H-1][i]=='.':
        D[H-1][i] = 1

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

ans = 0

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

print(ans)

Solution (Python):
h,w = map(int,input().split())
s = [[(l == '.')*1 for l in list(input())] for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if i == 0:
      U[i][j] = s[i][j]
      D[h-i-1][j] = s[h-i-1][j]
    else:
      U[i][j] = (U[i-1][j]+1)*s[i][j]
      D[h-i-1][j] = (D[h-i][j]+1)*s[h-i-1][j]
    if j == 0:
      L[i][j] = s[i][j]
      R[i][w-j-1] = s[i][w-j-1]
    else:
      L[i][j] = (L[i][j-1]+1)*s[i][j]
      R[i][w-j-1] = (R[i][w-j]+1)*s[i][w-j-1]
for i in range(h):
  for j in range(w):
    m = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
    if ans < m:
      ans = m
print(ans)

Solution (Python):


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    

    
    

    H,W = map(int, input().split())
    S = [list(input().rstrip()) for _ in range(H)]
    tate = [[0]*W for _ in range(H)]
    yoko = [[0]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '
                yoko[i][j] = 0
            else:
                if j==0:
                    yoko[i][j] = 1
                else:
                    yoko[i][j] = yoko[i][j-1] + 1
        for j in range(W-1, 0, -1):
            if yoko[i][j-1]==0 or yoko[i][j]==0:
                continue
            yoko[i][j-1] = yoko[i][j]
    
    for i in range(W):
        for j in range(H):
            if S[j][i] == '
                tate[j][i] = 0
            else:
                if j==0:
                    tate[j][i] = 1
                else:
                    tate[j][i] = tate[j-1][i] + 1
        for j in range(H-1, 0, -1):
            if tate[j-1][i]==0 or tate[j][i]==0:
                continue
            tate[j-1][i] = tate[j][i]
    res = 0
    for i in range(H):
        for j in range(W):
            res = max(res, tate[i][j]+yoko[i][j])
    print(res-1)


if __name__ == '__main__':
    main()

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

h,w=map(int,input().split())
G=[]
for i in range(h):
    S=input()
    g=[]
    cnt=0
    for s in S:
        if s==".":
            cnt+=1
        else:
            if cnt==0:
                g.append(0)
            else:
                for j in range(cnt):
                    g.append(cnt)
                g.append(0)
                cnt=0
    if cnt>0:
        for j in range(cnt):
            g.append(cnt)
    G.append(g)

ans=0
for i in range(w):
    cnt=0 
    m=0 
    for j in range(h):
        g=G[j][i] 
        if g==0:
            if cnt!=0:
                ans=max(m+cnt-1,ans)
                cnt=0
                m=0
        else:
            cnt+=1
            m=max(g,m)
    if cnt>0:
        ans=max(m+cnt-1,ans)

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

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

        if S[h][W-w-1] == "
            R[h][W-w-1] = 0
        elif W-w-1 == W-1:
            R[h][W-w-1] = 1
        else:
            R[h][W-w-1] = R[h][W-w]+1

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

        if S[H-h-1][w] == "
            D[H-h-1][w] = 0
        elif H-h-1 == H-1:
            D[H-h-1][w] = 1
        else:
            D[H-h-1][w] = D[H-h][w]+1

light_num = [[0]*W for _ in range(H)]
for h in range(H):
    for w in range(W):
        light_num[h][w] = L[h][w]+R[h][w]+U[h][w]+D[h][w]

print(max([max(l) for l in light_num])-3)

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

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

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

print(max(max(i) for i in cnt))

Solution (Python):
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
u=[[0]*w for i in range(h)]
d=[[0]*w for i in range(h)]
l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    if s[i][j]=='
      d[i][j]=0
      l[i][j]=0
    else:
      if i!=0:
        d[i][j]+=d[i-1][j]+1
      else:
        d[i][j]=1
      if j!=0:
        l[i][j]+=l[i][j-1]+1
      else:
        l[i][j]=1
for i in range(h)[::-1]:
  for j in range(w)[::-1]:
    if s[i][j]=='
      r[i][j]=0
      u[i][j]=0
    else:
      if i!=h-1:
        u[i][j]+=u[i+1][j]+1
      else:
        u[i][j]=1
      if j!=w-1:
        r[i][j]+=r[i][j+1]+1
      else:
        r[i][j]=1
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      ans=max(ans,u[i][j]+d[i][j]+l[i][j]+r[i][j]-3)
print(ans)

Solution (Python):
h,w = map(int,input().split())
list1 = []
list2 = []
 
for i in range(w):
  list2.append([])
 
for i in range(h):
  s = input()
  list1.append(s)
  for j in range(w):
    list2[j].append(s[j])
 
list3 = []
for i in range(h):
  list3.append([])
  
list4 = []
for i in range(w):
  list4.append([])
 
for i in range(h):
  tmp_list = list1[i].split('
  for tmp in tmp_list:
    leng = len(tmp)
    list3[i].extend([leng]*leng)
    list3[i].append(0)
    
for i in range(w):
  tmp_list = (''.join(list2[i])).split('
  for tmp in tmp_list:
    leng = len(tmp)
    list4[i].extend([leng]*leng)
    list4[i].append(0)
    
max_num = -1
for i in range(w):
  for j in range(h):
    list3[j][i] += list4[i][j]-1
    max_num = max(max_num, list3[j][i])
    
print(max_num)

Solution (Python):
h, w = map(int,input().split())
s = []
for i in range(h):
  s += [input()]
sh = [[0 for _ in range(h)] for _ in range(w)]
sw = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
  c = 0
  for j in range(w):
    if s[i][j]=='.':
      c += 1
    else:
      sw[i][(j-c):j] = [c]*c
      c = 0
  if c>0:
    sw[i][(w-c):w] = [c]*c
for j in range(w):
  c = 0
  for i in range(h):
    if s[i][j]=='.':
      c += 1
    else:
      sh[j][(i-c):i] = [c]*c
      c = 0
  if c>0:
    sh[j][(h-c):h] = [c]*c
print(max([sw[i][j]+sh[j][i] for i in range(h) for j in range(w)])-1)

Solution (Python):

import numpy as np
h,w=map(int,input().split())
s=np.array([list(input()) for i 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 i in range(w):
 l[:,i]=(l[:,i-1]+1)*s[:,i]
 r[:,-i-1]=(r[:,-i]+1)*s[:,-i-1]
print(np.max(u+d+l+r-3))

Solution (Python):
H,W = map(int,input().split())
S = [input() for _ in range(H)]
left = [[0]*W for _ in range(H)]
right = [[0]*W for _ in range(H)]
up = [[0]*W for _ in range(H)]
down = [[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if(S[i][j]=="."):
            if(j == 0):
                left[i][j] = 1
            else:
                left[i][j]=left[i][j-1]+1
for i in range(H):
    for j in range(W-1,-1,-1):                
        if(S[i][j]=="."):
            if(j == W-1):
                right[i][j]=1
            else:
                right[i][j]=right[i][j+1]+1
for i in range(H):
    for j in range(W):                   
        if(S[i][j]=="."):
            if(i == 0):
                up[i][j] = 1
            else:
                up[i][j]=up[i-1][j]+1
for i in range(H-1,-1,-1):
    for j in range(W):     
        if(S[i][j]=="."):
            if(i == H-1):
                down[i][j]=1
            else:
                down[i][j]=down[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] = left[i][j]+right[i][j]+up[i][j]+down[i][j]-3
    ans = max(ans,max(X[i]))
print(ans)

Solution (Python):
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))

from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

h, w = I()
g = []
for i in range(h):
    g.append(input())

rows = [[0] * (w + 10) for i in range(h + 10)]
cols = [[0] * (w + 10) for i in range(h + 10)]

ans = 0
for i in range(h):
    for j in range(w):
        rows[i][j] = (g[i][j] == '.')
        if j and g[i][j] == '.':
            rows[i][j] += rows[i][j - 1]
        cols[i][j] = (g[i][j] == '.')
        if i and g[i][j] == '.':
            cols[i][j] += cols[i - 1][j]
    for j in range(w - 1, -1, -1):
        if rows[i][j + 1] != 0 and rows[i][j]:
            rows[i][j] = rows[i][j + 1]

for i in range(h - 1, -1, -1):
    for j in range(w):
        if cols[i + 1][j] != 0 and cols[i][j]:
            cols[i][j] = cols[i + 1][j]
        ans = max(ans, rows[i][j] + cols[i][j] - 1)
print(ans)

Solution (Python):
import numpy
H,W = map(int,input().split())
S = numpy.array([[1 if i == '.' else 0 for i in input().strip()] for _ in range(H)])
S = numpy.array([S, S])

for w in range(1, W):
    S[0, :, w] += S[0, :, w] * S[0, :, w - 1]
for w in range(W - 2, -1, -1):
    S[0, :, w] = (S[0, :, w] != 0) * numpy.maximum(S[0, :, w], S[0, :, w + 1])
for h in range(1, H):
    S[1, h] += S[1, h] * S[1, h - 1]
for h in range(H - 2, -1, -1):
    S[1, h] = (S[1, h] != 0) * numpy.maximum(S[1, h], S[1, h + 1])

S = S[0]+S[1]
print(numpy.max(S)-1)

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 )

left=np.zeros((H, W))
right=np.zeros((H, W))
top=np.zeros((H, W))
bottom=np.zeros((H, W))

for i in range(W):
  if i==0:
    left[:,i]=S[:,i]
    right[:,-i-1]=S[:,-i-1]
  else:
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
    
for i in range(H):
  if i==0:
    top[i,:]=S[i,:]
    bottom[-1-i,:]=S[-i-1,:]
  else:
    top[i,:]=(top[i-1,:]+1)*S[i,:]
    bottom[-1-i,:]=(bottom[-i,:]+1)*S[-i-1,:]
    
ans=left+top+right+bottom-3
    

print(int(ans.max()))

Solution (Python):
from sys import stdin
H,W = [int(x) for x in stdin.readline().rstrip().split()]
grid = []
for i in range(H):
    grid.append(list(input()))


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

for i in range(H):
    cnt = 0
    for j in range(W):
        if grid[i][j] == ".":
            cnt += 1
            yoko[i][j] = cnt
        else:
            cnt = 0
    cnt = 0
    for j in range(W-1,-1,-1):
        if grid[i][j] == ".":
            cnt = max(cnt,yoko[i][j])
            yoko[i][j] = cnt
        else:
            cnt = 0

            
            
for j in range(W):
    cnt = 0
    for i in range(H):
        if grid[i][j] == ".":
            cnt += 1
            tate[i][j] = cnt
        else:
            cnt = 0
    cnt = 0
    for i in range(H-1,-1,-1):
        if grid[i][j] == ".":
            cnt = max(cnt,tate[i][j])
            tate[i][j] = cnt
        else:
            cnt = 0

ans = 0

for i in range(H):
    for j in range(W):
        tmp = tate[i][j] + yoko[i][j] - 1
        ans = max(ans,tmp)

print(ans)

Solution (Python):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
u1 = [[0 for _ in range(w)] for _ in range(h)]
u2 = [[0 for _ in range(w)] for _ in range(h)]
d1 = {}
d2 = {}

idx = 1
cnt = 0
for i in range(h):
    flag = False
    for j in range(w):
        if s[i][j] == ".":
            flag = True
            u1[i][j] = idx
            cnt += 1
        elif flag:
            d1[idx] = cnt
            cnt = 0
            idx += 1
            flag = False  
    if flag:
        d1[idx] = cnt
        cnt = 0
        idx += 1

idx = 1
cnt = 0
for j in range(w):
    flag = False
    for i in range(h):
        if s[i][j] == ".":
            flag = True
            u2[i][j] = idx
            cnt += 1
        elif flag:
            d2[idx] = cnt
            cnt = 0
            idx += 1
            flag = False  
    if flag:
        d2[idx] = cnt
        cnt = 0
        idx += 1

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            ans = max(ans, d1[u1[i][j]]+d2[u2[i][j]]-1)
print(ans)

Solution (Python):

import sys


def solve(H: int, W: int, S: "List[str]"):
    def isBlock(x, y):
        return S[y][x] == "
    cacheW = [[0 for i in range(W)] for j in range(H)]
    cacheH = [[0 for i in range(W)] for j in range(H)]
    for i in range(H):
        count = 0
        begin = 0
        for j in range(W):
            if isBlock(j, i):
                for k in range(begin, j):
                    cacheW[i][k] = count
                begin = j+1
                count = 0
            else:
                count += 1
        if begin != W:
            for k in range(begin, W):
                cacheW[i][k] = count
    for i2 in range(W):
        count2 = 0
        begin2 = 0
        for j2 in range(H):
            if isBlock(i2, j2):
                for k2 in range(begin2, j2):
                    cacheH[k2][i2] = count2
                
                begin2 = j2+1
                count2 = 0
            else:
                count2 += 1
        if begin2 != H:
            for k in range(begin2,H):
                cacheH[k][i2] = count2
    m = 0
    
    
    for i in range(W):
        for j in range(H):
            c = cacheW[j][i] + cacheH[j][i]-1
            m = max(m, c)
            
    print(m)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    S = [next(tokens) for _ in range(H)]  
    solve(H, W, S)


if __name__ == '__main__':
    main()

Solution (Python):
h,w=map(int,input().split())
ans=[[-3]*w for _ in range(h)]
s=[input() for _ in range(h)]
for i in range(h):
    tmp=0
    for j in range(w):
        if s[i][j]=="
        else: tmp+=1
        ans[i][j]+=tmp
    tmp=0
    for j in range(w-1,-1,-1):
        if s[i][j]=="
        else: tmp+=1
        ans[i][j]+=tmp

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

print(max( max(ans[i]) for i in range(h) ))

Solution (Python):

h,w = list(map(int,input().split()))
ss = ["
for i in range(h):
    ss.append("
ss.append("

yoko_list = []
tate_list = []
for s in ss:
    w_l_len_list = []
    w_l_len = 0
    for i,v in enumerate(s):
        if v == "
            w_l_len_list+=[w_l_len] * w_l_len
            w_l_len_list+=[0]
            w_l_len = 0
        else:
            w_l_len+=1
    yoko_list.append(w_l_len_list)
for s in zip(*ss):
    w_l_len_list = []
    w_l_len = 0
    for i,v in enumerate(s):
        if v == "
            w_l_len_list+=[w_l_len] * w_l_len
            w_l_len_list+=[0]
            w_l_len = 0
        else:
            w_l_len+=1
    tate_list.append(w_l_len_list)
ret = 0
for i in range(h+1):
    for j in range(w+1):
        ret = max(ret,tate_list[j][i]+yoko_list[i][j]-1)
print(ret)

Solution (Python):
h,w = map(int,input().split())
s = [list(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 in range(h):
    index = []
    l = []
    flag = True
    for j in range(w):
        if s[i][j] == "
            x[i][j] = -1
            flag = False
            if len(l) != 0:
                index.append(l)
                l = []
        else:
            flag = True
        if flag:
            l.append(j)
        if j == w - 1:
          if len(l) != 0:
              index.append(l)
    for j in index:
        for m in j:
            x[i][m] = len(j)


for j in range(w):
    index = []
    l = []
    flag = True
    for i in range(h):
        if s[i][j] == "
            y[i][j] = -1
            flag = False
            if len(l) != 0:
                index.append(l)
                l = []
        else:
            flag = True
        if flag:
            l.append(i)
        if i == h - 1:
          if len(l) != 0:
              index.append(l)
    for i in index:
        for m in i:
            y[m][j] = len(i)

ans=0

for i in range(h):
    for j in range(w):
        ans = max(ans,x[i][j] + y[i][j] - 1)

print(ans)

Solution (Python):
import numpy as np
import sys
buf = sys.stdin.buffer

h,w = map(int,buf.readline().split())
grid = np.array([list(input()) for _ in range(h)])
grid = np.where(grid == ".", 1, 0)


L,R,U,D = [np.zeros((h,w)) for _ in range(4)]
for i in range(w):
  L[:,i] = (L[:,i-1] + 1) * grid[:,i]
  R[:,-i-1] = (R[:,-i] + 1) * grid[:,-i-1]
  
for i in range(h):
  D[i,:] = (D[i-1,:] + 1) * grid[i,:]
  U[-i-1,:] = (U[-i,:] + 1) * grid[-i-1,:]

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

Solution (Python):

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

for i in range(H):
  S[i] = input()
  
for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      if counth[i][j]==0:
        b=False
        for k in range(j,W):
          if S[i][k]=='
            b = True
            break
        if b==False:
          k+=1
        
        for l in range(j,k):
          
          counth[i][l]=k-j
      if countw[i][j]==0:
        b=False
        for k in range(i,H):
          if S[k][j]=='
            b=True
            break
        if b==False:
          k+=1
        
        for l in range(i,k):
          
          countw[l][j]=k-i
      

maxim = 0
for i in range(H):
  for j in range(W):
    maxim = int(max(maxim,counth[i][j]+countw[i][j]-1))
print(maxim)

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

counter = [[[0, 0] for j in range(w)] for i in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if grid[i][j] == "
      continue
    if i == 0 or (i != 0 and grid[i-1][j] == "
      k = 0
      while i+k < h and grid[i+k][j] == ".":
        k += 1
      counter[i][j][0] = k-1
    else:
      counter[i][j][0] = counter[i-1][j][0]
    if j == 0 or (j != 0 and grid[i][j-1] == "
      k = 0
      while j+k < w and grid[i][j+k] == ".":
        k += 1
      counter[i][j][1] = k-1
    else:
      counter[i][j][1] = counter[i][j-1][1]
    if ans < counter[i][j][0]+counter[i][j][1]:
      ans = counter[i][j][0]+counter[i][j][1]
print(ans+1)

Solution (Python):
import sys

readline = sys.stdin.readline
h, w = map(int, readline().split())
grid = [readline() for _ in range(h)]
light = [[0] * w for _ in range(h)]


for i in range(h):
    start = -1
    for j in range(w):
        if grid[i][j] == '.' and start == -1:
            start = j
        elif grid[i][j] == '
            length = j - start
            light[i][start:j] = [length] * length
            start = -1
    if start != -1:
        length = w - start
        light[i][start:w] = [length] * length

for i in range(w):
    start = -1
    for j in range(h):
        if grid[j][i] == '.' and start == -1:
            start = j
        elif grid[j][i] == '
            length = j - start
            for k in range(start, j):
                light[k][i] += length
            start = -1
    if start != -1:
        length = h - start
        for k in range(start, h):
            light[k][i] += length
ans = max(max(row) for row in light)
print(ans-1)

Solution (Python):
import sys
import numpy as np
sys.setrecursionlimit(10**9)
H, W = map(int, input().split())
S = [list('
for _ in range(H):
    S.append(list('
S.append(list('
S = np.array(S)


north = np.zeros_like(S, dtype='int')
for w in range(1, W + 1):
    north[:, w] = north[:, w - 1] + 1
    north[:, w][S[:, w - 1] == '
    north[:, w][S[:, w] == '

south = np.zeros_like(S, dtype='int')
for w in range(W, 0, -1):
    south[:, w] = south[:, w + 1] + 1
    south[:, w][S[:, w + 1] == '
    south[:, w][S[:, w] == '

east = np.zeros_like(S, dtype='int')
for h in range(1, H + 1):
    east[h, :] = east[h - 1, :] + 1
    east[h, :][S[h - 1] == '
    east[h, :][S[h, :] == '

west = np.zeros_like(S, dtype='int')
for h in range(H, 0, -1):
    west[h, :] = west[h + 1, :] + 1
    west[h, :][S[h + 1] == '
    west[h, :][S[h, :] == '


ans = north + south + east + west
print(ans.max() + 1)