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())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w)) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

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

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,right,up,down=[np.zeros((h,w),dtype=np.int64) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

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

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

h_cnt = [[0] * w for _ in range(h)]
w_cnt = [[0] * w for _ in range(h)]

for i in range(h):
    dot_cnt, beg_sec = 0, 0
    for j in range(w):
        if s[i][j] == '
            if dot_cnt > 0:
                for k in range(beg_sec, j):
                    w_cnt[i][k] = dot_cnt
                beg_sec = j+1
                dot_cnt = 0
            else:
                w_cnt[i][j] = 0
                beg_sec += 1
        else:
            dot_cnt += 1
    if dot_cnt > 0:
        for k in range(beg_sec, w):
            w_cnt[i][k] = dot_cnt

for i in range(w):
    dot_cnt, beg_sec = 0, 0
    for j in range(h):
        if s[j][i] == '
            if dot_cnt > 0:
                for k in range(beg_sec, j):
                    h_cnt[k][i] = dot_cnt
                beg_sec = j+1
                dot_cnt = 0
            else:
                h_cnt[j][i] = 0
                beg_sec += 1
        else:
            dot_cnt += 1
    if dot_cnt > 0:
        for k in range(beg_sec, h):
            h_cnt[k][i] = dot_cnt

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

Solution (Python):

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

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)

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




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

S = [input() for _ in range(H)]
NUM = [[0] * (W) for _ in range(H)]

for r in range(H):
    cnt = 0
    for c in range(W):
        if S[r][c] == '
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

    cnt = 0
    for c in range(W - 1, -1, -1):
        if S[r][c] == '
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

for c in range(W):
    cnt = 0
    for r in range(H):
        if S[r][c] == '
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

    cnt = 0
    for r in range(H - 1, -1, -1):
        if S[r][c] == '
            cnt = 0
        else:
            cnt += 1
            NUM[r][c] += cnt

ans = 4
for i in range(H):
    t = max(NUM[i])
    ans = max(ans, t)

print(ans-3)

Solution (Python):
h,w = map(int,input().split())
t = [list(input()) for i in range(h)]
a = [[0 for i in range(w)] for j in range(h)]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if t[i][j] == "
      x[i][j] = -1
    elif j == 0:
      x[i][j] = 0
    else:
      x[i][j] = x[i][j-1]+1
      a[i][j] += x[i][j]
