Problem:
 Score : 400 points    Problem Statement There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.  Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.  Snuke wants to maximize the number of squares lighted by the lamp.  You are given H strings S_i ( 1 \leq i \leq H ), each of length W . If the j -th character ( 1 \leq j \leq W ) of S_i is # , there is an obstacle on the square at the i -th row from the top and the j -th column from the left; if that character is . , there is no obstacle on that square.  Find the maximum possible number of squares lighted by the lamp.      Constraints  1 \leq H \leq 2,000  1 \leq W \leq 2,000  S_i is a string of length W consisting of # and . .  . occurs at least once in one of the strings S_i ( 1 \leq i \leq H ).         Input Input is given from Standard Input in the following format:  H  W  S_1  :  S_H       Output Print the maximum possible number of squares lighted by the lamp.        Sample Input 1 4 6
#..#..
.....#
....#.
#.#...      Sample Output 1 8  If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.       Sample Input 2 8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#      Sample Output 2 13

Solution (Python):
import numpy as np
h, w = map(int, input().split())
arr = np.array([list(input()) for _ in range(h)]) == "."

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

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

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

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

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

s=[['
for i in range(h):
    s.append(['
s.append([['

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
            u[i][j]=u[i-1][j]+1
        if s[i][w+1-j]=='.':
            r[i][w+1-j]=r[i][w+2-j]+1
        if s[h+1-i][j]=='.':
            d[h+1-i][j]=d[h+2-i][j]+1

ans=0
for i in range(1, h+1):  
    for j in range(1, w+1):  
        tmp_ans=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
        ans=max(ans, tmp_ans)
print(ans)

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

row_list = [[0] * w for _ in range(h)]
for i in range(h):
    r = 0
    cnt = 0
    for l in range(w):
        if s[i][l] == '
            row_list[i][l] = 0
            r += 1
            cnt = 0
            continue

        while r < w and s[i][r] == '.':
            cnt += 1
            r += 1

        row_list[i][l] = cnt

col_list = [[0] * h for _ in range(w)]
for i in range(w):
    r = 0
    cnt = 0
    for l in range(h):
        if s[l][i] == '
            col_list[i][l] = 0
            r += 1
            cnt = 0
            continue

        while r < h and s[r][i] == '.':
            cnt += 1
            r += 1

        col_list[i][l] = cnt

res = 0
for i in range(h):
    for j in range(w):
        res = max(res, row_list[i][j] + col_list[j][i] - 1)

print(res)

Solution (Python):
import numpy as np
def main():
    printl = lambda l: [print(x) for x in l]
    H, W = list(map(int, input().split()))
    A = np.array([[1 if i == '.' else 0 for i in input()] for _ in range(H)])
    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)
    L[:, 0] = A[:, 0]
    for w in range(1, W):
        L[:, w] = (L[:, w - 1] + 1) * A[:, w]
    R[:, W - 1] = A[:, W - 1]
    for w in range(W - 2, -1, -1):
        R[:, w] = (R[:, w + 1] + 1) * A[:, w]
    U[0, :] = A[0, :]
    for h in range(1, H):
        U[h, :] = (U[h - 1, :] + 1) * A[h, :]
    D[H - 1, :] = A[H - 1, :]
    for h in range(H - 2, -1, -1):
        D[h, :] = (D[h + 1, :] + 1) * A[h, :]
    print(np.max(L + R + U + D - 3))

if __name__ == '__main__':
    main()

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

for i in range(H):
  G.append(list(input()))
  
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):
    k=-i-1
    l=-j-1
    if G[i][j]=="
      L[i][j]=0
      U[i][j]=0
    else:
      if j==0:
        L[i][j]=1
        U[i][j]=U[i-1][j]+1
      elif i==0:
        L[i][j]=L[i][j-1]+1
        U[i][j]=1
      else:
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1
        
    if G[k][l]=="
      R[k][l]=0
      D[k][l]=0
    else:
      if k==-1:
        R[k][l]=1
        D[k][l]=D[k+1][l]+1
      elif i==0:
        R[k][l]=R[k][l+1]+1
        D[k][l]=1
      else:
        R[k][l]=R[k][l+1]+1
        D[k][l]=D[k+1][l]+1
ans=0
for i in range(H):
  for j in range(W):
    
    ans=max(R[i][j]+L[i][j]+U[i][j]+D[i][j]-3,ans)
print(ans)

Solution (Python):
def m():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    Gx = [[-1 for _ in range(W)] for _ in range(H)]
    Gy = [[-1 for _ in range(W)] for _ in range(H)]

    for a in range(H):
        left = 0
        for b in range(W):
            if S[a][b] == '
                left = 0
            else:
                Gx[a][b] = left + 1
                left = Gx[a][b]
    for b in range(W):
        top = 0
        for a in range(H):
            if S[a][b] == '
                top = 0
            else:
                Gy[a][b] = top + 1
                top = Gy[a][b]

    for i in reversed(range(H)):
        right = 0
        for j in reversed(range(W)):
            if Gx[i][j] == -1:
                right = 0
            else:
                Gx[i][j] = max(Gx[i][j], right)
                right = Gx[i][j]

    for j in reversed(range(W)):
        bot = 0
        for i in reversed(range(H)):
            if Gy[i][j] == -1:
                bot = 0
            else:
                Gy[i][j] = max(Gy[i][j], bot)
                bot = Gy[i][j]
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(Gx[i][j] + Gy[i][j], ans)
    return ans - 1


print(m())

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

H,W = map(int,readline().split())
grid = [readline().rstrip() 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):
  cur = 0
  for j in range(W):
    if grid[i][j] == "
      cur = 0
    else:
      cur += 1
    L[i][j] = cur
  cur = 0
  for j in range(W - 1,-1,-1):
    if grid[i][j] == "
      cur = 0
    else:
      cur += 1
    R[i][j] = cur
    
for j in range(W):
  cur = 0
  for i in range(H):
    if grid[i][j] == "
      cur = 0
    else:
      cur += 1
    U[i][j] = cur
  cur = 0
  for i in range(H - 1,-1,-1):
    if grid[i][j] == "
      cur = 0
    else:
      cur += 1
    D[i][j] = cur
    
ans = 0
for i in range(H):
  for j in range(W):
    if ans < L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3:
      ans = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
      
print(ans)

Solution (Python):
[h,w] = [int(i) for i in input().split()]
s = []
tate = [[0] * (h+2) for i in range(w+2)]
yoko = [[0] * (w+2) for i in range(h+2)]
s.append("
for i in range(h):
    tmp = input()
    s.append(tmp.join(["
s.append("


for i in range(1,h+1):
    tmp = 1
    before = 1
    while tmp < w+2:
        if s[i][tmp] == "
            before += 1
            tmp += 1
        else:
            while s[i][tmp] != "
                tmp += 1
                if tmp == w+2:
                    break
            yoko[i][before:tmp] = [tmp-before] * (tmp - before)
            before = tmp

for i in range(1,w+1):
    tmp = 1
    before = 1
    while tmp < h+2:
        if s[tmp][i] == "
            before += 1
            tmp += 1
        else:
            while s[tmp][i] != "
                tmp += 1
                if tmp == h+2:
                    break
            tate[i][before:tmp] = [tmp-before] * (tmp - before)
            before = tmp
ans = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        ans = max(ans,tate[j][i]+yoko[i][j]-1)
print(ans)

Solution (Python):
def main():
    H, W = map(int, input().split())
    g = [str(input()) for _ in range(H)]
    LW = [[0] * W for _ in range(H)]
    LH = [[0] * W for _ in range(H)]
    for h in range(H):
        cnt = 0
        for w in range(W):
            if g[h][w] == '.':
                cnt += 1
            else:
                for i in range(1, cnt+1):
                    LW[h][w-i] = cnt
                LW[h][w] = 0
                cnt = 0
        else:
            for i in range(cnt):
                LW[h][w-i] = cnt
    for w in range(W):
        cnt = 0
        for h in range(H):
            if g[h][w] == '.':
                cnt += 1
            else:
                for i in range(1, cnt+1):
                    LH[h-i][w] = cnt
                LH[h][w] = 0
                cnt = 0
        else:
            for i in range(cnt):
                LH[h-i][w] = cnt
    ans = 0
    for h in range(H):
        for w in range(W):
            if g[h][w] != '
                ans = max(ans, LH[h][w] + LW[h][w] - 1)
    print(ans)
main()

Solution (Python):
import numpy as np
h, w = map(int, input().split())
arr = np.array([list(input()) for _ in range(h)]) == "."

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

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

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

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

Solution (Python):
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


def main():
    H, W = NMI()
    grid = [input() for _ in range(H)]
    L = make_grid(H, W, 0)
    R = make_grid(H, W, 0)
    U = make_grid(H, W, 0)
    D = make_grid(H, W, 0)

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

    
    for h in range(H):
        for w in range(W-1, -1, -1):
            if grid[h][w] == "
                continue
            elif w == W-1:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w+1] + 1

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

    
    for w in range(W):
        for h in range(H-1, -1, -1):
            if grid[h][w] == "
                continue
            elif h == H-1:
                D[h][w] = 1
            else:
                D[h][w] = D[h+1][w] + 1

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


if __name__ == "__main__":
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
H,W = map(int,input().split())
grid = []
for _ in range(H):
  grid.append(list(input()))

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

for i in range(H):
  for j in range(W):
    if j-1 >= 0:
      L[i][j] = L[i][j-1]
    if i-1 >= 0:
      D[i][j] = D[i-1][j]

    if grid[i][j] == ".":
      L[i][j] += 1
      D[i][j] += 1
    else:
      L[i][j] = 0
      D[i][j] = 0

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

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

print(res)

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

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

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] == "." and i - 1 < 0:
            D[i][j] = 1
        elif S[i][j] == "." and i - 1 >= 0:
            D[i][j] = D[i-1][j] + 1
        if S[i][j] == "." and j - 1 < 0:
            L[i][j] = 1
        elif S[i][j] == "." and j - 1 >= 0:
            L[i][j] = L[i][j-1] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        if S[i][j] == "." and i + 1 >= H:
            U[i][j] = 1
        elif S[i][j] == "." and i + 1 < H:
            U[i][j] = U[i+1][j] + 1
        if S[i][j] == "." and j + 1 >= W:
            R[i][j] = 1
        elif S[i][j] == "." and j + 1 < W:
            R[i][j] = R[i][j+1] + 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 sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    H, W = map(int, input().rstrip().split())
    G = []
    for i in range(H):
        s = list(input())
        G.append(s)
    
    cnt = [[0 for j in range(W)] for i in range(H)]

    for i in range(H):
        done = [0] * W
        for j in range(W):
            if G[i][j] == "
                continue
            if done[j]:
                continue
            length = 0
            while j + length < W:
                if G[i][j+length] == "
                    break
                length += 1
            for k in range(length):
                cnt[i][j + k] += length
                done[j + k] = 1

    for j in range(W):
        done = [0] * H
        for i in range(H):
            if G[i][j] == "
                continue
            if done[i]:
                continue
            length = 0
            while i + length < H:
                if G[i+length][j] == "
                    break
                length += 1
            for k in range(length):
                cnt[i + k][j] += length
                done[i + k] = 1
    ans = 0
    for i in range(H):
        ans = max(ans, max(cnt[i]) - 1)
    print(ans)


if __name__ == "__main__":
    main()

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


def light_count(light, H, W, h, w, count, wr=-1, hr=-1):

    if wr != -1:
        for i in range(h * W + wr, h * W + w):
            light[i] += count
    elif hr != -1:
        for i in range(hr * W + w, h * W + w, W):
            light[i] += count


def solve():
    H, W = map(int, input().split())
    S = [[] for _ in range(H)]
    light = [0 for _ in range(H * W)]
    for i in range(H):
        S[i] = list(input())

    for h in range(H):
        count = 0
        wr = -1
        for w in range(W):
            if S[h][w] == '.':
                if wr == -1:
                    wr = w
                count += 1
            elif S[h][w] == '
                if wr != -1:
                    light_count(light, H, W, h, w, count, wr=wr)
                    wr = -1
                    count = 0
        else:
            if wr != -1:
                light_count(light, H, W, h, w + 1, count, wr=wr)
                wr = -1
                count = 0

    for w in range(W):
        count = 0
        hr = -1
        for h in range(H):
            if S[h][w] == '.':
                if hr == -1:
                    hr = h
                count += 1
            elif S[h][w] == '
                if hr != -1:
                    light_count(light, H, W, h, w, count, hr=hr)
                    hr = -1
                    count = 0
        else:
            if hr != -1:
                light_count(light, H, W, h + 1, w, count, hr=hr)
                hr = -1
                count = 0

    print(max(light) - 1)


if __name__ == '__main__':
    solve()

Solution (Python):
import collections
n,m = map(int, raw_input().split(' '))
matrix = [list(raw_input()) for _ in range(n)]
dpleft = [[0 for j in range(m)] for i in range(n)]
dpright = [[0 for j in range(m)] for i in range(n)]
dpup = [[0 for j in range(m)] for i in range(n)]
dpdown = [[0 for j in range(m)] for i in range(n)]

for i in range(n):
	cumul = 0
	for j in range(m):
		if matrix[i][j] == '
			cumul = 0
		else:
			dpleft[i][j] = cumul
			cumul +=1

	cumul = 0
	for j in range(m-1,-1,-1):
		if matrix[i][j] == '
			cumul = 0
		else:
			dpright[i][j] = cumul
			cumul +=1

for j in range(m):
	cumul = 0
	for i in range(n):
		if matrix[i][j] == '
			cumul = 0
		else:
			dpup[i][j] = cumul
			cumul +=1

	cumul = 0
	for i in range(n-1,-1,-1):
		if matrix[i][j] == '
			cumul = 0
		else:
			dpdown[i][j] = cumul
			cumul +=1
r = 0
for i in range(len(matrix)):
	for j in range(len(matrix[0])):
		if matrix[i][j] != '
			r = max(r, 1 + dpleft[i][j] + dpright[i][j] + dpdown[i][j] + dpup[i][j])

print r

Solution (Python):
h,w=map(int,input().split())
s=[input()+'
s.append('
h1=[[0]*(w+1) for i in range(h+1)]
w1=[[0]*(w+1) for i in range(h+1)]
for j in range(h):
  r=0
  for i in range(w+1):
    if s[j][i]=='
      for k in range(i-r,i+1):
        h1[j][k]=r
      r=0
      h1[j][i]=0
    else:
      r+=1
for j in range(w):
  r=0
  for i in range(h+1):
    if s[i][j]=='
      for k in range(i-r,i+1):
        w1[k][j]=r
      r=0
      w1[i][j]=0
    else:
      r+=1
ans=0
for i in range(h):
  for j in range(w):
    ans=max(ans,h1[i][j]+w1[i][j]-1)
print(ans)

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

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

ret_mtx1 = [[0] * w for _ in range(h)]
ret_mtx2 = [[0] * w for _ in range(h)]
ret_mtx3 = [[0] * w for _ in range(h)]
ret_mtx4 = [[0] * w for _ in range(h)]


for i in range(h):
    for j in range(w):
        if mtx[i][j] == '.':
            ret_mtx1[i][j] = 1 if i == 0 else ret_mtx1[i-1][j] + 1
            ret_mtx2[i][j] = 1 if j == 0 else ret_mtx2[i][j-1] + 1
        if mtx[-1-i][-1-j] == '.':
            ret_mtx3[-1-i][-1-j] = 1 if i == 0 else ret_mtx3[-i][-1-j] + 1
            ret_mtx4[-1-i][-1-j] = 1 if j == 0 else ret_mtx4[-1-i][-j] + 1

ret = 0

for i in range(h):
    for j in range(w):
        tmp = ret_mtx1[i][j] + ret_mtx2[i][j] + \
            ret_mtx3[i][j] + ret_mtx4[i][j] - 3
        ret = max(ret, tmp)

print(ret)

Solution (Python):
MOD = 10**9+7
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 j > 0:
      if S[i][j-1] == ".":
        L[i][j] = L[i][j-1]+1
      if S[i][w-j] == ".":
        R[i][w-1-j] = R[i][w-j]+1
    if i > 0:
      if S[i-1][j] == ".":
        U[i][j] = U[i-1][j]+1
      if S[h-i][j] == ".":
        D[h-1-i][j] = D[h-i][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    if S[i][j] == ".":
      temp = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
      ans = max(ans, temp)
print(ans)

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    h, w = map(int, input().split())
    col = [[0, w + 1] for _ in range(h)]
    row = [[0, h + 1] for _ in range(w)]
    for i in range(h):
        s = list(input()[:-1].decode())
        for j in range(w):
            if s[j] == '
                col[i].append(j + 1)
                row[j].append(i + 1)

    cc = [[0] * (w + 2) for _ in range(h)]
    rc = [[0] * (h + 2) for _ in range(w)]

    for i in range(h):
        col[i].sort()
        for j in range(len(col[i]) - 1):
            cc[i][col[i][j] + 1:col[i][j + 1]] = [col[i][j + 1] - col[i][j] - 1] * (col[i][j + 1] - col[i][j] - 1)

    for i in range(w):
        row[i].sort()
        for j in range(len(row[i]) - 1):
            rc[i][row[i][j] + 1:row[i][j + 1]] = [row[i][j + 1] - row[i][j] - 1] * (row[i][j + 1] - row[i][j] - 1)

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

    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
import sys
import itertools

import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

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

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

tile = [0 for i in range(H)]
cnt = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    tile[i] = readline().decode().strip()

for i in range(H):
    done = [False for _ in range(W)]
    for j in range(W):
        if tile[i][j] == '
            continue
        if done[j]:
            continue
        l = 0
        while (j + l < W):
            if tile[i][j + l] == '
                break
            l += 1
        for k in range(l):
            cnt[i][j + k] += l
            done[j + k] = True

for j in range(W):
    done = [False for _ in range(H)]
    for i in range(H):
        if tile[i][j] == '
            continue
        if done[i]:
            continue
        l = 0
        while (i + l < H):
            if tile[i + l][j] == '
                break
            l += 1
        for k in range(l):
            cnt[i + k][j] += l
            done[i + k] = True

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

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

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

rlt = 0
for i in range(H+1):
  for j in range(W+1):
    if mp[i+1][j] == '
      D[i+1][j] = 0
    else:
      D[i+1][j] = D[i][j] + 1
    if mp[H-i][j] == '
      U[H-i][j] = 0
    else:
      U[H-i][j] = U[H-i+1][j] + 1 
    if mp[i][j+1] == '
      R[i][j+1] = 0
    else:
      R[i][j+1] = R[i][j] + 1
    if mp[i][W-j] == '
      L[i][W-j] = 0
    else:
      L[i][W-j] = L[i][W-j+1] + 1 

for i in range(1,H+1):
  for j in range(1,W+1):
    tmp = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
    if tmp > rlt:
      rlt = tmp
      
print(rlt)

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

l_list = [[0 for i in range(w)] for i in range(h)]
r_list = [[0 for i in range(w)] for i in range(h)]
u_list = [[0 for i in range(w)] for i in range(h)]
d_list = [[0 for i in range(w)] for i in range(h)]

for i in range(h):
  for j in range(w):
    if maps[i][j] == "
      l_list[i][j] = 0
    elif j == 0:
      l_list[i][j] = 1
    else:
      l_list[i][j] = l_list[i][j-1] + 1
      
for i in range(h):
  for j in range(w-1,-1,-1):
    if maps[i][j] == "
      r_list[i][j] = 0
    elif j == w-1:
      r_list[i][j] = 1
    else:
      r_list[i][j] = r_list[i][j+1] + 1
      
for i in range(h):
  for j in range(w):
    if maps[i][j] == "
      u_list[i][j] = 0
    elif i == 0:
      u_list[i][j] = 1
    else:
      u_list[i][j] = u_list[i-1][j] + 1  
      
for i in range(h-1,-1,-1):
  for j in range(w):
    if maps[i][j] == "
      d_list[i][j] = 0
    elif i == h-1:
      d_list[i][j] = 1
    else:
      d_list[i][j] = d_list[i+1][j] + 1  

result = []
for i in range(h):
  for j in range(w):
    result.append(l_list[i][j] + u_list[i][j] + d_list[i][j] + r_list[i][j] - 3)
  
print(max(result))

Solution (Python):
h,w=map(int,input().split())
s=[input() for ri in range(h)]
table=[0]*(h*w)
for i in range(h):
    p=0
    pre=0
    for j in range(w):
        if s[i][j]=="
            if p==0:continue
            for x in range(pre,j):
                table[w*i+x]+=p
            p=0
        else:
            if p==0:
                pre=j
            p+=1
    else:
        if p:
            for x in range(pre,w):table[w*i+x]+=p

for j in range(w):
    p=0
    pre=0
    for i in range(h):
        if s[i][j]=="
            if p==0:continue
            for x in range(pre,i):
                table[j+w*x]+=p
            p=0
        else:
            if p==0:pre=i
            p+=1
    else:
        if p:
            for x in range(pre,h):table[j+w*x]+=p
        p=0

print(max(table)-1)

Solution (Python):
from sys import stdin
import numpy as np
def main():
    
    readline=stdin.readline
    h,w=map(int,readline().split())
    grid=[readline().strip() for _ in range(h)]
    grid=[[1 if grid[i][j]=="." else 0 for j in range(w)] for i in range(h)]
    grid=np.array(grid,dtype=np.int64)

    up=np.zeros((h,w),dtype="int64")
    up[0]=grid[0]
    for i in range(1,h):
        up[i]=(up[i-1]+1)*grid[i]
    
    down=np.zeros((h,w),dtype="int64")
    down[-1]=grid[-1]
    for i in range(h-2,-1,-1):
        down[i]=(down[i+1]+1)*grid[i]
    
    left=np.zeros((h,w),dtype="int64")
    left[:,0]=grid[:,0]
    for i in range(1,w):
        left[:,i]=(left[:,i-1]+1)*grid[:,i]
    
    right=np.zeros((h,w),dtype="int64")
    right[:,-1]=grid[:,-1]
    for i in range(w-2,-1,-1):
        right[:,i]=(right[:,i+1]+1)*grid[:,i]

    ans=(up+down+left+right-3).max()
    print(ans)
    
if __name__=="__main__":
    main()

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

M=[]
for i in range(h):
    M.append(input())

L=[]
for j in range(h):
    Lj=[]
    for i in range(w):
        if M[j][i]=="
            Lj.append(0)
        elif i==0:
            Lj.append(1)
        else:
            Lj.append(Lj[i-1]+1)
    L.append(Lj)
R=[]
for j in range(h):
    Rj=[]
    for i in range(w):
        if M[j][w-1-i]=="
            Rj.append(0)
        elif i==0:
            Rj.append(1)
        else:
            Rj.append(Rj[i-1]+1)
    R.append(Rj)   
U=[]
for i in range(w):
    Ui=[]
    for j in range(h):
        if M[j][i]=="
            Ui.append(0)
        elif j==0:
            Ui.append(1)
        else:
            Ui.append(Ui[j-1]+1)
    U.append(Ui)
D=[]
for i in range(w):
    Di=[]
    for j in range(h):
        if M[h-1-j][i]=="
            Di.append(0)
        elif j==0:
            Di.append(1)
        else:
            Di.append(Di[j-1]+1)
    D.append(Di)

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

print(s)

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

teraseru_H = [[0 for i in range(0,W,1)]for j in range(0,H,1)]
teraseru_W = [[0 for i in range(0,W,1)]for j in range(0,H,1)]

left = -1
for i in range(0,H,1):
    left=-1
    for j in range(0,W,1):
        if S[i][j]=="
            if left!=-1:
                for k in range(left,j,1):
                    teraseru_H[i][k] = j-left
                left=-1

        else:
            if left==-1:
                left=j
    if left!=-1:
        for k in range(left,W,1):
            teraseru_H[i][k] = W-left
    left=-1

left = -1
for j in range(0,W,1):
    left=-1
    for i in range(0,H,1):
        if S[i][j]=="
            if left!=-1:
                for k in range(left,i,1):
                    teraseru_W[k][j] = i-left
                left=-1
        else:
            if left==-1:
                left=i
    if left!=-1:
        for k in range(left,H,1):
            teraseru_W[k][j] = H-left
    left=-1

ans = 0

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

Solution (Python):
from collections import defaultdict

def dfs(i,j,dx,dy,kum):
    visited[i][j] = 1
    if grid[i][j]!="
        num[i][j]=max(num[i][j],dfs(i+dx,j+dy,dx,dy,kum+1))
    num[i][j] = max(num[i][j],kum)
    return kum
def main():
    h,w = map(int, input().split())
    grid = []
    for i in range(h):
        s = list(input().rstrip())
        grid.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 grid[i][j]!="
                if j==0:
                    l[i][j]=1
                else:
                    l[i][j]=l[i][j-1]+1
            if grid[i][j]=="
                l[i][j]=0
    for i in range(h):
        for j in range(w-1,-1,-1):
            if grid[i][j]!="
                if j==w-1:
                    r[i][j]=1
                else:
                    r[i][j]=r[i][j+1]+1
            if grid[i][j]=="
                r[i][j]=0
    for i in range(h):
        for j in range(w):
            if grid[i][j]!="
                if i==0:
                    d[i][j]=1
                else:
                    d[i][j]=d[i-1][j]+1
            if grid[i][j]=="
                d[i][j]=0
    for i in range(h-1,-1,-1):
        for j in range(w):
            if grid[i][j]!="
                if i==h-1:
                    u[i][j]=1
                else:
                    u[i][j]=u[i+1][j]+1
            if grid[i][j]=="
                u[i][j]=0
    tmp = 0

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



    print(tmp)

if __name__ == '__main__':
    main()