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(sample_file = ''):

    """ convenient functions
    
    
    
    
    
    """

    """convenient decorator
    
    
        
        
        
        
        
        
        
        
        
        
    """
    
    
    import sys
    sys.setrecursionlimit(10**7)
    from itertools import accumulate, combinations, permutations, product 
    
    from math import factorial, ceil, floor, sqrt
    def factorize(n):
        """return the factors of the Arg and count of each factor
        
        Args:
            n (long): number to be resolved into factors
        
        Returns:
            list of tuples: factorize(220) returns [(2, 2), (5, 1), (11, 1)]
        """
        fct = []  
        b, e = 2, 0  
        while b * b <= n:
            while n % b == 0:
                n = n // b
                e = e + 1
            if e > 0:
                fct.append((b, e))
            b, e = b + 1, 0
        if n > 1:
            fct.append((n, 1))
        return fct
    def combinations_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        
        if n < 0 or r < 0:
            raise Exception('combinations_count(n, r) not defined when n or r is negative')
        if n - r < r: r = n - r
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]
        for p in range(2,r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1,r,p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot
        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])
        return result
    def combinations_with_replacement_count(n, r):
        """Return the number of selecting r pieces of items from n kinds of items allowing individual elements to be repeated more than once.
        
        Args:
            n (long): number
            r (long): number
        
        Raises:
            Exception: not defined when n or r is negative
        
        Returns:
            long: number
        """
        if n < 0 or r < 0:
            raise Exception('combinations_with_replacement_count(n, r) not defined when n or r is negative')
        elif n == 0:
            return 1
        else:
            return combinations_count(n + r - 1, r)
    from bisect import bisect_left, bisect_right
    from collections import deque, Counter, defaultdict 
    from heapq import heapify, heappop, heappush, heappushpop, heapreplace,nlargest,nsmallest 
    from copy import deepcopy, copy 
    import operator
    from operator import itemgetter 
    
    
    from functools import reduce, lru_cache
    def chmin(x, y):
        """change minimum
        if x > y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current minimum value
            y (long): potential minimum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x > y:
            x = y
            return (x, True)
        else:
            return (x, False)
    def chmax(x, y):
        """change maximum
        if x < y, x = y and return (x, True).
        convenient when solving problems of dp[i]
        
        Args:
            x (long): current maximum value
            y (long): potential maximum value
        
        Returns:
            (x, bool): (x, True) when updated, else (x, False)
        """
        if x < y:
            x = y
            return (x, True)
        else:
            return (x, False)

    from fractions import gcd 
    def gcds(numbers):
        return reduce(gcd, numbers)
    def lcm(x, y):
        return (x * y) // gcd(x, y)
    def lcms(numbers):
        return reduce(lcm, numbers, 1)
    def make_divisors(n, reversed=False):
        """create list of divisors
        
        Args:
            number (int): number from which list of divisors is created
            reversed (bool, optional): ascending order if False. Defaults to False.
        
        Returns:
            list: list of divisors
        """
        divisors = set()
        for i in range(1, int(n**0.5)+1):
            if n % i == 0:
                divisors.add(i)
                divisors.add(n//i)
        return sorted(list(divisors),reverse=reversed)
    
    
    
    INF = 10 ** 18
    MOD = 10 ** 9 + 7
    modpow = lambda a, n, p = MOD: pow(a, n, p) 
    def modinv(a, p = MOD):
        
        
        return modpow(a, p-2, p)
    def modinv_list(n, p = MOD):
        if n <= 1:
            return [0,1][:n+1]
        else:
            inv_t = [0,1]
            for i in range(2, n+1):
                inv_t += [inv_t[p % i] * (p - int(p / i)) % p]
            return inv_t
    def modfactorial_list(n, p = MOD):
        if n == 0:
            return [1]
        else:
            l = [0] * (n+1)
            tmp = 1
            for i in range(1, n+1):
                tmp = tmp * i % p
                l[i] = tmp
            return l
    def modcomb(n, k, fac_list = [], p = MOD):
        
        
        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        if len(fac_list) <= n:
            a = factorial(n) % p
            b = factorial(k) % p
            c = factorial(n-k) % p
        else:
            a = fac_list[n]
            b = fac_list[k]
            c = fac_list[n-k]
        return (a * modpow(b, p-2, p) * modpow(c, p-2, p)) % p
    def modadd(a, b, p = MOD):
        return (a + b) % MOD
    def modsub(a, b, p = MOD):
        return (a - b) % p
    def modmul(a, b, p = MOD):
        return ((a % p) * (b % p)) % p
    def moddiv(a, b, p = MOD):
        return modmul(a, modpow(b, p-2, p))

    class UnionFindTree:
        """union find tree class
        TODO: fix this description...
        how to use (example):
        >>  uf = UnionFindTree(N) 
        >>  if uf.find_root(a) == uf.find_root(b):
        >>      do something
        >>  else:
        >>      do something
        >>      uf.unite(a, b)
        """
        def __init__(self, N):
            self.root = [-1] * (N+1)
            self.rank   = [0]  * (N+1)
            self.connected_num = [1] * (N+1)
    
        def find_root(self,x):
            root = self.root
            while root[x] != -1:
                x = root[x]
            return x
    
        def unite(self,x,y):
            root = self.root
            rank = self.rank
            connected_num = self.connected_num
            find_root = self.find_root
    
            rx = find_root(x)
            ry = find_root(y)
            if rx != ry:
                if rank[rx] < rank[ry]:
                    root[rx] = ry
                    rx,ry = ry,rx
                else:
                    if rank[rx] == rank[ry]:
                        rank[rx] += 1
                    root[ry] = rx       
                connected_num[rx] += connected_num[ry]

    
    
    
    
    

    def BellmanFord(N, M, ABC, vertex_start, vertex_end, value_if_inf = -1, find_shortest = False):
        """to calculate furthest or shortest length between vertex_start and vertex_end using BellmanFord algorithm
        
        Args:
            N (int): number of vertices
            M (int): number of edges
            ABC (list): [(ai, bi, ci) for _ in range(N)] where i-th edge is directed from vertex ai to vertex bi and the length is ci 
            vertex_start (int): start vertex. usually use 0.
            vertex_end (int): end vertex. usually use N-1.
            value_if_inf (int or string as you like, optional): value you want when the furthest (or shortest) distance is infinite (or -infinite). Defaults to -1.
            find_shortest (bool, optional): choose False to find furthest path. Defaults to False.
        
        Returns:
            int or string: normally int (but can be str if you set value_if_inf to str)
            
        Example:
                N, M, P = R()
                ABC = [R() for _ in range(M)]
                ABC = [(a-1, b-1, c-P) for a, b, c in ABC]
                print(BellmanFord(N, M, ABC, 0, N-1, value_if_inf = 'inf'))

        """

        def make_reachable_list(N, M, ABC, vertex_start, vertex_end):
            reachable_to_direct = defaultdict(list)
            reachable_from_direct = defaultdict(list)
            reachable_from_start = [False] * N
            reachable_to_end = [False] * N
            reachable_from_start[vertex_start] = True
            reachable_to_end[vertex_end] = True
            reachable_from_both_sides = [False] * N
            dfs_from_start = []
            dfs_to_end = []
            for a, b, c in ABC:
                reachable_to_direct[a].append(b)
                reachable_from_direct[b].append(a)
                if a == vertex_start:
                    dfs_from_start.append(b)
                    reachable_from_start[b] = True
                if b == vertex_end:
                    dfs_to_end.append(a)
                    reachable_to_end[a] = True
            while dfs_from_start:
                v = dfs_from_start.pop()
                for i in reachable_to_direct[v]:
                    if not reachable_from_start[i]:
                        reachable_from_start[i] = True
                        dfs_from_start.append(i)
            while dfs_to_end:
                v = dfs_to_end.pop()
                for i in reachable_from_direct[v]:
                    if not reachable_to_end[i]:
                        reachable_to_end[i] = True
                        dfs_to_end.append(i)
            for i in range(N):
                reachable_from_both_sides[i] = reachable_from_start[i] and reachable_to_end[i]
            return reachable_from_both_sides
        
        reachable_from_both_sides = make_reachable_list(N, M, ABC, vertex_start, vertex_end)
        
        if find_shortest:
            dist = [INF for i in range(N)]
        else:
            dist = [-INF for i in range(N)]
        
        dist[vertex_start] = 0
        for i in range(N):
            updated = False
            for a, b, c in ABC:
                if not reachable_from_both_sides[a]:
                    continue
                elif find_shortest:
                    update_condition = dist[a] + c < dist[b]
                else:
                    update_condition = dist[a] + c > dist[b]
                if dist[a] != INF and update_condition:
                    dist[b] = dist[a] + c
                    updated = True
                    if i == N-1:
                        return value_if_inf
            if not updated:
                break
        return dist[vertex_end]

    """ initialize variables and set inputs
    
        
        
            
            
    
        
        
        
        
        
        
        
    
        
        
        
        
    
        
        
    """

    
    r = lambda: sys.stdin.readline().strip()
    r_int = lambda: int(r())
    r_float = lambda: float(r())
    R = lambda: list(map(int, r().split()))
    R_map = lambda: map(int, r().split())
    R_float = lambda: list(map(float, r().split()))
    R_tuple = lambda: tuple(map(int, r().split()))

    """ how to treat input
    
    
    
    
    
    
    
    """

    
    if sample_file:
        sys.stdin = open(sample_file)
        
    
    

    H, W = R()
    S = [r() for _ in range(H)]
    dp = [[0] * W for _ in range(H)]
    
    for w in range(W):
        for h in range(H):
            if h == 0:
                m = 0
            if S[h][w] == '
                if S[h][w] != '
                    m += 1
                    h = h+1
                for i in range(m):
                    dp[h-i-1][w] += m
                m = 0
            else:
                m += 1
    for h in range(H):
        for w in range(W):
            if w == 0:
                m = 0
            if S[h][w] == '
                if S[h][w] != '
                    m += 1
                    w = w+1
                for i in range(m):
                    dp[h][w-i-1] += m
                m = 0
            else:
                m += 1
    
    print(max([flatten for inner in dp for flatten in inner])-1)
    
    
    
    

    """memo: how to use defaultdict of list
    
    Dic = defaultdict(list)
    
    Dic[x].append(y)
    
    for k, v in Dic.items():
    """
    
    """memo: how to solve binary problems
    
    >>> a = 5
    >>> bin_str_a = format(a, '
    >>> print(bin_str_a)
    0b0101 
    """
    
    """memo: how to solve the problem
    creating simple test/answer
    greed
    simple dp
    graph
    """

if __name__ == '__main__':
    main()

Solution (Python):
h,w=map(int,input().split())
s=[input() for _ in range(h)]
yoko=[[0]*w for _ in range(h)]
tate=[[0]*w for _ in range(h)]
count=0
for i in range(h):
    a=[0]
    for j in range(w):
        if s[i][j]=="
            a.append(j+1)
    a.append(w+1)
    for j in range(1,len(a)):
        for k in range(a[j-1],a[j]-1):
            yoko[i][k]=a[j]-a[j-1]-1
for i in range(w):
    a=[0]
    for j in range(h):
        if s[j][i]=="
            a.append(j+1)
    a.append(h+1)
    for j in range(1,len(a)):
        for k in range(a[j-1],a[j]-1):
            tate[k][i]=a[j]-a[j-1]-1

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

Solution (Python):
import numpy as np

H, W = map(int, input().split())
grid = np.array([list(input()) for i in range(H)]) == '.'
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
for i in range(1, H):
    U[i] = (U[i-1] + 1) * grid[i-1]
for i in reversed(range(H-1)):
    D[i] = (D[i+1] + 1) * grid[i+1]
for i in range(1, W):
    L[:, i] = (L[:, i-1] + 1) * grid[:, i-1]
for i in reversed(range(W-1)):
    R[:, i] = (R[:, i+1] + 1) * grid[:, i+1]
print(((U + D + L + R) * grid).max() + 1)

Solution (Python):
import sys



		
def main():
	h , w = map(int, input().split())
	mm=[input() for _ in range(h)]
	
	rr_lr=[[0]*(w) for _ in range(h)]
	rr_rl=[[0]*(w) for _ in range(h)]
	rr_ud=[[0]*(w) for _ in range(h)]
	rr_du=[[0]*(w) for _ in range(h)]
							
	for hi in range(h):
		ll=0
		rl=0
		for wj in range(w):
			if mm[hi][wj] == '.':
				ll+=1
				rr_lr[hi][wj]=ll
			else:
				ll=0				
				
			if mm[hi][w-1-wj] == '.':
				rl+=1
				rr_rl[hi][w-1-wj]=rl
			else:
				rl=0				
					
	for wi in range(w):
		ll=0
		rl=0
		for hj in range(h):
			if mm[hj][wi] == '.':
				ll+=1
				rr_ud[hj][wi]=ll
			else:
				ll=0
				
			if mm[(h-1)-hj][wi] == '.':
				rl+=1
				rr_du[(h-1)-hj][wi]=rl
			else:
				rl=0
				
	ret=0
	for i in range(w):
		for j in range(h):
			vv=rr_lr[j][i]-3
			vv+=rr_rl[j][i]
			vv+=rr_du[j][i]
			vv+=rr_ud[j][i]
			ret = max(ret,vv)
	
	return ret

	


if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

def aaa(s):
    i = 0
    l = len(s)
    o = []
    while True:
        if i == l:
            break
        if s[i] == ".":
            n = 0
            while i < l and s[i] == '.':
                i += 1
                n += 1
            o += [n] * n
        else:
            o += [0]
            i += 1
    return o

Hor = [0]*H
y = 0
while y != H:
    Hor[y] = aaa(S[y])
    y += 1

Ver = [0]*W
x = 0
while x != W:
    _ = 0
    s = [0] * H
    while _ != H:
        s[_] = S[_][x]
        _ += 1
    Ver[x] = aaa(s)
    x += 1

ans = 1
x = 0
while x != W:
    y = 0
    while y != H:
        h = Hor[y][x]
        if h:
            v = Ver[x][y]
            ans = max(ans,h+v-1)
        y += 1
    x += 1

print(ans)

Solution (Python):
import numpy as np
import sys
input = sys.stdin.readline
def main():
    H,W = map(int,input().split())
    S = np.array([list(input().rstrip()) for _ in range(H)]) == "."
    L = np.zeros((H,W),dtype=int)
    R = np.zeros((H,W),dtype=int)
    U = np.zeros((H,W),dtype=int)
    D = np.zeros((H,W),dtype=int)
    
    for i in range(H):
        U[i] = (U[i-1]+1)*S[i]
        D[-i-1] = (D[-i]+1)*S[-i-1]  
    for j in range(W):
        L[:,j] = (L[:,j-1]+1)*S[:,j]
        R[:,-j-1] = (R[:,-j]+1)*S[:,-j-1]

    su = L+R+U+D
    
    print(np.amax(su)-3)
if __name__ == '__main__':
    main()

Solution (Python):
h,w=map(int,input().split())
grid=[None]*h
for i in range(h):
  grid[i]=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)]
U=[[0 for i in range(w)] for j in range(h)]
D=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  if grid[i][0]=="
    L[i][0]=0
  else:
    L[i][0]=1
  for l in range(1,w):
    if grid[i][l]=="
      L[i][l]=0
    else:
      L[i][l]=L[i][l-1]+1
      
  if grid[i][-1]=="
    R[i][-1]=0
  else:
    R[i][-1]=1
  for r in range(w-2,-1,-1):
    if grid[i][r]=="
      R[i][r]=0
    else:
      R[i][r]=R[i][r+1]+1
      
for j in range(w):
  if grid[0][j]=="
    U[0][j]=0
  else:
    U[0][j]=1
  for u in range(1,h):
    if grid[u][j]=="
      U[u][j]=0
    else:
      U[u][j]=U[u-1][j]+1
      
  if grid[-1][j]=="
    D[-1][j]=0
  else:
    D[-1][j]=1
  for d in range(h-2,-1,-1):
    if grid[d][j]=="
      D[d][j]=0
    else:
      D[d][j]=D[d+1][j]+1
      
ans=0
for i in range(h):
  for j in range(w):
    ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j])

print(ans-3)

Solution (Python):
h,w=map(int,input().split())
grid=[None]*h

for i in range(h):
  grid[i]=input()

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  s=grid[i]
  left=0
  right=0
  while left<len(s):
    if s[left]=="
      left+=1
      right=left
      continue
    while right+1<w and s[right+1]==".":
      right+=1
  
    for j in range(left,right+1):
      yoko[i][j]=right-left
      
    left=right+1
    right=left
    
for i in range(w):
  up=0
  down=0
  while up<h:
    if grid[down][i]=="
      up+=1
      down=up
      continue
    while down+1<h and grid[down+1][i]==".":
      down+=1
    for j in range(up,down+1):
      tate[j][i]=down-up
    up=down+1
    down=up
    
ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]==".":
      ans=max(ans,tate[i][j]+yoko[i][j])
      
print(ans+1)

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

h, w = map(int, input().split())
s = [list(input().replace('\n', '')) for _ in range(h)]

import numpy as np


up = np.zeros((h, w))
down = np.zeros((h, w))
right = np.zeros((h, w))
left = np.zeros((h, w))

s = (np.array(s)==".").astype(np.int)

for i in range(h):
    down[-i-1] = (down[-i] + 1)*s[-i-1]
    up[i] = (up[i-1] + 1)*s[i]
    

for i in range(w):
    left[:,-i-1] = (left[:,-i] + 1)*s[:,-i-1]
    right[:,i] = (right[:,i-1] + 1)*s[:,i]
    
ans = np.max(up+down+left+right-3)
print(int(ans))

Solution (Python):
h, w = map(int, input().split(' '))
s = [''] * h
l = [[0] * w] * h
r = [[0] * w] * h
u = [[0] * w] * h
d = [[0] * w] * h


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




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

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

for j in range(w):
  for i in range(h-1, -1, -1):
    c = s[i][j]
    
    if c == '
      u[i][j] = 0
    else:
      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):
    total = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
    if ans < total:
      ans = total

print(ans)

Solution (Python):
H, W = map(int, input().split())
src = []
for i in range(H):
    src.append(list(input()))
L = [[0]*W for i in range(H)]
R = [[0]*W for i in range(H)]
U = [[0]*W for i in range(H)]
D = [[0]*W for i in range(H)]

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

for h in range(H):
    for w in range(W)[::-1]:
        if src[h][w] == '
            R[h][w] = 0
        elif w == W - 1:
            R[h][w] = 1
        else:
            R[h][w] += R[h][w + 1] + 1

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

for w in range(W):
    for h in range(H)[::-1]:
        if src[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 i in range(H):
    for j in range(W):
        tmp = R[i][j] + L[i][j] + U[i][j] + D[i][j] - 3
        ans = max(ans, tmp)
print(ans)

Solution (Python):
import bisect
h,w=map(int,input().split())
g = [['
for i in range(h):
  g[i+1][1:-1] = list(input())
L=[[0]*(w+2) for i in range(h+2)]
R=[[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(h+2):
  for j in range(w+2):
    if g[i][j]=="
      L[i][j]=0
    else:
      L[i][j]=L[i][j-1]+1
for i in range(h+2):
  for j in range(w+1,-1,-1):
    if g[i][j]=="
      R[i][j]=0
    else:
      R[i][j]=R[i][j+1]+1
for i in range(h+2):
  for j in range(w+2):
    if g[i][j]=="
      D[i][j]=0
    else:
      D[i][j]=D[i-1][j]+1
for i in range(h+1,-1,-1):
  for j in range(w+2):
    if g[i][j]=="
      U[i][j]=0
    else:
      U[i][j]=U[i+1][j]+1
Max=0
for i in range(h+2):
  for j in range(w+2):
    a=0
    a=L[i][j]+R[i][j]+D[i][j]+U[i][j]
    if a>Max:
      Max=a
print(Max-3)

Solution (Python):
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)


def calc(x, isTrans):
    if isTrans:
        y = np.copy(x.T)
    else:
        y = np.copy(x)

    for i in range(len(y)):
        xxx = np.copy(y[i])
        tmp_l = np.arange(len(xxx))
        tmp_l[xxx > 0] = 0
        np.maximum.accumulate(tmp_l, out=tmp_l)
        left = tmp_l

        xxx_reverse = xxx[::-1]
        tmp_r = np.arange(len(xxx_reverse))
        tmp_r[xxx_reverse > 0] = 0
        np.maximum.accumulate(tmp_r, out=tmp_r)
        right = len(xxx)-tmp_r[::-1]-1

        y[i] = right-left-1
        y[i][xxx == 0] = 0

    if isTrans:
        return np.transpose(y)
    else:
        return y


if __name__ == "__main__":
    h, w = map(int, readline().split())
    room = np.zeros((h+2, w+2), dtype=np.int)
    for i in range(1, h+1):
        room[i][1:-1] = [0 if i == "

    a = calc(room, True)
    b = calc(room, False)
    ans = (a + b).max() - 1
    print(ans)

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


for y in range(H):
    prev_x = -1
    for x in range(W):
        if C[y][x] == '
            for i in range(x - prev_x - 1):
                dp[y][i + prev_x + 1] = x - prev_x - 1
            prev_x = x
        if x == W - 1:
            for i in range(x - prev_x):
                dp[y][i + prev_x + 1] = x - prev_x
             

ans = 0

for x in range(W):
    prev_y = -1
    for y in range(H):
        if C[y][x] == '
            for i in range(y - prev_y - 1):
                dp[i + prev_y + 1][x] += y - prev_y - 1
                ans = max(ans, dp[i + prev_y + 1][x] - 1) 
            prev_y = y
        if y == H - 1:
            for i in range(y - prev_y):
                dp[i + prev_y + 1][x] += y - prev_y
                ans = max(ans, dp[i + prev_y + 1][x] - 1) 


print(ans)

Solution (Python):
import numpy as np

H, W = map(int, input().split())
S = []
for h in range(H):
  S.append(list(map(lambda s:0 if s=='
S = np.array(S)
 
l,r,u,d = [np.zeros([H,W], dtype=int) for _ in range(4)]

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

for h in range(H):
  u[h] = (u[h-1]+1)*S[h]
  d[-h-1] = (d[-h]+1)*S[-h-1]
  
ans = np.max((l+r+u+d-3)*S)

print(ans)

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

for i in range(h):
    cnt = 0
    now = 0
    for j in range(w):
        if s[i][j] == ".":
            cnt += 1
        else:
            for k in range(now,j+1):
                yoko[i][k] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        yoko[i][k] = cnt
for i in range(w):
    cnt = 0
    now = 0
    for j in range(h):
        if s[j][i] == ".":
            cnt += 1
        else:
            for k in range(now,j):
                tate[k][i] = cnt
            cnt = 0
            now = j+1
    for k in range(now,j+1):
        tate[k][i] = cnt
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,tate[i][j]+yoko[i][j]-1)
print(ans)

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

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

a = []
for i in range(H):
    a.append(str(input()))

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

for i in range(H):
    cur = 0
    for j in range(W):
        if a[i][j] == "
            cur = 0
            U[i][j] = 0
        else:
            cur += 1
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] += U[i-1][j] + 1
        L[i][j] = cur

ans = 0
for i in reversed(range(H)):
    cur = 0
    for j in reversed(range(W)):
        if a[i][j] == "
            cur = 0
            D[i][j] = 0
        else:
            cur += 1
            if i == (H-1):
                D[i][j] = 1
            else:
                D[i][j] += D[i+1][j] + 1
        R[i][j] = cur
        if L[i][j] + R[i][j] + D[i][j] + U[i][j] -3 > ans:
            ans = L[i][j] + R[i][j] + D[i][j] + U[i][j] -3

print(ans)

Solution (Python):
def add(dp, n, l):
    t = 0
    for v in range(1, len(l)):
        y = l[v]
        x = l[v-1]
        while t != y:
            dp[n][t] += y - 1 - x
            t += 1
        t += 1


H,W = [int(_) for _ in input().split()]
s = []
b = []
c = []
for _ in range(H):
    s.append(input())
for i in range(H):
    a = []
    a.append(0)
    for j in range(W):
        if s[i][j] == '
            a.append(j+1)
    a.append(W+1)
    b.append(a)
for j in range(W):
    a = []
    a.append(0)
    for i in range(H):
        if s[i][j] == '
            a.append(i+1)
    a.append(H+1)
    c.append(a)
dp = [[0 for _ in range(W+2)] for _ in range(H+2)]
dp2 = [[0 for _ in range(H+2)] for _ in range(W+2)]
for i in range(len(b)):
    add(dp, i+1, b[i])
for i in range(W+2):
    for j in range(H+2):
        dp2[i][j] = dp[j][i]
for i in range(len(c)):
    add(dp2, i+1, c[i])
ans = 0
for i in range(1, W+1):
    for j in range(1, H+1):
        ans = max(ans, dp2[i][j])
print(ans-1)

Solution (Python):
def add(n, l):
    global dp
    t = 0
    for v in range(1, len(l)):
        y = l[v]
        x = l[v-1]
        while t != y:
            dp[n][t] += y - 1 - x
            t += 1
        t += 1

def add2(n, l):
    global dp2
    t = 0
    for v in range(1, len(l)):
        y = l[v]
        x = l[v-1]
        while t != y:
            dp2[n][t] += y - 1 - x
            t += 1
        t += 1


H,W = [int(_) for _ in input().split()]
s = []
b = []
c = []
for _ in range(H):
    s.append(input())
for i in range(H):
    a = []
    a.append(0)
    for j in range(W):
        if s[i][j] == '
            a.append(j+1)
    a.append(W+1)
    b.append(a)
for j in range(W):
    a = []
    a.append(0)
    for i in range(H):
        if s[i][j] == '
            a.append(i+1)
    a.append(H+1)
    c.append(a)
dp = [[0 for _ in range(W+2)] for _ in range(H+2)]
dp2 = [[0 for _ in range(H+2)] for _ in range(W+2)]
for i in range(len(b)):
    add(i+1, b[i])
for i in range(W+2):
    for j in range(H+2):
        dp2[i][j] = dp[j][i]
for i in range(len(c)):
    add2(i+1, c[i])
for i in range(H+2):
    for j in range(W+2):
        dp[i][j] = dp2[j][i]
ans = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        ans = max(ans, dp[i][j])
print(ans-1)