x = [[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 t[i][j] == "
      x[i][j] = -1
    elif j == w-1:
      x[i][j] += 0
    else:
      x[i][j] = x[i][j+1]+1
      a[i][j] += x[i][j]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if t[i][j] == "
      x[i][j] = -1
    elif i == 0:
      a[i][j] += 0
    else:
      x[i][j] = x[i-1][j]+1
      a[i][j] += x[i][j]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h-1,-1,-1):
  for j in range(w):
    if t[i][j] == "
      x[i][j] = -1
    elif i == h-1:
      a[i][j] += 0
    else:
      x[i][j] = x[i+1][j]+1
      a[i][j] += x[i][j]
print(max(max(a[i]) for i in range(h))+1)

Solution (Python):
def solve():
    H, W = map(int, input().split())
    field = [list(input()) for i in range(H)]
    H_table = [[0] * W for i in range(H)]
    W_table = [[0] * W for i in range(H)]
    
    for h in range(H):
        for w in range(W):
            if field[h][w] == '
                continue
            if w == 0:
                H_table[h][w] = 1
            else:
                H_table[h][w] = H_table[h][w-1] + 1

    for h in range(H-1, -1, -1):
        mx = 0
        for w in range(W-1,-1,-1):
            if field[h][w] == '
                continue
            if w == W-1 or field[h][w+1] == '
                mx = H_table[h][w]
            else:
                H_table[h][w] = mx
    
    for w in range(W):
        for h in range(H):
            if field[h][w] == '
                continue
            if h == 0:
                W_table[h][w] = 1
            else:
                W_table[h][w] = W_table[h-1][w] + 1

    for w in range(W-1, -1, -1):
        mx = 0
        for h in range(H-1,-1,-1):
            if field[h][w] == '
                continue
            if h == H-1 or field[h+1][w] == '
                mx = W_table[h][w]
            else:
                W_table[h][w] = mx
    
    mx = 0
    for h in range(H):
        for w in range(W):
            if field[h][w] == '
                continue
            mx = max(mx, W_table[h][w] + H_table[h][w] - 1)
    
    print(mx)

if __name__ == '__main__':
    solve()

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



sta_l1 = [[] for i in range(H)]
goa_l1 = [[] for i in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            if j == 0 or S[i][j-1] == "
                start = j
                sta_l1[i].append(start)
            if j == W-1:
                goal = j
                goa_l1[i].append(goal)

        else:
            if j-1 >= 0 and S[i][j-1] == ".":
                goal = j-1
                goa_l1[i].append(goal)



sta_l2 = [[] for i in range(W)]
goa_l2 = [[] for i in range(W)]

v1 = [[0]*W for i in range(H)]
for i in range(len(sta_l1)):
    for j in range(len(sta_l1[i])):
        for k in range(sta_l1[i][j],goa_l1[i][j]+1):
            v1[i][k] = goa_l1[i][j] - sta_l1[i][j] +1


for i in range(W):
    for j in range(H):
        if S[j][i] == ".":
            if j == 0 or S[j-1][i] == "
                start = j
                sta_l2[i].append(start)
            if j == H-1:
                goal = j
                goa_l2[i].append(goal)

        else:
            if j-1 >= 0 and S[j-1][i] == ".":
                goal = j-1
                goa_l2[i].append(goal)



v2 = [[0]*W for i in range(H)]
for i in range(len(sta_l2)):
    for j in range(len(sta_l2[i])):
        for k in range(sta_l2[i][j],goa_l2[i][j]+1):
            v2[k][i] = goa_l2[i][j] - sta_l2[i][j] +1


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


print(ans)

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

F = [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 F[i][j] == "
            L[i][j] = 0
            U[i][j] = 0
        else:
            L[i][j] = L[i][j - 1] + 1 if j - 1 >= 0 else 1
            U[i][j] = U[i - 1][j] + 1 if i - 1 >= 0 else 1

        if F[i][-1 - j] == "
            R[i][-1 - j] = 0
        else:
            R[i][-1 - j] = R[i][-j] + 1 if j > 0 else 1

        if F[- 1 - i][j] == "
            D[- 1 - i][j] = 0
        else:
            D[- 1 - i][j] = D[-i][j] + 1 if i > 0 else 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())
MAP = []
for _ in range(H):
    MAP.append(list(input()))
L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H)]
U = [[0 for i in range(W)] for j in range(H)]

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

MAX = 0

for i in range(H):
    for j in range(W):
        tmp = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
        if MAX < tmp:
            MAX = tmp

print(MAX)

Solution (Python):
import bisect




import itertools



import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    h, w = list(map(int,ipti().split()))
    hw = [sys.stdin.readline().rstrip("\n") 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):
        s = hw[i]
        for j in range(w):
            if s[j] == "
                l[i][j] = 0
                d[i][j] = 0
            else:
                if j == 0:
                    l[i][j] = 1
                else:
                    l[i][j] = l[i][j-1] + 1
                if i == 0:
                    u[i][j] = 1
                else:
                    u[i][j] = u[i-1][j] + 1

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

    ans = 0

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

    print(ans-3)

if __name__ == '__main__':
    main()

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

dph = [[0 for _ in range(w)] for _ in range(h)]
dpw = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
  for j in range(w):
    if maze[i][j] == '
      continue
    if dpw[i][j] != 0:
      continue
    k = j
    count = 0
    while k< w:
      
      if maze[i][k] == '.':
        count += 1
        k += 1
      else:
        break
    for l in range(j,k):
      dpw[i][l] = count
      
for i in range(w):
  for j in range(h):
    if maze[j][i] == '
      continue
    if dph[j][i] != 0:
      continue
    k = j
    count = 0
    while k< h:
      
      if maze[k][i] == '.':
        count += 1
        k += 1
      else:
        break
    for l in range(j,k):
      dph[l][i] = count


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

