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())
G=[input() for _ in range(H)]
A_u=[[0 for _ in range(W)] for _ in range(H)]
A_d=[[0 for _ in range(W)] for _ in range(H)]
A_r=[[0 for _ in range(W)] for _ in range(H)]
A_l=[[0 for _ in range(W)] for _ in range(H)]
for h in range(H):
  for w in range(1,W):
    if G[h][w-1] == '.':
      A_r[h][w] = A_r[h][w-1]+1
  for w in range(W-2,-1,-1):
    if G[h][w+1] == '.':
      A_l[h][w] = A_l[h][w+1]+1
for w in range(W):
  for h in range(1,H):
    if G[h-1][w] == '.':
      A_d[h][w] = A_d[h-1][w]+1
  for h in range(H-2,-1,-1):
    if G[h+1][w] == '.':
      A_u[h][w] = A_u[h+1][w]+1
ans=0
for h in range(H):
  for w in range(W):
    if G[h][w] == '.':
      ans = max(ans,A_r[h][w]+A_l[h][w]+A_d[h][w]+A_u[h][w]+1)
print(ans)

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

G = []
for _ in range(H):
    g = []
    line = input()
    for i in range(W):
        g.append(line[i])
    G.append(g)


G_left = [[0] * W for _ in range(H)]
for h in range(H):
    cnt = 0
    for w in range(W):
        if G[h][w] == "
            cnt = 0
            G_left[h][w] = 0
        elif G[h][w] == ".":
            cnt += 1
            G_left[h][w] = cnt



G_right = [[0] * W for _ in range(H)]
for h in range(H):
    cnt = 0
    for w in range(W - 1, -1, -1):
        if G[h][w] == "
            cnt = 0
            G_right[h][w] = 0
        elif G[h][w] == ".":
            cnt += 1
            G_right[h][w] = cnt



G_up = [[0] * W for _ in range(H)]
for w in range(W):
    cnt = 0
    for h in range(H):
        if G[h][w] == "
            cnt = 0
            G_up[h][w] = 0
        elif G[h][w] == ".":
            cnt += 1
            G_up[h][w] = cnt



G_down = [[0] * W for _ in range(H)]
for w in range(W):
    cnt = 0
    for h in range(H - 1, -1, -1):
        if G[h][w] == "
            cnt = 0
            G_down[h][w] = 0
        elif G[h][w] == ".":
            cnt += 1
            G_down[h][w] = cnt

ans = 0
for h in range(H):
    for w in range(W):
        tmp = G_left[h][w] + G_right[h][w] + G_up[h][w] + G_down[h][w] - 3
        ans = max(ans, tmp)

print(ans)

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

G = []
for _ in range(H):
    g = []
    line = input()
    for i in range(W):
        g.append(line[i])
    G.append(g)


G_left = [[0] * W for _ in range(H)]
for h in range(H):
    cnt = 0
    for w in range(W):
        if G[h][w] == "
            cnt = 0
            G_left[h][w] = 0
        elif G[h][w] == ".":
            cnt += 1
            G_left[h][w] = cnt



G_right = [[0] * W for _ in range(H)]
for h in range(H):
    cnt = 0
    for w in range(W - 1, -1, -1):
        if G[h][w] == "
            cnt = 0
            G_right[h][w] = 0
        elif G[h][w] == ".":
            cnt += 1
            G_right[h][w] = cnt



G_up = [[0] * W for _ in range(H)]
for w in range(W):
    cnt = 0
    for h in range(H):
        if G[h][w] == "
            cnt = 0
            G_up[h][w] = 0
        elif G[h][w] == ".":
            cnt += 1
            G_up[h][w] = cnt



G_down = [[0] * W for _ in range(H)]
for w in range(W):
    cnt = 0
    for h in range(H - 1, -1, -1):
        if G[h][w] == "
            cnt = 0
            G_down[h][w] = 0
        elif G[h][w] == ".":
            cnt += 1
            G_down[h][w] = cnt

