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 = (int(x) for x in input().split())

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

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


for i in range(h):
    mi = -1
    count = 0
    for j in range(w):
        this_s = s[i][j]
        
        if this_s == ".":
            count += 1
            if mi == -1:
                mi = j
        if this_s == "
            y[i][mi:j] = [count] * (j-mi)
            mi = -1
            count = 0
    else:
        if not(mi == -1):
            y[i][mi:w] = [count] * (w-mi)

        

for j in range(w):
    mi = -1
    count = 0
    for i in range(h):
        this_s = s[i][j]
        
        if this_s == ".":
            count += 1
            if mi == -1:
                mi = i
        if this_s == "
            for k in range(mi,i):
                t[k][j] = count
            mi = -1
            count = 0
    else:
        if not(mi == -1):
            
            for k in range(mi,h):
                t[k][j] = count


count = 0
for i in range(h):
    for j in range(w):
        this_count = y[i][j] + t[i][j] -1
        count = max(count, this_count)
        
print(count)

Solution (Python):
import numpy as np
import sys


def main():
    sin = sys.stdin.buffer
    H, W = map(int, sin.readline().split())
    a = np.frombuffer(sin.read(H * (W + 1)), dtype='B') == ord('.')
    a = a.reshape((H, W + 1))[:, :-1]

    L = np.empty((H, W), dtype='i4')
    R = np.empty((H, W), dtype='i4')
    T = np.empty((H, W), dtype='i4')
    B = np.empty((H, W), dtype='i4')
    T[0] = a[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * a[i]
    B[-1] = a[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * a[i]
    L[:, 0] = a[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * a[:, i]
    R[:, -1] = a[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * a[:, i]

    print((T + B + L + R - 3).max())


main()

Solution (Python):
import numpy as np
import sys


def main():
    sin = sys.stdin.buffer
    H, W = map(int, sin.readline().split())
    a = np.frombuffer(sin.read(H * (W + 1)), dtype='B') == ord('.')
    a = a.reshape((H, W + 1))
    L = np.empty((H, W + 1), dtype='i4')
    R = np.empty((H, W + 1), dtype='i4')
    T = np.empty((H, W + 1), dtype='i4')
    B = np.empty((H, W + 1), dtype='i4')

    T[0] = a[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * a[i]
    B[H - 1] = a[H - 1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * a[i]
    L[:, 0] = a[:, 0]
    for i in range(1, W + 1):
        L[:, i] = (L[:, i - 1] + 1) * a[:, i]
    R[:, W] = a[:, W]
    for i in range(W - 1, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * a[:, i]

    print((T + B + L + R - 3).max())


main()

Solution (Python):



def main():
    h, w = map(int, input().split())
    grids = [list(input()) for _ in range(h)]
    up = [[1 for __ in range(w)] for _ in range(h)]
    down = [[1 for __ in range(w)] for _ in range(h)]
    left = [[1 for __ in range(w)] for _ in range(h)]
    right = [[1 for __ in range(w)] for _ in range(h)]
    ans = 0

    for i in range(h - 1, -1, -1):
        for j in range(w):
            if (grids[i][j] == '.') and (i < h - 1):
                up[i][j] = up[i + 1][j] + 1
            elif grids[i][j] == '
                up[i][j] = 0

    for i in range(h):
        for j in range(w):
            if (grids[i][j] == '.') and (i > 0):
                down[i][j] = down[i - 1][j] + 1
            elif grids[i][j] == '
                down[i][j] = 0

    for i in range(h):
        for j in range(w - 1, -1, -1):
            if (grids[i][j] == '.') and (j < w - 1):
                left[i][j] = left[i][j + 1] + 1
            elif grids[i][j] == '
                left[i][j] = 0

    for i in range(h):
        for j in range(w):
            if (grids[i][j] == '.') and (j > 0):
                right[i][j] = right[i][j - 1] + 1
            elif grids[i][j] == '
                right[i][j] = 0

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):



def main():
    h, w = map(int, input().split())
    grids = [list(input()) for _ in range(h)]
    up = [[1 for __ in range(w)] for _ in range(h)]
    down = [[1 for __ in range(w)] for _ in range(h)]
    left = [[1 for __ in range(w)] for _ in range(h)]
    right = [[1 for __ in range(w)] for _ in range(h)]
    ans = 0

    for i in range(h - 1, -1, -1):
        for j in range(w):
            if (grids[i][j] == '.') and (i < h - 1):
                up[i][j] = up[i + 1][j] + 1
            elif grids[i][j] == '
                up[i][j] = 0

    for i in range(h):
        for j in range(w):
            if (grids[i][j] == '.') and (i > 0):
                down[i][j] = down[i - 1][j] + 1
            elif grids[i][j] == '
                down[i][j] = 0

    for i in range(h):
        for j in range(w - 1, -1, -1):
            if (grids[i][j] == '.') and (j < w - 1):
                left[i][j] = left[i][j + 1] + 1
            elif grids[i][j] == '
                left[i][j] = 0

    for i in range(h):
        for j in range(w):
            if (grids[i][j] == '.') and (j > 0):
                right[i][j] = right[i][j - 1] + 1
            elif grids[i][j] == '
                right[i][j] = 0

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

    print(ans)


if __name__ == '__main__':
    main()

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

    H, W = map(int, readline().split())
    C = [[i]*i for i in range(W+1)]
    rW = range(W); rH = range(H)
    S = [readline() for i in rH]
    P = [[0]*W for i in rH]
    for i in rH:
        p = -1
        Si = S[i]
        Pi = P[i]
        for j in rW:
            if Si[j] == '
                c = j - p - 1
                Pi[p+1:j] = C[c]
                p = j
        c = W - p - 1
        Pi[p+1:W] = C[c]

    def gen():
        U = [-1]*W
        V = [0]*W
        for i in rH:
            Si = S[i]; Pi = P[i]
            for j in rW:
                if Si[j] == '
                    yield V[j] + (i - U[j] - 1)
                    V[j] = 0
                    U[j] = i
                else:
                    V[j] = max(V[j], Pi[j])
        for u, v in zip(U, V):
            yield v + (H - u - 1)
    sys.stdout.write("%d\n" % (max(gen()) - 1))
solve()

Solution (Python):
import sys
import numpy as np

h, w = list(map(int, input().split()))
field = np.array([[c == '.' for c in line.rstrip()] for line in sys.stdin], dtype=np.int32)
li, ri, ui, di = (field.copy() for _ in [0] * 4)

for i in range(1, h):
    ui[i] = (ui[i - 1] + 1) * field[i]
    di[h - i - 1] = (di[h - i] + 1) * field[h - i - 1]
field = field.T
li, ri = li.T, ri.T
for j in range(1, w):
    li[j] = (li[j - 1] + 1) * field[j]
    ri[w - j - 1] = (ri[w - j] + 1) * field[w - j - 1]
li, ri = li.T, ri.T
print((li + ri + ui + di).max() - 3)

Solution (Python):
import sys
import numpy as np

h, w = list(map(int, input().split()))
field = np.array([[c == '.' for c in line.rstrip()] for line in sys.stdin], dtype=np.int32)
li, ri, ui, di = (field.copy() for _ in [0] * 4)

for i in range(1, h):
    ui[i] = (ui[i - 1] + 1) * field[i]
    di[h - i - 1] = (di[h - i] + 1) * field[h - i - 1]
for j in range(1, w):
    li[:, j] = (li[:, j - 1] + 1) * field[:, j]
    ri[:, w - j - 1] = (ri[:, w - j] + 1) * field[:, w - j - 1]
print((li + ri + ui + di).max() - 3)

Solution (Python):
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

h,w  = na()
grid = [input().strip() for i in range(h)]


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

for i in range(h):
    count=0
    for j in range(w):
        if(grid[i][j]=="
            count=0
        else:
            count+=1
            
            T[i][j]=count

for i in range(h):
    for j in range(w-2,-1,-1):
        if grid[i][j] == "
            T[i][j] = 0
        else:
            T[i][j] = max(T[i][j],T[i][j+1])

for j in range(w):
    count=0
    for i in range(h):
        if(grid[i][j]=="
            count=0
        else:
            count+=1
            Y[i][j]=count

for j in range(w):
    for i in range(h-2,-1,-1):
        if grid[i][j] == "
            Y[i][j] = 0
        else:
            Y[i][j] = max(Y[i][j],Y[i+1][j])

ANS = -1
for i in range(h):
    for j in range(w):
        ANS = max(ANS, Y[i][j] + T[i][j] - 1)


print(ANS)

Solution (Python):


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


left = [[0 for i in range(W)] for j in range(H)]   
right = [[0 for i in range(W)] for j in range(H)]
up = [[0 for i in range(W)] for j in range(H)]
down = [[0 for i in range(W)] for j in range(H)]



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

for i in range(H):
    cur = 0
    for j in reversed(range(W)):
        if grid[i][j] == "
            cur = 0
        elif grid[i][j] == ".":
            cur += 1
        right[i][j] = cur

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

for j in range(W):       
    cur = 0
    for i in reversed(range(H)):
        if grid[i][j] == "
            cur = 0
        else:
            cur += 1
        down[i][j] = cur

res = 0
for i in range(H):
    for j in range(W):
        res = max([res, (left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3)])
print(res)

Solution (Python):
import numpy as np
import sys


def main():
    stream = sys.stdin
    buf = stream.buffer.readline()
    H, W = map(int, buf.split())
    buf = stream.buffer.read(H * (W + 1))
    arr = np.frombuffer(buf, dtype='B').reshape((H, W + 1))[:, : -1]
    a = (arr == ord('.'))
    L = np.empty((H, W), dtype='i4')
    R = np.empty((H, W), dtype='i4')
    T = np.empty((H, W), dtype='i4')
    B = np.empty((H, W), dtype='i4')
    T[0] = a[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * a[i]
    B[-1] = a[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * a[i]
    L[:, 0] = a[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * a[:, i]
    R[:, -1] = a[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * a[:, i]

    print((T + B + L + R - 3).max())


main()

Solution (Python):
import numpy as np
import sys
buf = sys.stdin.buffer

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

grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:] = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'.').reshape((H,W+1))


def F(transpose):
  x = grid
  if transpose:
    x = (x.T).copy()
  x = np.ravel(x) 
  L = len(x)
  
  left_zero = np.where(x,0,-np.arange(L)) 
  np.minimum.accumulate(left_zero, out=left_zero)
  
  right_zero = np.where(x[::-1],0,np.arange(L)) 
  np.maximum.accumulate(right_zero, out=right_zero)
  
  y = left_zero
  y += L-right_zero[::-1]
  
  return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
  
answer = (F(False) + F(True)).max()-5
print(answer)

Solution (Python):
import numpy as np

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

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

map = np.array([list(input()) for i in range(h)]) == "."

for i in range(1, h):
    up[i] = (up[i-1] + 1) * map[i-1]
    down[h-1-i] = (down[h-i] + 1) * map[h-i]
for j in range(1, w):
    left[:,j] = (left[:,j-1] + 1) * map[:,j-1]
    right[:,w-1-j] = (right[:,w-j] + 1) * map[:,w-j]

print(((up+down+right+left+1) * map).max())

Solution (Python):
from subprocess import *
call(('pypy3','-c',"""
n,m = map(int,input().split())
ls = [[x for x in input() + '
yokodp = [[0 for x in range(m+1)] for i in range(n+1)]
for i in range(n+1):
    yoko = 0
    for j in range(m+1):
        if ls[i][j] == '
            yokodp[i][j] = yoko
            yoko = 0
        else:
            yoko += 1
for i in range(n,-1,-1):
    check = 0
    for j in range(m,-1,-1):
        if yokodp[i][j] != 0:
            check = yokodp[i][j]
        if ls[i][j] == '.':
            yokodp[i][j] = check
tatedp = [[0 for x in range(m+1)] for i in range(n+1)]            
for j in range(m+1):
    tate = 0
    for i in range(n+1):
        if ls[i][j] == '
            tatedp[i][j] = tate
            tate = 0
        else:
            tate += 1
for j in range(m,-1,-1):
    for i in range(n,-1,-1):
        if tatedp[i][j] != 0:
            check = tatedp[i][j]
        if ls[i][j] == '.':
            tatedp[i][j] = check
ans = 0
for i in range(n):
    for j in range(m):
        if ls[i][j] == '.':
            ans = max(ans,tatedp[i][j] + yokodp[i][j] - 1)
print(ans)
"""))

Solution (Python):
h,*s=open(0)
h,w=map(int,h.split())
r=range
a,b,c,d=[[[0]*w for _ in r(h)]for i in r(4)]
for i in r(h*w):
    i,j=i//w,i%w
    a[i][j]=-~a[i][j-1]*(s[i][j]=='.')
    b[i][~j]=-~b[i][-j]*(s[i][-j-2]=='.')
    c[i][j]=-~c[i-1][j]*(s[i][j]=='.')
    d[~i][j]=-~d[-i][j]*(s[~i][j]=='.')
print(max(a[i][j]+b[i][j]+c[i][j]+d[i][j]-3for i in r(h)for j in r(w)))

Solution (Python):
from subprocess import*
call(('pypy3','-c',"""
h,*s=open(0)
h,w=map(int,h.split())
r=range
a,b,c,d=[[[0]*w for _ in r(h)]for i in r(4)]
for i in r(h*w):
    i,j=i//w,i%w
    a[i][j]=-~a[i][j-1]*(s[i][j]=='.')
    b[i][~j]=-~b[i][-j]*(s[i][-j-2]=='.')
    c[i][j]=-~c[i-1][j]*(s[i][j]=='.')
    d[~i][j]=-~d[-i][j]*(s[~i][j]=='.')
print(max(a[i][j]+b[i][j]+c[i][j]+d[i][j]-3for i in r(h)for j in r(w)))
"""))

Solution (Python):
import sys
import numpy as np


def solve(field):
    idx = np.arange(field.size).reshape(field.shape)
    field_idx = field * idx
    li = np.maximum.accumulate(field_idx, axis=1)
    ui = np.maximum.accumulate(field_idx, axis=0)

    field_idx += (field ^ 1) * field.size
    ri = np.fliplr(np.minimum.accumulate(np.fliplr(field_idx), axis=1))
    di = np.flipud(np.minimum.accumulate(np.flipud(field_idx), axis=0))
    return (ri - li + (di - ui) // field.shape[1]).max() - 3


h, w = list(map(int, input().split()))
h2, w2 = h + 2, w + 2
field = np.ones((h2, w2), dtype=np.int32)
field[1:h + 1, 1:w + 1] = [[c == '
print(solve(field))

Solution (Python):
import numpy as np
import sys
buf = sys.stdin.buffer

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

grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:] = (np.frombuffer(buf.read(H*(W+1)),dtype='S1') == b'.').reshape((H,W+1))


def F(transpose):
  x = grid
  if transpose:
    x = (x.T).copy()
  x = np.ravel(x) 
  L = len(x)
  
  left_zero = -np.arange(L) 
  left_zero[x] = 0
  np.minimum.accumulate(left_zero, out=left_zero)
  
  right_zero = np.arange(L) 
  right_zero[x[::-1]] = 0
  np.maximum.accumulate(right_zero, out=right_zero)
  
  y = left_zero
  y += L-right_zero[::-1]
  
  return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
  
answer = (F(False) + F(True)).max()-5
print(answer)

Solution (Python):
def main():
    H, W = map(int, input().split())
    S = [input() for _ 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)]
    L = [[0 for i in range(W)] for j in range(H)]
    R = [[0 for i in range(W)] for j in range(H)]

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

    res = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] != '
                res = max(res, U[i][j] + D[i][j] + R[i][j] + L[i][j])
    
    print(res + 1)

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

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

grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:-1] = (np.array([list(input()) for _ in range(H)]) == '.')

L = grid.size


def F(transpose):
  x = grid
  if transpose:
    x = x.T
  x = np.ravel(x) 
  
  left_zero = -np.arange(L) 
  left_zero[x] = 0
  np.minimum.accumulate(left_zero, out=left_zero)
  
  right_zero = np.arange(L) 
  right_zero[x[::-1]] = 0
  np.maximum.accumulate(right_zero, out=right_zero)
  
  y = left_zero
  y -= right_zero[::-1]
  
  return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
  
answer = (F(False) + F(True)).max()+2*L-5
print(answer)

Solution (Python):
import numpy as np

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

grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:-1] = (np.array([list(input()) for _ in range(H)]) == '.')

L = grid.size
a = np.arange(L)


def F(transpose):
  x = grid
  if transpose:
    x = (x.T).copy()
  x = np.ravel(x) 
  
  left_zero = -a.copy() 
  left_zero[x] = 0
  np.minimum.accumulate(left_zero, out=left_zero)
  
  right_zero = a.copy() 
  right_zero[x[::-1]] = 0
  np.maximum.accumulate(right_zero, out=right_zero)
  
  y = left_zero
  y += L-right_zero[::-1]
  
  return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
  
answer = (F(False) + F(True)).max()-5
print(answer)

Solution (Python):
import numpy as np

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

grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:-1] = (np.array([list(input()) for _ in range(H)]) == '.')


def F(transpose):
  x = grid
  if transpose:
    x = (x.T).copy()
  x = np.ravel(x) 
  L = len(x)
  
  left_zero = -np.arange(L) 
  left_zero[x] = 0
  np.minimum.accumulate(left_zero, out=left_zero)
  
  right_zero = np.arange(L) 
  right_zero[x[::-1]] = 0
  np.maximum.accumulate(right_zero, out=right_zero)
  
  y = left_zero
  y += L-right_zero[::-1]
  
  return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
  
answer = (F(False) + F(True)).max()-5
print(answer)

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


A = [[-10000] * W for i in range(H)]
B = [[-10000] * W for i in range(H)]

for i in range(H):
    jj = 0
    s = 0
    for j in range(W+1):
        if j == W or S[i][j] == '
            for x in range(jj, j):
                A[i][x] = s
            s = 0
            jj = j + 1
        else:
            s += 1


for j in range(W):
    ii = 0
    s = 0
    for i in range(H+1):
        if i == H or S[i][j] == '
            for y in range(ii, i):
	            B[y][j] = s
            s = 0
            ii = i + 1
        else:
            s += 1

m = 0
for i in range(H):
    for j in range(W):
        m = max(A[i][j] + B[i][j] - 1, m)
            
print(m)

Solution (Python):
import numpy as np
H,W=map(int,input().split())
S=[list(input()) for h in range(H)]
S=[[1 if s=='.' else 0 for s in S[h]] for h in range(H)]
S=np.array(S)
L=S.copy()
R=S.copy()
U=S.copy()
D=S.copy()
for w in range(1,W):
    L[:,w]=(L[:,w-1]+1)*S[:,w]
    R[:,-(1+w)]=(R[:,-w]+1)*S[:,-(1+w)]
for h in range(1,H):
    U[h,:]=(U[h-1,:]+1)*S[h,:]
    D[-(1+h),:]=(D[-h,:]+1)*S[-(1+h),:]
print(int((L+R+U+D).max())-3)

Solution (Python):
import numpy as np
 
H, W = map(int, input().split())

mymap = [] 
for i in range(H):
    mymap.append(list(input()))


mymap = (np.array(mymap) == ".")
  
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 j in range(W):
  if j == 0: 
    L[:, j] = mymap[:, j] 
  else:
    L[:, j] = (L[:, j - 1] + 1) * mymap[:, j] 


for j in range(W - 1, -1, -1): 
  if j >= W - 1: 
    R[:, j] = mymap[:, j]
  else:
    R[:, j] = (R[:, j + 1] + 1) * mymap[:, j] 


for i in range(H):
  if i <= 0: 
    U[i, :] = mymap[i, :]
  else:
    U[i, :] = (U[i - 1, :] + 1) * mymap[i, :]


for i in range(H - 1, -1, -1):
  if i >= H - 1: 
    D[i, :] = mymap[i, :]
  else:
    D[i, :] = (D[i + 1, :] + 1) * mymap[i, :]


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

Solution (Python):
import sys

input = sys.stdin.readline

h, w = map(int, input().split())
map_list = [[0 if s == '

h_map = []
for h_list in map_list:
    cnt = 0
    tmp_list = []
    for a in h_list:
        if a == 0:
            if cnt > 0:
                tmp_list.extend([cnt]*cnt)
                cnt = 0
            tmp_list.append(0)
        else:
            cnt += 1
    if cnt > 0:
        tmp_list.extend([cnt]*cnt)
    h_map.append(tmp_list)

w_map = []
for w_arr in [list(x) for x in zip(*map_list)]:
    cnt = 0
    tmp_list = []
    for a in w_arr:
        if a == 0:
            if cnt > 0:
                tmp_list.extend([cnt]*cnt)
                cnt = 0
            tmp_list.append(0)
        else:
            cnt += 1
    if cnt > 0:
        tmp_list.extend([cnt]*cnt)
    w_map.append(tmp_list)
w_map = [list(x) for x in zip(*w_map)]
max_l = 0
for h_list, w_list in zip(h_map, w_map):
    for h_num, w_num in zip(h_list, w_list):
        max_l = max(max_l, h_num + w_num)
print(max_l - 1)

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

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

for i in range(h):
    d[i] = (d[i-1]+1) * table[i]
    u[-i-1] = (u[-i]+1) * table[-i-1]
for i in range(w):
    r[:, i] = (r[:, i-1]+1) * table[:, i]
    l[:, -i-1] = (l[:, -i]+1) * table[:, -i-1]
print(np.max(d+u+r+l)-3)

Solution (Python):
from itertools import takewhile


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


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

for i, j in ((i, j) for i in range(H) for j in range(W) if S[i][j] == '.'):
    if x[i][j] == 0:
        w = len(list(takewhile(lambda k: S[i][k] == '.', range(j, W))))
        for k in range(j, j + w):
            x[i][k] = w
    if y[i][j] == 0:
        h = len(list(takewhile(lambda k: S[k][j] == '.', range(i, H))))
        for l in range(i, i + h):
            y[l][j] = h

ans = max(
    x[i][j] + y[i][j] - 1
    for i in range(H)
    for j in range(W)
)

print(ans)

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

H, W = map(int, input().split())
S = np.array([list(input().rstrip()) for _ in range(H)]) == '.'
ups = np.zeros((H,W), dtype=int)
downs = np.zeros((H,W), dtype=int)
lefts = np.zeros((H,W), dtype=int)
rights = np.zeros((H,W), dtype=int)

for h in range(1, H):
    ups[h] = (ups[h-1] + 1) * S[h-1]
    downs[H-h-1] = (downs[H-h] + 1) * S[H-h]
for w in range(1, W):
    lefts[:, w] = (lefts[:, w-1] + 1) * S[:, w-1]
    rights[:, W-w-1] = (rights[:, W-w] + 1) * S[:, W-w]
print(np.amax((ups+downs+lefts+rights)*S)+1)

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

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)
def dmatprint(mat):

    if debug == True:
        for row in mat:
            for col in row:
                print("{0:2d} ".format(col), end="")
            print("")
        print("")

def solve():
    H, W = map(int, input().split())
    s_arr = [[-1 for w in range(W)] for h in range(H)]
    for h in range(H):
        s_row = input()
        for w in range(W):
            if s_row[w] == ".":
                s_arr[h][w] = 0
            else:
                s_arr[h][w] = 1

    
    r_arr = [[0 for w in range(W)] for h in range(H)]
    l_arr = [[0 for w in range(W)] for h in range(H)]
    u_arr = [[0 for w in range(W)] for h in range(H)]
    d_arr = [[0 for w in range(W)] for h in range(H)]

    
    for h in range(H):
        for w in range(W):
            if s_arr[h][w] == 1:
                continue
            else:
                if w == 0:
                    val = 1
                else:
                    val = l_arr[h][w-1] + 1
            l_arr[h][w] = val

    
    for w in range(W):
        for h in range(H):
            if s_arr[h][w] == 1:
                continue
            else:
                if h == 0:
                    val = 1
                else:
                    val = u_arr[h-1][w] + 1
            u_arr[h][w] = val

    
    for h in range(H):
        for w in reversed(range(W)):
            if s_arr[h][w] == 1:
                continue
            else:
                if w == W-1:
                    val = 1
                else:
                    val = r_arr[h][w+1] + 1
            r_arr[h][w] = val

    
    for w in range(W):
        for h in reversed(range(H)):
            if s_arr[h][w] == 1:
                continue
            else:
                if h == H-1:
                    val = 1
                else:
                    val = d_arr[h + 1][w] + 1
            d_arr[h][w] = val

    mx_ans = 0
    for h in range(H):
        for w in range(W):
            ans = l_arr[h][w] + r_arr[h][w] + u_arr[h][w] + d_arr[h][w] - 3
            if ans >= mx_ans:
                mx_ans = ans

    print(mx_ans)
    dmatprint(s_arr)
solve()

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

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

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

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

U=np.zeros((H,W), dtype=int)
D=np.zeros((H,W), dtype=int)
R=np.zeros((H,W), dtype=int)
L=np.zeros((H,W), dtype=int)

for i in range(H):
    if i==0:
        U[i,:]=S[i,:]
    else:
        U[i,:]=(U[i-1,:]+1)*S[i,:]

for i in range(H-1,-1,-1):
    if i==H-1:
        D[i,:]=S[i,:]
    else:
        D[i,:]+=(D[i+1,:]+1)*S[i,:]

for i in range(W):
    if i==0:
        L[:,i]=S[:,i]
    else:
        L[:,i]+=(L[:,i-1]+1)*S[:,i]
        
for i in range(W-1,-1,-1):
    if i==W-1:
        R[:,i]=S[:,i]
    else:
        R[:,i]+=(R[:,i+1]+1)*S[:,i]
    
print(np.max(U+D+R+L-3))

Solution (Python):
H, W = map(int, input().split())
MAP = [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 i in range(H):
    for j in range(W):
        if MAP[i][j] == "
            L[i][j] = 0
        elif j == 0:
            L[i][j] = 1
        else:
            L[i][j] = L[i] [j - 1] + 1

        if MAP[i][W - j - 1] == "
            R[i][W - j - 1] = 0
        elif j == 0:
            R[i][W - j - 1] = 1
        else:
            R[i][W - j - 1] = R[i][W - j] + 1

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

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

print(result)

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

P = [ [ 0 if x == "

class Union:
    def __init__(self):
        self.rx = 0
        self.ry = 0
        self.lx = 0
        self.ly = 0
    def init(self, y, x):
        value = P[y][x]
        if value == 0:
            return False

        self.lx = x
        self.ly = y
        w = value & 0xffff
        if w & 0x8000:
            self.ry = w ^ 0x8000
        else:
            self.ry = self.ly

        w = value >> 16
        if w & 0x8000:
            self.rx = w ^ 0x8000
        else:
            self.rx = self.lx

        return True

    def changeH(self, src, value):
        return (src ^ (src & 0xffff0000)) | (value << 16)
    def changeV(self, src, value):
        return (src ^ (src & 0xffff)) | value

    def changeHA(self, value):
        return self.changeH(value, self.rx | 0x8000)
    def changeVA(self, value):
        return self.changeV(value, self.ry | 0x8000)

    def getHC(self):
        return P[self.ly][self.rx] >> 16
    def setHC(self, value):
        P[self.ly][self.rx] = self.changeH(P[self.ly][self.rx], value)
    def getVC(self):
        return P[self.ry][self.lx] & 0xffff
    def setVC(self, value):
        P[self.ry][self.lx] = self.changeV(P[self.ry][self.lx], value)
        
uni = Union()

for i in range(H):
    for j in range(W):
        if P[i][j] != 0:
            if i > 0 and uni.init(i-1, j):
                uni.setVC(uni.getVC() + 1)
                P[i][j] = uni.changeVA(P[i][j])
            if j > 0 and uni.init(i, j-1):
                uni.setHC(uni.getHC() + 1)
                P[i][j] = uni.changeHA(P[i][j])


w = 0
for i in range(H):
    for j in range(W):
        if uni.init(i, j):
            w = max(w, uni.getHC() + uni.getVC() -1)

print(w)