Solution (Python):
def main():

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

    c1 = [[0 for i in range(w)] for i in range(h)]
    c2 = [[0 for i in range(w)] for i in range(h)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if c1[i][j] == 0:
                n = 0
                k = i
                while k < h:
                    if l[k][j] == ".":
                        n +=1
                        k += 1
                    else:
                        break
                for r in range(i,k):
                    c1[r][j] = n
                
            if c2[i][j] == 0:
                n = 0
                k = j
                while k < w:
                    if l[i][k] == ".":
                        n +=1
                        k += 1
                    else:
                        break
                for r in range(j,k):
                    c2[i][r] = n


            ans = max(ans,c1[i][j]+c2[i][j])
    print(ans-1)
if __name__ == "__main__":
    main()

Solution (Python):

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

c1 = [[0 for i in range(w)] for i in range(h)]
c2 = [[0 for i in range(w)] for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if c1[i][j] == 0:
            n = 0
            k = i
            while k < h:
                if l[k][j] == ".":
                    n +=1
                    k += 1
                else:
                    break
            for r in range(i,k):
                c1[r][j] = n
            
        if c2[i][j] == 0:
            n = 0
            k = j
            while k < w:
                if l[i][k] == ".":
                    n +=1
                    k += 1
                else:
                    break
            for r in range(j,k):
                c2[i][r] = n


        ans = max(ans,c1[i][j]+c2[i][j])
print(ans-1)

Solution (Python):

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

c1 = [[0 for i in range(w)] for i in range(h)]
c2 = [[0 for i in range(w)] for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if c1[i][j] == 0:
            n = 0
            while i+n < h:
                if l[i+n][j] == ".":
                    n +=1
                else:
                    break
            for k in range(n):
                c1[i+k][j] = n
            
        if c2[i][j] == 0:
            n = 0
            while j+n < w:
                if l[i][j+n] == ".":
                    n +=1
                else:
                    break
            for k in range(n):
                c2[i][j+k] = n


        ans = max(ans,c1[i][j]+c2[i][j])
print(ans-1)

Solution (Python):

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

c1 = [[-1 for i in range(w)] for i in range(h)]
c2 = [[-1 for i in range(w)] for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if c1[i][j] == -1:
            n = 0
            while i+n < h:
                if l[i+n][j] == ".":
                    n += 1
                else:
                    break
            for k in range(n):
                c1[i+k][j] = n
            
        if c2[i][j] == -1:
            n = 0
            while j+n < w:
                if l[i][j+n] == ".":
                    n += 1
                else:
                    break
            for k in range(n):
                c2[i][j+k] = n


        ans = max(ans,c1[i][j]+c2[i][j])
print(ans-1)

Solution (Python):
h,w = map(int,input().split())
ans = [[0]*(w+2) for _ in range(h+2)]
grid = []
grid.append(['
for _ in range(h):
    s = list(input())
    grid.append(['
grid.append(['
for i in range(1,h+1):
    for j in range(0,w+2):
        if grid[i][j] == '
            if j >= 1:
                for k in range(j-start):
                    ans[i][start+k] += j-start
            start = j + 1
for j in range(1,w+1):
    for i in range(0,h+2):
        if grid[i][j] == '
            if i >= 1:
                for k in range(i-start):
                    ans[start+k][j] += i-start
            start = i + 1
print(max(list(map(lambda x:max(x),ans)))-1)

Solution (Python):
import numpy as np

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

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):
    D[i] = (D[i-1]+1) * S[i]
    U[-i-1] = (U[-i]+1) * S[-i-1]

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

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

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

dph = [[0 for _ in range(w)] for _ in range(h)]
dpw = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
  for j in range(w):
    if maze[i][j] == '
      continue
    if dpw[i][j] != 0:
      continue
    k = j
    count = 0
    while k< w:
      
      if maze[i][k] == '.':
        count += 1
        k += 1
      else:
        break
    for l in range(j,k):
      dpw[i][l] = count
      
for i in range(w):
  for j in range(h):
    if maze[j][i] == '
      continue
    if dph[j][i] != 0:
      continue
    k = j
    count = 0
    while k< h:
      
      if maze[k][i] == '.':
        count += 1
        k += 1
      else:
        break
    for l in range(j,k):
      dph[l][i] = count


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

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

    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input().rstrip('\n'))

    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(1, W):
            if grid[h][w-1] == '.' and grid[h][w] == '.':
                L[h][w] = L[h][w-1] + 1
    for h in range(H):
        for w in range(W-2, -1, -1):
            if grid[h][w] == '.' and grid[h][w+1] == '.':
                R[h][w] = R[h][w+1] + 1
    for w in range(W):
        for h in range(1, H):
            if grid[h][w] == '.' and grid[h-1][w] == '.':
                U[h][w] = U[h-1][w] + 1
    for w in range(W):
        for h in range(H-2, -1, -1):
            if grid[h][w] == '.' and grid[h+1][w] == '.':
                D[h][w] = D[h+1][w] + 1

    ans = 1
    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] + 1)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
s=[]
for i in range(h):
	s.append(input().rstrip())
num=[[0]*w for _ in range(h)]
for i in range(h):
	p=0
	for j in range(w):
		if s[i][j]==".":
			p+=1
			num[i][j]+=p
		else:
			p=0
for i in range(h):
	p=0
	for j in range(w-1,-1,-1):
		if s[i][j]==".":
			p+=1
			num[i][j]+=p
		else:
			p=0
for i in range(w):
	p=0
	for j in range(h):
		if s[j][i]==".":
			p+=1
			num[j][i]+=p
		else:
			p=0
for i in range(w):
	p=0
	for j in range(h-1,-1,-1):
		if s[j][i]==".":
			p+=1
			num[j][i]+=p
		else:
			p=0
ans=0
for i in range(h):
	ans=max(ans,max(num[i])-3)
print(ans)

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

L=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if M[i][j]=='
            L[i][j]=0
        elif j!=0:
            L[i][j]=L[i][j-1]+1
        else:
            L[i][j]=1
    
R=[[0]*w for _ in range(h)]
for i in range(h):
    for j in reversed(range(w)):
        if M[i][j]=='
            R[i][j]=0
        elif j!=w-1:
            R[i][j]=R[i][j+1]+1
        else:
            R[i][j]=1

U=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if M[i][j]=='
            U[i][j]=0
        elif i!=0:
            U[i][j]=U[i-1][j]+1
        else:
            U[i][j]=1

D=[[0]*w for _ in range(h)]
for i in reversed(range(h)):
    for j in range(w):
        if M[i][j]=='
            D[i][j]=0
        elif i!=h-1:
            D[i][j]=D[i+1][j]+1
        else:
            D[i][j]=1

ans=1
for i in range(h):
    for j in range(w):
        if M[i][j]=='
            continue
        ans=max(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()]
room = ['0'] * H
ans = -1
for i in range(H):
    room[i] = list(input())
L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
B = [[0] * W for _ in range(H)]
for i in range(W):
    if room[0][i] == '.':
        U[0][i] = 1
        if i == 0:
            L[0][i] = 1
        else:
            L[0][i] = L[0][i-1] +1
for i in range(H):
    if room[i][0] == '.':
        L[i][0] = 1
        if i == 0:
            U[i][0] = 1
        else:
            U[i][0] = U[i-1][0] +1
for x in range(1,H):
    for y in range(1,W):
        if room[x][y] == '.':
            U[x][y] = U[x-1][y]+1
            L[x][y] = L[x][y-1]+1
Ha = [int(i) for i in range(H)]
Wa = [int(i) for i in range(W)]
for i in Wa[::-1]:
    if room[H-1][i] == '.':
        B[H-1][i] = 1
        if i == W-1:
            R[H-1][i] = 1
        else:
            R[H-1][i] = R[H-1][i+1] +1
for i in Ha[::-1]:
    if room[i][W-1] == '.':
        R[i][W-1] = 1
        if i == H-1:
            B[i][W-1] = 1
        else:
            B[i][W-1] = B[i+1][W-1] +1
Haa = [int(i) for i in range(H-1)]
Waa = [int(i) for i in range(W-1)]
for x in Haa[::-1]:
    for y in Waa[::-1]:
        if room[x][y] == '.':
            R[x][y] = R[x][y+1]+1
            B[x][y] = B[x+1][y]+1
for x in range(H):
    for y in range(W):
        if room[x][y] == '.':
            ansa = U[x][y]+R[x][y]+B[x][y]+L[x][y]-3
            ans = max(ans,ansa)
print(ans)

Solution (Python):

from collections import deque
import sys
sys.setrecursionlimit(10 ** 9)

h, w = map(int, input().split())
maze = [[-1 for i in range(w)] for j in range(h)]

ans = 0
for i in range(h):
    maze[i] = input()

queue = deque()

left = [[0 for j in range(w)] for i in range(h)]
right = [[0 for j in range(w)] for i in range(h)]
up = [[0 for j in range(w)] for i in range(h)]
down = [[0 for j in range(w)] for i in range(h)]

cnt = 0

for i in range(h):
    cnt = 0
    for j in range(w):
        if maze[i][j] == '
        else:
            cnt += 1
            left[i][j] = cnt

    cnt = 0
    for j in reversed(range(w)):
        if maze[i][j] == '
        else:
            cnt += 1
            right[i][j] = cnt


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

    cnt = 0
    for i in reversed(range(h)):
        if maze[i][j] == '
        else:
            cnt += 1
            down[i][j] = cnt

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

print(ans)

Solution (Python):
def main():
    H, W = (int(i) for i in input().split())
    S = [input() for i in range(H)]
    c = [[-3]*W for i in range(H)]
    for h in range(H):
        cur = 1
        for w in range(W):
            if S[h][w] == ".":
                c[h][w] += cur
            else:
                cur = 0
            cur += 1
    for h in range(H):
        cur = 1
        for w in range(W)[::-1]:
            if S[h][w] == ".":
                c[h][w] += cur
            else:
                cur = 0
            cur += 1
    for w in range(W):
        cur = 1
        for h in range(H):
            if S[h][w] == ".":
                c[h][w] += cur
            else:
                cur = 0
            cur += 1
    for w in range(W):
        cur = 1
        for h in range(H)[::-1]:
            if S[h][w] == ".":
                c[h][w] += cur
            else:
                cur = 0
            cur += 1
    ma = 0
    
    for h in range(H):
        for w in range(W):
            if ma < c[h][w]:
                ma = c[h][w]
    print(ma)


if __name__ == '__main__':
    main()

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

H, W = [int(x) for x in input().split()]
S = []
for _ in range(H):
    S.append(input().rstrip())

dp_left = [[0] * (W + 2) for _ in range(H + 2)]
dp_up = [[0] * (W + 2) for _ in range(H + 2)]
dp_right = [[0] * (W + 2) for _ in range(H + 2)]
dp_down = [[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 - 1][j - 1] == "
            dp_left[i][j] = 0
        else:
            dp_left[i][j] = dp_left[i][j - 1] + 1
        
        if S[i - 1][-j] == "
            dp_right[i][-(j + 1)] = 0
        else:
            dp_right[i][-(j + 1)] = dp_right[i][-j] + 1

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

        if S[-j][i - 1] == "
            dp_down[-(j + 1)][i] = 0
        else:
            dp_down[-(j + 1)][i] = dp_down[-j][i] + 1

ans = 0

for i in range(1, H + 1):
    for j in range(1, W + 1):
        ans = max(ans, dp_left[i][j] + dp_up[i][j] + dp_right[i][j] + dp_down[i][j] - (dp_left[i][j] > 0) - (dp_up[i][j] > 0) - (dp_right[i][j] > 0) - (dp_down[i][j] > 0) + 1)

print(ans)

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


Left_count = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    s = S[i]
    count = 0
    for j in range(w):
        if s[j] == '
            count = 0
            continue
        else:
            count += 1
            Left_count[i][j] = count


Right_count = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    s = S[i][::-1]
    count = 0
    for j in range(w):
        if s[j] == '
            count = 0
            continue
        else:
            count += 1
            Right_count[i][j] = count
for i in range(h):
    Right_count[i] = Right_count[i][::-1]


Up_count = [[0 for _ in range(w)] for _ in range(h)]
for j in range(w):
    count = 0
    for i in range(h):
        if S[i][j] == '
            count = 0
            continue
        else:
            count += 1
            Up_count[i][j] = count


Down_count = [[0 for _ in range(w)] for _ in range(h)]
for j in range(w):
    count = 0
    for i in range(h-1,-1,-1):
        if S[i][j] == '
            count = 0
            continue
        else:
            count += 1
            Down_count[i][j] = count

ans = 0
for i in range(h):
    for j in range(w):
        tot_ij = Left_count[i][j] + Right_count[i][j] + Down_count[i][j] + Up_count[i][j] -3
        ans = max(tot_ij, ans)
print(ans)

Solution (Python):
import numpy as np
from copy import deepcopy


def main():
    height, width = map(int, input().split())
    grid = [list(input()) for _ in range(height)]
    grid = (np.array(grid) == ".") * 1
    left = np.zeros((height, width), dtype=int)
    right = deepcopy(left)
    upper = deepcopy(left)
    down = deepcopy(left)

    for i in range(height):
        if i == 0:
            upper[i] = grid[i]
        else:
            upper[i] = (upper[i - 1] + 1) * grid[i]

    for i in range(width):
        if i == 0:
            left[:, i] = grid[:, i]
        else:
            left[:, i] = (left[:, i - 1] + 1) * grid[:, i]

    for i in range(width - 1, -1, -1):
        if i == width - 1:
            right[:, i] = grid[:, i]
        else:
            right[:, i] = (right[:, i + 1] + 1) * grid[:, i]

    for i in range(height - 1, -1, -1):
        if i == height - 1:
            down[i] = grid[i]
        else:
            down[i] = (down[i + 1] + 1) * grid[i]

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


if __name__ == '__main__':
    main()

Solution (Python):
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[list(S()) 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)]

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

  ans=-inf
  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)

  return ans


print(main())