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):
def main():
    H, W = map(int, input().split())
    grid = [list(input()) for _ in range(H)]
    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 h in range(H):
        for w in range(W):
            if grid[h][w] == '
                continue
            if w == 0:
                L[h][w] = 1
            else:
                L[h][w] = L[h][w-1] + 1
            if h == 0:
                U[h][w] = 1
            else:
                U[h][w] = U[h-1][w] + 1
    for h in range(H - 1, -1, -1):
        for w in range(W - 1, -1, -1):
            if grid[h][w] == '
                continue
            if w == W - 1:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w + 1] + 1
            if 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)


if __name__ == '__main__':
    main()

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

yoko = [[0] * w for i in range(h)]
for i in range(h):
    tmp = 0
    l = 0
    for j in range(w + 1):
        if j == w or s[i][j] == "
            for k in range(l, j):
                yoko[i][k] = tmp
            l = j + 1
            tmp = 0
        else:
            tmp += 1
            
tate = [[0] * w for i in range(h)]
for j in range(w):
    tmp = 0
    l = 0
    for i in range(h + 1):
        if i == h or s[i][j] == "
            for k in range(l, i):
                tate[k][j] = tmp
            l = i + 1
            tmp = 0
        else:
            tmp += 1

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

Solution (Python):
h,w=map(int,input().split())
s=[]
s.append("
for i in range(h):
  s.append("
s.append("
r=[[0]*(w+2) for i in range(h+2)]
l=[[0]*(w+2) for i in range(h+2)]
d=[[0]*(w+2) for i in range(h+2)]
u=[[0]*(w+2) for i in range(h+2)]

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

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


def read_map_as(H, W, replace={'
    '''
    文字列のmapを置換して読み込み。デフォでは
    '''
    ret = []
    ret.append([1] * (W + 2))
    for _ in range(H):
        ret.append([1] + [replace[s] for s in read()[:-1]] + [1])
        
        
    ret.append([1] * (W + 2))
    return ret


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  






H, W = read_ints()
S = read_map_as(H, W)

yoko = [[-1] * (W + 2) for _ in ra(H + 2)]
tate = [[-1] * (W + 2) for _ in ra(H + 2)]


for i in ra(H + 2):
    fillranges = []
    pre_0 = 0
    for j in ra(1, W + 2):
        if S[i][j] == 1:
            fillranges.append((pre_0, j))
            pre_0 = j
    for l, r in fillranges:
        for j in range(l, r):
            yoko[i][j] = r - l - 1


for j in ra(W + 2):
    fillranges = []
    pre_0 = 0
    for i in ra(1, H + 2):
        if S[i][j] == 1:
            fillranges.append((pre_0, i))
            pre_0 = i
    for l, r in fillranges:
        for i in range(l, r):
            tate[i][j] = r - l - 1




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

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

for i in range(h):
    cnt = 0
    lis = []
    for j in range(w):

        if s[i][j] == '
            lis.append(cnt)
            cnt = 0
        elif j == w-1:
            if s[i][j] == '.':
                cnt += 1
            lis.append(cnt)
        else:
            cnt += 1
    p = 0
    
    for j in range(w):
        if s[i][j] == '.':
            
            
            lr[i][j] = lis[p]
        else:
            p += 1


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

for j in range(w):
    cnt = 0
    lis = []
    for i in range(h):
        
        if s[i][j] == '
            lis.append(cnt)
            cnt = 0
        elif i == h-1:
            if s[i][j] == '.':
                cnt += 1
            lis.append(cnt)
        else:
            cnt += 1
    p = 0
    
    for i in range(h):
        
        
        
        if s[i][j] == '.':
            
            
            ud[i][j] = lis[p]
        else:
            p += 1
        

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

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

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

for i in range(H):
  s = S[i]
  mar = 0
  cnt = 0
  for j in range(W):
    if s[j] == ".":
      cnt += 1
    if s[j] == "
      for k in range(mar,j):
        m[i][k] += cnt
      cnt = 0
      mar = j+1    
    
    if j == W-1 and s[j] == ".":
      for k in range(mar,j+1):
        m[i][k] += cnt



for i in range(W):
  mar = 0
  cnt = 0
  for j in range(H):
    if S[j][i] == ".":
      cnt += 1
    if S[j][i] == "
      for k in range(mar,j):
        m[k][i] += cnt
      cnt = 0
      mar = j+1 
    
    if j == H-1 and S[j][i] == ".":
      for k in range(mar,j+1):
        m[k][i] += cnt


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

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

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

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

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

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

for w in range(1,W+1):
    for h in range(H,0,-1):
        if S[h+1][w] in ['
            down[h][w] = 0
        else:
            down[h][w] = down[h+1][w]+1
ans = 0
for h in range(1,H+1):
    for w in range(1,W+1):
        ans = max(ans,left[h][w]+right[h][w]+up[h][w]+down[h][w]+1)

print(ans)

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


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

for i in range(h):
    for j in range(w):
        temp_L = s[i][j]
        temp_R = s[i][-(j + 1)]
        temp_U = s[i][j]
        temp_D = s[-(i + 1)][j]

        if temp_L == '
        else:
            if j == 0:L[i][j] = 1
            else:L[i][j] = L[i][j - 1] + 1

        if temp_R == '
        else:
            if j == 0:R[i][-(j + 1)] = 1
            else:R[i][-(j + 1)] = R[i][-(j + 1) + 1] + 1

        if temp_U == '
        else:
            if i == 0:U[i][j] = 1
            else:U[i][j] = U[i - 1][j] + 1

        if temp_D == '
        else:
            if i == 0:D[-(i + 1)][j] = 1
            else:D[-(i + 1)][j] = D[-(i + 1) + 1][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] - 3
        if ans < temp:ans = temp
print(ans)

Solution (Python):
from sys import stdin
def main():
    
    readline=stdin.readline
    H,W=map(int,readline().split())
    grid=[]
    for i in range(H):
        S=readline().strip()
        grid.append(S)
    up=[[0]*W for _ in range(H)]
    down=[[0]*W for _ in range(H)]
    left=[[0]*W for _ in range(H)]
    right=[[0]*W for _ in range(H)]

    
    for i in range(H):
        for j in range(W):
            if grid[i][j]==".":
                if i==0:
                    up[i][j]=1
                else:
                    up[i][j]=up[i-1][j]+1
            
                if j==0:
                    left[i][j]=1
                else:
                    left[i][j]=left[i][j-1]+1

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

                if j==W-1:
                    right[i][j]=1
                else:
                    right[i][j]=right[i][j+1]+1

    res=0
    for i in range(H):
        for j in range(W):
            if grid[i][j]==".":
                res=max(res,up[i][j]+down[i][j]+left[i][j]+right[i][j]-3)
    
    print(res)
if __name__=="__main__":
    main()

Solution (Python):
def main():
    H, W = (int(i) for i in input().split())
    A = [input() for i in range(H)]
    L = [[[0]*W for _ in range(H)] for _ in range(4)]
    for di in range(4):
        if di == 0 or di == 1:
            rangeH = range(H)
            rangeW = range(W)
        else:
            rangeH = range(H)[::-1]
            rangeW = range(W)[::-1]

        for h in rangeH:
            for w in rangeW:
                if A[h][w] == "
                    continue
                if di == 0:
                    if h-1 < 0 or A[h-1][w] == "
                        L[di][h][w] = 1
                    else:
                        L[di][h][w] = L[di][h-1][w] + 1
                elif di == 1:
                    if w-1 < 0 or A[h][w-1] == "
                        L[di][h][w] = 1
                    else:
                        L[di][h][w] = L[di][h][w-1] + 1
                elif di == 2:
                    if h+1 > H-1 or A[h+1][w] == "
                        L[di][h][w] = 1
                    else:
                        L[di][h][w] = L[di][h+1][w] + 1
                elif di == 3:
                    if w+1 > W-1 or A[h][w+1] == "
                        L[di][h][w] = 1
                    else:
                        L[di][h][w] = L[di][h][w+1] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            v = sum(L[i][h][w] for i in range(4)) - 3
            ans = max(ans, v)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = np.array(['
S = np.array([[x == '.' for x in row] for row in S])
S = S.astype(np.int16)
left = S.copy(); right = S.copy(); up = S.copy(); down = S.copy()
for i in range(1, W+1):
    left[:, i] += left[:, i-1]
    left[:, i] *= S[:, i]
for i in range(W, 0, -1):
    right[:, i] += right[:, i+1]
    right[:, i] *= S[:, i]
for i in range(1, H+1):
    up[i, :] += up[i-1, :]
    up[i, :] *= S[i, :]
for i in range(H, 0, -1):
    down[i, :] += down[i+1, :]
    down[i, :] *= S[i, :]

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

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

imoslr = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
  c = 0
  prev = 0
  for j in range(W):
    if S[i][j] == "
      imoslr[i][j] -= c
      imoslr[i][prev] += c
      prev = j + 1
      c = 0
    else: c += 1
  imoslr[i][prev] += c
  for j in range(W): imoslr[i][j + 1] += imoslr[i][j]

imosud = [[0] * (W) for _ in range(H + 1)]
for i in range(W):
  c = 0
  prev = 0
  for j in range(H):
    if S[j][i] == "
      imosud[j][i] -= c
      imosud[prev][i] += c
      prev = j + 1
      c = 0
    else: c += 1
  imosud[prev][i] += c
  for j in range(H): imosud[j + 1][i] += imosud[j][i]

res = 0
for i in range(H):
  for j in range(W): res = max(res, imoslr[i][j] + imosud[i][j] - 1)
print(res)

Solution (Python):
def resolve():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    hs = [[0]*w for _ in range(h)]
    ws = [[0]*w for _ in range(h)]

    for i in range(h):
        cums = 0
        for j in range(w):
            if s[i][j] == "
                cums = 0
                ws[i][j] = 0
            else:
                cums += 1
                ws[i][j] = cums
        for j in reversed(range(w-1)):
            if ws[i][j+1] != 0 and ws[i][j] != 0:
                ws[i][j] = ws[i][j+1]

    for i in range(w):
        cums = 0
        for j in range(h):
            if s[j][i] == "
                cums = 0
                hs[j][i] = 0
            else:
                cums += 1
                hs[j][i] = cums
        for j in reversed(range(h-1)):
            if hs[j+1][i] != 0 and hs[j][i] != 0:
                hs[j][i] = hs[j+1][i]

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()


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

    """まずは縦に何連続かだけ計測"""
    dp = [[0] * W for _ in range(H)]
    
    for j in range(W):
        if S[0][j] != '
            dp[0][j] = 1
    
    for i in range(1, H):
        for j in range(W):
            if S[i][j] != '
                dp[i][j] = dp[i - 1][j] + 1
            else:
                num = dp[i - 1][j]
                for k in range(num):
                    dp[i - 1 - k][j] = num
    
    for j in range(W):
        num = dp[H - 1][j]
        for k in range(num):
            dp[H - 1 - k][j] = num
    
    """次に横に何連続かを計測"""

    dp2 = [[0] * W for _ in range(H)]
    
    for i in range(H):
        if S[i][0] != '
            dp2[i][0] = 1
    
    for j in range(1, W):
        for i in range(H):
            if S[i][j] != '
                dp2[i][j] = dp2[i][j - 1] + 1
            else:
                num = dp2[i][j - 1]
                for k in range(num):
                    dp2[i][j - 1 - k] = num
    
    for i in range(H):
        num = dp2[i][W - 1]
        for k in range(num):
            dp2[i][W - 1 - k] = num
    
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, dp[i][j] + dp2[i][j] - 1)
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import sys

input = sys.stdin.readline

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

grid = []

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

for _ in range(H):
  grid.append([x for x in input()])
  

for h in range(H):
  r = 0
  count = 0
  for l in range(W):
    while r < W and grid[h][r] == '.':
      r += 1
      count += 1
    count_w[h][l] = count
    if r == l:
      r += 1
      count = 0
      
for w in range(W):
  r = 0
  count = 0
  for l in range(H):
    while r < H and grid[r][w] == '.':
      r += 1
      count += 1
    count_h[l][w] = count
    if r == l:
      r += 1
      count = 0

answer = 0

for h in range(H):
  for w in range(W):
    answer = max(answer, count_h[h][w] + count_w[h][w] - 1)

print(answer)

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

l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
u=[[0]*w for i in range(h)]
d=[[0]*w for i in range(h)]

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

for i in range(h):
    for j in reversed(range(w)):
        if field[i][j]=="
            r[i][j]=0
        elif j==w-1:
            r[i][j]=1
        else:
            r[i][j]=r[i][j+1]+1

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

for i in reversed(range(h)):
    for j in range(w):
        if field[i][j]=="
            d[i][j]=0
        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):
        tmp=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
        ans=max(ans,tmp)
print(ans)

Solution (Python):
h, w = map(int, input().split())
grid = ['
for _ in range(h):
    grid.append('
grid.append('
lgrid = [[0 for _ in range(w+2)] for _ in range(h+2)]
rgrid = [[0 for _ in range(w+2)] for _ in range(h+2)]
dgrid = [[0 for _ in range(w+2)] for _ in range(h+2)]
ugrid = [[0 for _ in range(w+2)] for _ in range(h+2)]
for i in range(1, h+1):
    for j in range(1, w+1):
        if grid[i][j] == '
            lgrid[i][j] = 0
            ugrid[i][j] = 0
        else:
            lgrid[i][j] = lgrid[i][j-1] + 1
            ugrid[i][j] = ugrid[i-1][j] + 1
        if grid[i][w+1-j] == '
            rgrid[i][w+1-j] = 0
        else:
            rgrid[i][w+1-j] = rgrid[i][w+2-j] + 1
        if grid[h+1-i][j] == '
            dgrid[h+1-i][j] = 0
        else:
            dgrid[h+1-i][j] = dgrid[h+2-i][j] + 1        
cnt = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        tmp = lgrid[i][j]+rgrid[i][j]+ugrid[i][j]+dgrid[i][j] - 3
        cnt = max(cnt, tmp)
print(cnt)

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

    b = [[0] * (w + 2) for _ in range(h + 2)]
    for hi in range(h + 2):
        for wi in range(w + 2):
            if s[hi][wi] == ".":
                b[hi][wi] = 1

    u = [[0] * (w + 2) for _ in range(h + 2)]
    d = [[0] * (w + 2) for _ in range(h + 2)]
    l = [[0] * (w + 2) for _ in range(h + 2)]
    r = [[0] * (w + 2) for _ in range(h + 2)]

    for hi in range(1, h + 1):
        for wi in range(1, w + 1):
            if b[hi][wi]:
                u[hi][wi] = u[hi-1][wi] + 1
                l[hi][wi] = l[hi][wi-1] + 1

    for hi in range(h, 0, -1):
        for wi in range(w, 0, -1):
            if b[hi][wi]:
                d[hi][wi] = d[hi+1][wi] + 1
                r[hi][wi] = r[hi][wi+1] + 1

    ans = 0
    for hi in range(1, h + 1):
        for wi in range(1, w + 1):
            cnt = u[hi][wi] + d[hi][wi] + l[hi][wi] + r[hi][wi] - 3
            ans = max(ans, cnt)

    print(ans)


if __name__ == "__main__":
    main()

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

Left  = [[0] * 2100 for _ in range(2100)]
Right = [[0] * 2100 for _ in range(2100)]
Up    = [[0] * 2100 for _ in range(2100)]
Down  = [[0] * 2100 for _ in range(2100)]

for i in range(H):
	cur = 0
	for j in range(W):
		if S[i][j] == '
			cur = 0
		else:
			cur += 1
		Left[i][j] = cur

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

for j in range(W):
	cur = 0
	for i in range(H):
		if S[i][j] == '
			cur = 0
		else:
			cur += 1
		Up[i][j] = cur

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

cnt = 0
for i in range(H):
	for j in range(W):
		if S[i][j] == '
			continue
		cnt = max(cnt, Left[i][j] + Right[i][j] + Up[i][j] + Down[i][j] - 3)

print(cnt)

Solution (Python):


import sys



















def main():
    mod = 1000000007                  
    inf = float('inf')
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    h, w = mi()
    L = [li() for _ in range(h)]
    memo = [[0] * w for _ in range(h)]
    
    for i in range(h):
        
        cnt = 0
        for j in range(w):
            if L[i][j] == '
                cnt = 0
            else:
                memo[i][j] += cnt
                cnt += 1
        cnt = 1
        
        for j in range(w-1, -1, -1):
            if L[i][j] == '
                cnt = 1
            else:
                memo[i][j] += cnt
                cnt += 1
    
    for j in range(w):
        
        cnt = 0
        for i in range(h):
            if L[i][j] == '
                cnt = 0
            else:
                memo[i][j] += cnt
                cnt += 1
        
        cnt = 1
        for i in range(h-1, -1, -1):
            if L[i][j] == '
                cnt = 1
            else:
                memo[i][j] += cnt
                cnt += 1
    print(max([max(line) for line in memo]) - 1)    



if __name__ == "__main__":
    main()

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

for i in range(H):
    for j, x in enumerate(list(input())):        
        if x == "
            s = 0
        else:
            s = 1
        d[i][j] = s


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

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

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

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

for i in range(H):
    for j in range(W):
        
        if d[i][j]:
            if j == 0:
                L[i][j] = 1            
            else:
                L[i][j] = L[i][j-1] + 1
        else:
            L[i][j] = 0
        
        
        rj = W - j - 1
        if d[i][rj]:
            if rj == W-1:
                R[i][rj] = 1            
            else:
                R[i][rj] = R[i][rj+1] + 1
        else:
            R[i][rj] = 0
        
        
        if d[i][j]:
            if i == 0:
                U[i][j] = 1            
            else:
                U[i][j] = U[i-1][j] + 1
        else:
            U[i][j] = 0
     
        
        di = H - i - 1
        if d[di][j]:
            if di == H-1:
                D[di][j] = 1            
            else:
                D[di][j] = D[di+1][j] + 1
        else:
            D[di][j] = 0

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

Solution (Python):

import numpy as np

h, w = map(int, input().split())



g = np.zeros((h+2,w+2),dtype=np.int64)
for i in range(h):
    grid = np.array(list(input()))
    g[i+1, 1:w+1] = (grid=='.')


gW = np.copy(g)
gW = np.ravel(gW)
tWLeft = np.arange((w+2)*(h+2))
tWRight = np.copy(tWLeft)

tWLeft[gW==1] = 0
tWRight[gW[::-1]==1] = 0

np.maximum.accumulate(tWLeft, out=tWLeft)
np.maximum.accumulate(tWRight, out=tWRight)

tWRight = len(tWRight) - 1 - tWRight[::-1]

tW = tWRight-tWLeft-1
tW[gW==0] = 0
tW = tW.reshape(h+2, w+2)


gH = np.copy(g.T)
gH = np.ravel(gH)
tHLeft = np.arange((w+2)*(h+2))
tHRight = np.copy(tHLeft)

tHLeft[gH==1] = 0
tHRight[gH[::-1]==1] = 0

np.maximum.accumulate(tHLeft, out=tHLeft)
np.maximum.accumulate(tHRight, out=tHRight)

tHRight = len(tHRight) - 1 - tHRight[::-1]

tH = tHRight-tHLeft-1
tH[gH==0] = 0
tH = tH.reshape(w+2, h+2).T



print(np.max(tW+tH-1))


'''

tblW = np.zeros((h, w),dtype=np.int64)
for i in range(h):
    for j in range(w):
        if grid[i, j]=='
            continue
        else:
            cnt = 1
            while j+cnt<w and grid[i, j+cnt]!='
                cnt += 1
            tblW[i, j:j+cnt] = cnt
print(tblW)
    

tblH = np.zeros((h, w),dtype=np.int64)
for j in range(w):
    for i in range(h):
        if grid[i, j]=='
            continue
        else:
            cnt = 1
            while i+cnt<h and grid[i+cnt, j]!='
                cnt += 1
            tblH[i:i+cnt, j] = cnt
print(tblH)

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

print(ans)
'''

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

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

for i in range(h):
    done = [0] * w
    for j in range(w):
        if lst[i][j] == '
            continue
        if done[j]:
            continue
        k = 0
        while lst[i][j+k] != '
            done[j+k] = 1
            k += 1  
            if j+k > w-1:
                break
        for l in range(k):
            H[i][j+l] = k


for j in range(w):
    done = [0] * h
    for i in range(h):
        if lst[i][j] == '
            continue
        if done[i]:
            continue
        k = 0
        while lst[i+k][j] != '
            done[i+k] = 1
            k += 1  
            if i+k > h-1:
                break
        for l in range(k):
            W[i+l][j] = k

ans = 0
for i in range(h):
    for j in range(w):
        if lst[i][j] != '
            ans = max(ans, H[i][j] + W[i][j] - 1)

print(ans)

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

grid = []

for i in range(H):
    s = input()
    r = []
    for j, x in enumerate(s):
        r.append(x)

    grid.append(r)


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

for r in range(H):
    idx = 0

    while idx < W:
        if grid[r][idx] == '.' and (idx == 0 or grid[r][idx - 1] == '
            cnt = 1
            st = idx
            if idx == W - 1 or grid[r][idx + 1] == '
                W_cnt[r][idx] = 1
        elif grid[r][idx] == '.' and (idx == W - 1 or grid[r][idx + 1] == '
            cnt += 1
            for i in range(st, idx + 1):
                W_cnt[r][i] = cnt
        elif grid[r][idx] == '.':
            cnt += 1
        elif grid[r][idx] == '
            pass

        idx += 1

for c in range(W):
    idx = 0

    while idx < H:
        if grid[idx][c] == '.' and (idx == 0 or grid[idx - 1][c] == '
            cnt = 1
            st = idx
            if idx == H - 1 or grid[idx + 1][c] == '
                H_cnt[idx][c] = 1
        elif grid[idx][c] == '.' and (idx == H - 1 or grid[idx + 1][c] == '
            cnt += 1
            for i in range(st, idx + 1):
                H_cnt[i][c] = cnt
        elif grid[idx][c] == '.':
            cnt += 1
        elif grid[idx][c] == '
            pass

        idx += 1

max_ = 0
for r in range(H):
    for c in range(W):
        max_ = max(max_, W_cnt[r][c] + H_cnt[r][c] - 1)

print(max_)

Solution (Python):
h, w = map(int, input().split())
G = []
l_w = [[0] * w for i in range(h)]
l_h = [[0] * w for i in range(h)]
for i in range(h):
    G.append(input())
for i in range(h):
    cnt = 0
    for j in range(w):
        if G[i][j] == ".":
            cnt += 1
            l_w[i][j] = cnt
        else:
            cnt = 0
    tmp = 0
    for j in range(w - 1, -1, -1):
        if l_w[i][j] > 0 and tmp == 0:
            tmp = l_w[i][j]
        elif l_w[i][j] > 0 and tmp > 0:
            l_w[i][j] = tmp
        elif l_w[i][j] == 0 and tmp > 0:
            tmp = 0
for i in range(w):
    cnt = 0
    for j in range(h):
        if G[j][i] == ".":
            cnt += 1
            l_h[j][i] = cnt
        else:
            cnt = 0
    tmp = 0
    for j in range(h - 1, -1, -1):
        if l_h[j][i] > 0 and tmp == 0:
            tmp = l_h[j][i]
        elif l_h[j][i] > 0 and tmp > 0:
            l_h[j][i] = tmp
        elif l_h[j][i] == 0 and tmp > 0:
            tmp = 0
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, l_w[i][j] + l_h[i][j] - 1)
print(ans)