ans = 0
for h in range(H):
    for w in range(W):
        tmp = G_left[h][w] + G_right[h][w] + G_up[h][w] + G_down[h][w] - 3
        ans = max(ans, tmp)

print(ans)

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

grid = []
for _ in range(H):
    line = input()
    
    line += "
    grid.append(line)


grid.append("


G_h = []
for h in range(H):
    g = [-1] * W
    lamp_start = -1
    lamp = 0
    line = grid[h]
    for w in range(W):
        if line[w] == "
            g[w] = 0
        elif line[w] == ".":
            lamp += 1
            if lamp_start == -1:
                lamp_start = w
                
            if line[w + 1] == "
                
                for i in range(lamp_start, w + 1):
                    g[i] = lamp
                lamp_start = -1
                lamp = 0
    G_h.append(g)



G_v = []
for w in range(W):
    g = [-1] * H
    lamp_start = -1
    lamp = 0
    line = []
    for hi in range(H):
        line.append(grid[hi][w])
    line.append("
    
    for h in range(H):
        if line[h] == "
            g[h] = 0
        elif line[h] == ".":
            lamp += 1
            if lamp_start == -1:
                lamp_start = h
                
            if line[h + 1] == "
                
                for i in range(lamp_start, h + 1):
                    g[i] = lamp
                lamp_start = -1
                lamp = 0
    G_v.append(g)



ans = 0
for h in range(H):
    for w in range(W):
        tmp_ans = G_h[h][w] + G_v[w][h] - 1
        ans = max(ans, tmp_ans)
print(ans)

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

X = []
for i in range(H):
  C = [0 for _ in range(W)]
  count = 0
  for j in range(W-1, -1, -1):
    if M[i][j] == ".":
      count += 1
      C[j] = count
    else:
      count = 0

  r = [0 for _ in range(W)]
  current = C[0]
  for j in range(W):
    if M[i][j] == ".":
      r[j] = current
    else:
      r[j] = 0
      if j + 1 < W:
        current = C[j+1]
  X.append(r)
Y = []
for i in range(W):
  C = [0 for _ in range(H)]
  count = 0
  for j in range(H-1, -1, -1):
    if M[j][i] == ".":
      count += 1
      C[j] = count
    else:
      count = 0

  r = [0 for _ in range(H)]
  current = C[0]
  for j in range(H):
    if M[j][i] == ".":
      r[j] = current
    else:
      r[j] = 0
      if j + 1 < H:
        current = C[j+1]
  Y.append(r)

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

Solution (Python):
import sys
H, W = map(int, input().split())
G = [sys.stdin.readline() for _ in range(H)]

counts = [[[-1] * 4 for _ in range(W + 1)] for _ in range(H + 1)]
for h in range(H):
    for w in range(W):
        if G[h][w] == ".":
            counts[h][w][0] = counts[h][w-1][0] + 1
            counts[h][w][1] = counts[h-1][w][1] + 1
        dih = H - h - 1
        diw = W - w - 1
        if G[dih][diw] == ".":
            counts[dih][diw][2] = counts[dih][diw+1][2] + 1
            counts[dih][diw][3] = counts[dih+1][diw][3] + 1
ans = 0
for h in range(H):
    for w in range(W):
        if G[h][w] == ".":
            ans = max(ans, sum(counts[h][w]) + 1)
print(ans)

Solution (Python):
h, w = map(int, input().split())
s = [[*map(lambda c:c == ".", input())] for _ in [0] * h]
for i in "LRUD":
    exec(i + "= [[0] * w for _ in [0] * h]")
for i in range(h):
    for j in range(w):
        L[i][j]    = L[i][j-1] + 1 if s[i][j]    else 0
        R[i][-j-1] = R[i][-j]  + 1 if s[i][-j-1] else 0
for j in range(w):
    for i in range(h):
        U[i][j]    = U[i-1][j] + 1 if s[i][j]    else 0
        D[-i-1][j] = D[-i][j]  + 1 if s[-i-1][j] else 0
print(max(L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(h) for j in range(w)))

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

ans = 1
opt = [(0,1),(0,-1),(1,0),(-1,0)]
s2 = [[0]*(w+2) for i in range(h+2)]
s3 = [[0]*(w+2) for i in range(h+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "." and s2[i][j] == 0:
            cnt = 0
            for k in opt[0:2]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    cnt += 1
                    tempy += k[0]
                    tempx += k[1]
            for k in opt[0:2]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    s2[tempy+k[0]][tempx+k[1]] += cnt
                    tempy += k[0]
                    tempx += k[1]
            s2[i][j] += cnt
        if s[i][j] == "." and s3[i][j] == 0:
            cnt = 0
            for k in opt[2:4]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    cnt += 1
                    tempy += k[0]
                    tempx += k[1]
            for k in opt[2:4]:
                tempy = i
                tempx = j
                while s[tempy+k[0]][tempx+k[1]] == ".":
                    s3[tempy+k[0]][tempx+k[1]] += cnt
                    tempy += k[0]
                    tempx += k[1]
            s3[i][j] += cnt
        ans = max(ans,1+s2[i][j]+s3[i][j])

print(ans)

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

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


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






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

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

Solution (Python):
import numpy as np
H, W = map(int, input().split())
S = np.zeros((H,W))
for i in range(H):
    Si = np.array([int(s == '.') for s in input()])
    S[i] = Si
    
top = S.copy()
bottom = S.copy()
left = S.copy()
right = S.copy()

for i in range(1, H):
    top[i] = (top[i-1] + 1) * S[i]
    bottom[-i-1] = (bottom[-i] + 1) * S[-i-1]

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

print(np.max((top + bottom + left + right - 3).astype(np.int)))

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

cnt_l, cnt_r, cnt_u, cnt_d = [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)]

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

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

        if data[h - i - 1][j] == "
            cnt_d[h - i - 1][j] = 0
        else:
            if i == 0:
                cnt_d[h - i - 1][j] = 1
            else:
                cnt_d[h - i - 1][j] = cnt_d[h - i][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        total= cnt_l[i][j] + cnt_r[i][j] + cnt_u[i][j] + cnt_d[i][j] - 3
        ans = max(ans, total)

print(ans)

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

L = [[0]*W for _ in range(H)]
U = [[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] == "
            U[h][w] = 0
        elif h == 0:
            U[h][w] = 1
        else:
            U[h][w] = U[h-1][w] + 1

R = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == "
            R[h][w] = 0
        elif w == W-1:
            R[h][w] = 1
        else:
            R[h][w] = R[h][w+1] + 1

        if S[h][w] == "
            D[h][w] = 0
        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):
        ans = max(ans, L[h][w]+R[h][w]+U[h][w]+D[h][w]-3)

print(ans)

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


yoko, tate = [], []
for h in range(H):
    now = []
    
    w, cnt = 0, 0
    while True:
        if not w < W:
            for _ in range(cnt): now.append(cnt) 
            break

        if S[h][w] == "
            for _ in range(cnt): now.append(cnt)
            now.append(0)
            cnt = 0
        else:
            cnt += 1

        w += 1

    yoko.append(now)

for w in range(W):
    now = []
    
    h, cnt = 0, 0
    while True:
        if not h < H:
            for _ in range(cnt): now.append(cnt) 
            break

        if S[h][w] == "
            for _ in range(cnt): now.append(cnt)
            now.append(0)
            cnt = 0
        else:
            cnt += 1

        h += 1
    
    tate.append(now)

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

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

dpl = [[1] * w for _ in range(h)]
dpr = [[1] * w for _ in range(h)]
dpu = [[1] * w for _ in range(h)]
dpd = [[1] * w for _ in range(h)]

for i, si in enumerate(s):
    for j, sij in enumerate(si):
        if sij == '
            dpl[i][j], dpu[i][j] = 0, 0
        elif sij == '.':
            if j - 1 >= 0:
                dpl[i][j] = dpl[i][j - 1] + 1
            if i - 1 >= 0:
                dpu[i][j] = dpu[i - 1][j] + 1
for i, si in enumerate(s[::-1]):
    i = h - i - 1
    for j, sij in enumerate(si[::-1]):
        j = w - j - 1
        if sij == '
            dpr[i][j], dpd[i][j] = 0, 0
        elif sij == '.':
            if j + 1 < w:
                dpr[i][j] = dpr[i][j + 1] + 1
            if i + 1 < h:
                dpd[i][j] = dpd[i + 1][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        cnt = dpl[i][j] + dpr[i][j] + dpu[i][j] + dpd[i][j]
        ans = max(ans, cnt)
print(ans - 3)

Solution (Python):

H, W = map(int, input().split())
X = [input() for _ in range(H)]

grid0 = [[0] * (W + 1) for _ in range(H + 1)]
for i in range(H):
    for j in range(W):
        grid0[i + 1][j + 1] = int(X[i][j] == ".")


for i in range(H + 1):
    for j in range(W):
        if grid0[i][j + 1] > 0:
            grid0[i][j + 1] += grid0[i][j]


for i in range(H + 1):
    for j in reversed(range(W)):
        if grid0[i][j] > 0:
            grid0[i][j] = max(grid0[i][j], grid0[i][j + 1])

grid1 = [[0] * (W + 1) for _ in range(H + 1)]
for i in range(H):
    for j in range(W):
        grid1[i + 1][j + 1] = int(X[i][j] == ".")


for i in range(H):
    for j in range(W + 1):
        if grid1[i + 1][j] > 0:
            grid1[i + 1][j] += grid1[i][j]


for i in reversed(range(H)):
    for j in range(W + 1):
        if grid1[i][j] > 0:
            grid1[i][j] = max(grid1[i][j], grid1[i + 1][j])

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

print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    S = [list(SS()) for _ in range(H)]

    left = [[0] * W for _ in range(H)]
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][j] == '.':
                cnt += 1
                left[i][j] = cnt
            else:
                cnt = 0

    right = [[0] * W for _ in range(H)]
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][W-1-j] == '.':
                cnt += 1
                right[i][W-1-j] = cnt
            else:
                cnt = 0

    up = [[0] * W for _ in range(H)]
    for i in range(W):
        cnt = 0
        for j in range(H):
            if S[j][i] == '.':
                cnt += 1
                up[j][i] = cnt
            else:
                cnt = 0

    down = [[0] * W for _ in range(H)]
    for i in range(W):
        cnt = 0
        for j in range(H):
            if S[H-1-j][i] == '.':
                cnt += 1
                down[H-1-j][i] = cnt
            else:
                cnt = 0

    ans = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            ans[i][j] = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3

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

if __name__ == '__main__':
    resolve()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    S = [list(SS()) for _ in range(H)]

    idx_w = []
    for i in range(H):
        tmp = [-1]
        for j in range(W):
            if S[i][j] == '
                tmp.append(j)
        tmp.append(W)
        idx_w.append(tmp)

    idx_h = []
    for i in range(W):
        tmp = [-1]
        for j in range(H):
            if S[j][i] == '
                tmp.append(j)
        tmp.append(H)
        idx_h.append(tmp)

    ans = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(len(idx_w[i]) - 1):
            for k in range(idx_w[i][j] + 1, idx_w[i][j+1]):
                ans[i][k] += idx_w[i][j+1] - idx_w[i][j] - 1

    for i in range(W):
        for j in range(len(idx_h[i]) - 1):
            for k in range(idx_h[i][j] + 1, idx_h[i][j+1]):
                ans[k][i] += idx_h[i][j+1] - idx_h[i][j] - 2

    
    

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

if __name__ == '__main__':
    resolve()

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

res=[[] for i in range(H)]
for i in range(H):
  count=0
  for j in range(W):
    if S[i][j]=='
      if j != 0 and S[i][j-1]=='.':
        res[i].append(count)
      res[i].append(0)
      count=0
      continue
    else:
      count += 1
      if j == W-1:
        res[i].append(count)

cum = [[] for i in range(len(res))]
for i in range(len(res)):
  for j in range(len(res[i])):
    if res[i][j]==0:cum[i].append(0)
    else:cum[i].extend([res[i][j]]*res[i][j])

res=[[] for i in range(W)]
for i in range(W):
  count=0
  for j in range(H):
    if S[j][i]=='
      if j != 0 and S[j-1][i]=='.':
        res[i].append(count)
      res[i].append(0)
      count=0
      continue
    else:
      count += 1
      if j == H-1:
        res[i].append(count)

cum2 = [[] for i in range(len(res))]
for i in range(len(res)):
  for j in range(len(res[i])):
    if res[i][j]==0:cum2[i].append(0)
    else:cum2[i].extend([res[i][j]]*res[i][j])

ans=0
for i in range(H):
  for j in range(W):
    tmp = cum[i][j]+cum2[j][i]-1
    if tmp > ans:ans=tmp

print(ans)

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

Solution (Python):
h, w = map(int, input().split())
w += 2
h += 2
grid = ["

dpx = [[0] * w for _ in range(h)]
dpy = [[0] * w for _ in range(h)]
for y in range(1, h - 1):
    grid.append("
    for x in range(1, w):
        if grid[y][x] == '.':
            dpx[y][x] = dpx[y][x - 1] + 1
            dpy[y][x] = dpy[y - 1][x] + 1
    for x in range(w - 2, 0, -1):
        if dpx[y][x] != 0 and dpx[y][x + 1] != 0:
            dpx[y][x] = dpx[y][x + 1]

max_val = 0
for y in range(h - 2, 0, -1):
    for x in range(1, w - 1):
        if dpy[y][x] != 0 and dpy[y + 1][x] != 0:
            dpy[y][x] = dpy[y + 1][x]
        val = dpy[y][x] + dpx[y][x] - 1
        if max_val < val:
            max_val = val
print(max_val)

Solution (Python):
def main():
    import sys
    input=sys.stdin.readline
    H,W=map(int,input().split())
    maze=[]
    for _ in range(H):
        s=input().rstrip()
        maze.append(s)
    lamp=[[0]*W for _ in range(H)]
    for i in range(H):
        num=0
        for j in range(W):
            if maze[i][j]=="
                for k in range(1,num+1):
                    lamp[i][j-k]=num
                num=0
            else:
                num+=1
                if j==W-1:
                    for k in range(num):
                        lamp[i][j-k]=num
    for i in range(W):
        num=0
        for j in range(H):
            if maze[j][i]=="
                for k in range(1,num+1):
                    lamp[j-k][i]+=num
                num=0
            else:
                num+=1
                if j==H-1:
                    for k in range(num):
                        lamp[j-k][i]+=num
    lamp=[i for j in lamp for i in j]
    print(max(lamp)-1)
    
if __name__=="__main__":
    main()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7





H, W = getNM()
S = [input() for i in range(H)]
score_w = [[0] * W for i in range(H)]
score_h = [[0] * W for i in range(H)]

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

    for j in range(1, W):
        if score_w[i][-j - 1] > 0:
            score_w[i][-j - 1] = max(score_w[i][-j - 1], score_w[i][-j])

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

    for i in range(1, H):
        if score_h[-i - 1][j] > 0:
            score_h[-i - 1][j] = max(score_h[-i - 1][j], score_h[-i][j])

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, score_w[i][j] + score_h[i][j] - 1)
print(ans)

Solution (Python):
h,w=map(int,input().split())
l=list()
l.append('
for i in range(h):
    l.append("
l.append('
si=[[0 for i in j] for j in l]
sj=[[0 for i in j] for j in l]
for i in range(h+2):
    k=0
    for j in range(w+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(j-k,j):
                si[i][f]=k
            k=0
for j in range(w+2):
    k=0
    for i in range(h+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(i-k,i):
                sj[f][j]=k
            k=0
ans=0
for i in range(h+2):
    for j in range(w+2):
        ans=max(ans,sj[i][j]+si[i][j])
print(ans-1)

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

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

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

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

ans = 0

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

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    grid = [list(input().rstrip()) for _ in range(H)]

    cnt_w = [[0] * W for _ in range(H)]
    for h in range(H):
        cnt = 0
        for w in range(W):
            if grid[h][w] == "
                cnt = 0
            else:
                cnt += 1
            cnt_w[h][w] = cnt

    for h in range(H):
        cnt = 0
        for w in reversed(range(W)):
            if grid[h][w] == "
                cnt = 0
            else:
                cnt = max(cnt, cnt_w[h][w])
            cnt_w[h][w] = cnt

    cnt_h = [[0] * W for _ in range(H)]
    for w in range(W):
        cnt = 0
        for h in range(H):
            if grid[h][w] == "
                cnt = 0
            else:
                cnt += 1
            cnt_h[h][w] = cnt

    for w in range(W):
        cnt = 0
        for h in reversed(range(H)):
            if grid[h][w] == "
                cnt = 0
            else:
                cnt = max(cnt, cnt_h[h][w])
            cnt_h[h][w] = cnt

    res = 0
    for h in range(H):
        for w in range(W):
            res = max(res, cnt_w[h][w] + cnt_h[h][w] - 1)
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())
    
ans_W = [[-1 for i in range(W)] for j in range(H)]
for i in range(H):
    count = 0
    now = 0
    for j in range(W):
        if S[i][j] == ".":
            count += 1
        else:
            for k in range(now, min(W, now+1+count)):
                if k == j:
                    ans_W[i][k] = 0
                else:
                    ans_W[i][k] = count
            now += count+1
            count = 0
    if count != 0:
        for k in range(now, min(W, now+1+count)):
            ans_W[i][k] = count

ans_H = [[-1 for i in range(W)] for j in range(H)]
for i in range(W):
    count = 0
    now = 0
    for j in range(H):
        if S[j][i] == ".":
            count += 1
        else:
            for k in range(now, min(H, now+1+count)):
                if k == j:
                    ans_H[k][i] = 0
                else:
                    ans_H[k][i] = count
            now += count+1
            count = 0
    if count != 0:
        for k in range(now, min(H, now+1+count)):
            ans_H[k][i] = count

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

Solution (Python):
import sys
import bisect


def input():
    return sys.stdin.readline().rstrip()


def main():
    H, W = map(int, input().split())
    S = [[] for _ in range(H)]
    count = [[0] * W for _ in range(H)]

    
    for i in range(H):
        s = list(input())
        S[i] = s
        con = 0
        for j in range(W):
            if s[j] == "
                con = 0
                continue
            elif con == 0:
                con = 1
                k = j + 1
                while k < W:
                    if s[k] == ".":
                        con += 1
                        k += 1
                    else:
                        break
                count[i][j] = con
            elif con > 0:
                count[i][j] = con

    pass
    
    for j in range(W):
        
        con = 0
        for i in range(H):
            if S[i][j] == "
                con = 0
                continue
            elif con == 0:
                con = 1
                k = i + 1
                while k < H:
                    if S[k][j] == ".":
                        con += 1
                        k += 1
                    else:
                        break
                count[i][j] += con
            elif con > 0:
                count[i][j] += con

    m = 0
    for i in range(H):
        m =max(m,max(count[i]))
    print(m-1)

if __name__ == "__main__":
    main()