Problem:
 Score : 400 points    Problem Statement There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.  Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.  Snuke wants to maximize the number of squares lighted by the lamp.  You are given H strings S_i ( 1 \leq i \leq H ), each of length W . If the j -th character ( 1 \leq j \leq W ) of S_i is # , there is an obstacle on the square at the i -th row from the top and the j -th column from the left; if that character is . , there is no obstacle on that square.  Find the maximum possible number of squares lighted by the lamp.      Constraints  1 \leq H \leq 2,000  1 \leq W \leq 2,000  S_i is a string of length W consisting of # and . .  . occurs at least once in one of the strings S_i ( 1 \leq i \leq H ).         Input Input is given from Standard Input in the following format:  H  W  S_1  :  S_H       Output Print the maximum possible number of squares lighted by the lamp.        Sample Input 1 4 6
#..#..
.....#
....#.
#.#...      Sample Output 1 8  If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.       Sample Input 2 8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#      Sample Output 2 13

Solution (Python):
H, W = map(int,input().split())
s = [list(input()) for i in range(H)]
sl = [[0]*(W) for _ in range(H)]
sr = [[0]*(W) for _ in range(H)]
su = [[0]*(W) for _ in range(H)]
sd = [[0]*(W) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j]=='.':
            if i==0:
                sl[i][j] = 1
            else:
                sl[i][j] = sl[i-1][j]+1
            if j==0:
                su[i][j]=1
            else:
                su[i][j] = su[i][j-1]+1
for i in list(range(H))[::-1]:
    for j in list(range(W))[::-1]:
        if s[i][j]=='.':
            if i==H-1:
                sr[i][j] = 1
            else:
                sr[i][j] = sr[i+1][j]+1
            if j==W-1:
                sd[i][j]=1
            else:
                sd[i][j] = sd[i][j+1]+1
ans = 0
for i in range(H):
    for j in range(W):
        if s[i][j]=='.':
            ans = max(ans, sl[i][j]+sr[i][j]+su[i][j]+sd[i][j]-3)
print(ans)

Solution (Python):
import numpy as np
h,w = map(int,input().split())
s = [[] for j in range(h)]
for i in range(h):
    tmp = input()
    for j in tmp:
        if j == '.':
            s[i].append(1)
        else:
            s[i].append(0)


L = np.zeros((h,w))
R = np.zeros((h,w))
U = np.zeros((h,w))
D = np.zeros((h,w))
s = np.array(s)

for i in range(w):
    L[:,i] = (L[:,i-1]+1)*s[:,i]
    R[:,-1-i] = (R[:,-i]+1)*s[:,-1-i]
    
for i in range(h):
    U[i,:] = (U[i-1,:]+1)*s[i,:]
    D[-1-i,:] = (D[-i,:]+1)*s[-i-1,:]
    
print(int(np.max(L+R+D+U-3)))

Solution (Python):
import sys
import numpy as np
def main():
    input = sys.stdin.readline
    h, w = map(int, input().split())
    s = np.array([list(input().rstrip()) for _ in range(h)])
    t = np.zeros((h+2, w+2))
    t[1:-1, 1:-1][s == "."] = 1
    row = np.zeros((h+2, w+2))
    col = np.zeros((w+2, h+2))
    for i in range(1, h+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        row[i, idx[:-1]+1] += dif-1
        row[i, idx[1:]] -= dif-1
        row[i] = np.cumsum(row[i])
    t = t.T
    for i in range(1, w+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        col[i, idx[:-1]] += dif-2
        col[i, idx[1:]] -= dif-2
        col[i] = np.cumsum(col[i])
    col = col.T
    cost = np.add(row, col)
    print(int(np.max(cost)))

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np
def main():
    h, w = map(int, input().split())
    s = np.array([list(input()) for _ in range(h)])
    t = np.zeros((h+2, w+2))
    t[1:-1, 1:-1][s == "."] = 1
    row = np.zeros((h+2, w+2))
    col = np.zeros((w+2, h+2))
    for i in range(1, h+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        row[i, idx[:-1]+1] += dif-1
        row[i, idx[1:]] -= dif-1
        row[i] = np.cumsum(row[i])
    t = t.T
    for i in range(1, w+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        col[i, idx[:-1]] += dif-2
        col[i, idx[1:]] -= dif-2
        col[i] = np.cumsum(col[i])
    col = col.T
    cost = np.add(row, col)
    print(int(np.max(cost)))

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 = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])

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

for h in range(H-1):
    U[h+1] = (U[h] + 1) * S[h]
    D[H-h-2] = (D[H-h-1] + 1) * S[H-h-1]
for w in range(W-1):
    L[:, w+1] = (L[:, w] + 1) * S[:, w]
    R[:, W-w-2] = (R[:, W-w-1] + 1) * S[:, W-w-1]


print(((U + D + L + R) * S).max() + 1)

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 = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])

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

for h in range(H-1):
    U[h+1] = (U[h] + 1) * S[h]
    D[H-h-2] = (D[H-h-1] + 1) * S[H-h-1]
for w in range(W-1):
    L[:, w+1] = (L[:, w] + 1) * S[:, w]
    R[:, W-w-2] = (R[:, W-w-1] + 1) * S[:, W-w-1]


print(((U + D + L + R) * S).max() + 1)

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

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

for i in range(H):
    cnt=0
    id=0
    buf=[]
    for j in range(W):
        if S[i][j]=="
            buf.append(j)
    buf.append(W+1)
    for j in range(W):
        if buf[id]!=j:
            if id==0:
                Syoko[i][j]=min(buf[0],W)
            elif id==len(buf)-1:
                Syoko[i][j]=(W-1)-buf[id-1]
            else:
                Syoko[i][j]=buf[id]-(buf[id-1]+1)
        else:
            id=id+1

for j in range(W):
    cnt=0
    id=0
    buf=[]
    for i in range(H):
        if S[i][j]=="
            buf.append(i)
    buf.append(H+1)
    for i in range(H):
        if buf[id]!=i:
            if id==0:
                State[i][j]=min(buf[0],H)
            elif id==len(buf)-1:
                State[i][j]=(H-1)-buf[id-1]
            else:
                State[i][j]=buf[id]-(buf[id-1]+1)
        else:
            id=id+1

ma=0
for i in range(H):
    for j in range(W):
        ma=max(ma,State[i][j]+Syoko[i][j]-1)
print(ma)

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

        if j != 0:
            if s[i][j] == '.':
                L[i][j] = L[i][j - 1] + 1
            if s[i][- (j + 1)] == '.':
                R[i][- (j + 1)] = R[i][- (j + 1) + 1] + 1

        if i == 0:
            if s[i][j] == '.':
                U[i][j] = 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = 1
        if i != 0:
            if s[i][j] == '.':
                U[i][j] = U[i - 1][j] + 1
            if s[- (i + 1)][j] == '.':
                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 = R[i][j] + L[i][j] + D[i][j] + U[i][j] -3
        if ans < temp:ans = temp
        
print(ans)

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

map=[list(input()) for _ in range(h)]
map = [[1 if s == '.' else 0 for s in map[i]] for i in range(h)]

map = np.array(map,dtype=int)
l=map.copy()
r=map.copy()
u=map.copy()
d=map.copy()

for i in range(1,h):
    u[i] += u[i-1]
    u[i] *= map[i]
for i in range(h-1, 0, -1):
    d[i-1] += d[i]
    d[i-1] *= map[i-1]
for i in range(1,w):
    l[:, i] += l[:, i-1]
    l[:, i] *= map[:, i]
for i in range(w-1, 0, -1):
    r[:, i-1] += r[:, i]
    r[:, i-1] *= map[:, i-1]

print((u+d+l+r).max()-3)

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

from copy import deepcopy

h, w = map(int, readline().split())
s = [input() for _ in range(h)]
cnt_x = [[0] * w for _ in range(h)]
cnt_y = deepcopy(cnt_x)
for i in range(h):
    memo = 0
    for j in range(w):
        if s[i][j] == '.':
            memo += 1
            cnt_x[i][j] = memo
        else:
            memo = 0
    for j in range(w - 1, 0, -1):
        if s[i][j - 1] == '.':
            if cnt_x[i][j - 1] < cnt_x[i][j]:
                cnt_x[i][j - 1] = cnt_x[i][j]
for i in range(w):
    memo = 0
    for j in range(h):
        if s[j][i] == '.':
            memo += 1
            cnt_y[j][i] = memo
        else:
            memo = 0
    for j in range(h - 1, 0, -1):
        if s[j - 1][i] == '.':
            cnt_y[j - 1][i] = max(cnt_y[j - 1][i], cnt_y[j][i])
            if cnt_y[j - 1][i] < cnt_y[j][i]:
                cnt_y[j - 1][i] = cnt_y[j][i]
ans = 0
for i in range(h):
    for j in range(w):
        v = cnt_x[i][j] + cnt_y[i][j] - 1
        if ans < v:
            ans = v
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['
for _ in range(h-2):
    MAZE.append('
else:
    MAZE.append('

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

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

for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '.':
            L[i][j+1] = L[i][j]+1
            U[i+1][j] = U[i][j]+1
        if MAZE[i][w-j] == '.':
            R[i][w-j-1] = R[i][w-j]+1
        if MAZE[h-i][j] == '.':
            D[h-i-1][j] = D[h-i][j]+1

ans = 0
for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '
            continue
        LAMP[i][j] = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
        ans = max(ans, LAMP[i][j])

print(ans)

Solution (Python):
h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['
for _ in range(h-2):
    MAZE.append('
else:
    MAZE.append('

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

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

for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '
            continue
        L[i][j+1] = L[i][j]+1

for i in range(1, h-1):
    for j in reversed(range(1, w-1)):
        if MAZE[i][j] == '
            continue
        R[i][j-1] = R[i][j]+1

for j in range(1, w-1):
    for i in range(1, h-1):
        if MAZE[i][j] == '
            continue
        U[i+1][j] = U[i][j]+1

for j in range(1, w-1):
    for i in reversed(range(1, h-1)):
        if MAZE[i][j] == '
            continue
        D[i-1][j] = D[i][j]+1

ans = 0
for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '
            continue
        LAMP[i][j] = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
        ans = max(ans, LAMP[i][j])

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['
for _ in range(h-2):
    MAZE.append('
else:
    MAZE.append('

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

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

for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '.':
            L[i][j+1] = L[i][j]+1
        if MAZE[i][w-j] == '.':
            R[i][w-j-1] = R[i][w-j]+1

for j in range(1, w-1):
    for i in range(1, h-1):
        if MAZE[i][j] == '.':
            U[i+1][j] = U[i][j]+1
        if MAZE[h-i][j] == '.':
            D[h-i-1][j] = D[h-i][j]+1

ans = 0
for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '
            continue
        LAMP[i][j] = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
        ans = max(ans, LAMP[i][j])

print(ans)

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

Left = [[0] * W for _ in range(H)]
for y in range(H):
    count = 0
    for x in range(W):
        if S[y][x] == '
            count = 0
        else:
            count += 1
        Left[y][x] = count

Right = [[0] * W for _ in range(H)]
for y in range(H):
    count = 0
    for x in range(W-1, -1, -1):
        if S[y][x] == '
            count = 0
        else:
            count += 1
        Right[y][x] = count

Up = [[0] * W for _ in range(H)]
for x in range(W):
    count = 0
    for y in range(H):
        if S[y][x] == '
            count = 0
        else:
            count += 1
        Up[y][x] = count

Down = [[0] * W for _ in range(H)]
for x in range(W):
    count = 0
    for y in range(H-1, -1, -1):
        if S[y][x] == '
            count = 0
        else:
            count += 1
        Down[y][x] = count

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

print(ans)

Solution (Python):
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
a=[[0]*w for j in range(h)]
b=[[0]*w for j in range(h)]
for i in range(h):
    k=0
    rep=0
    while k<w:
        cnt=0
        if s[i][k]==".":
            j=k
            while k<w and s[i][k]==".":
                k+=1
                cnt+=1
            for x in range(j,k):
                a[i][x]=cnt
        else:
            k+=1
for i in range(w):
    k=0
    while k<h:
        cnt=0
        if s[k][i]==".":
            j=k
            while k<h and s[k][i]==".":
                k+=1
                cnt+=1
            for x in range(j,k):
                b[x][i]=cnt
        else:
            k+=1
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,a[i][j]+b[i][j])
print(ans-1)

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

lat = [[0] * w for _ in range(h)]
lng = [[0] * w for _ in range(h)]

for i in range(h):
    count = 0
    for j in range(w):
        if grid[i][j] == '
            for k in range(j-count, j):
                lat[i][k] = count
            count = 0
        else:
            count += 1
    for k in range(w-count, w):
        lat[i][k] = count

for j in range(w):
    count = 0
    for i in range(h):
        if grid[i][j] == '
            for k in range(i-count, i):
                lng[k][j] = count
            count = 0
        else:
            count += 1
    for k in range(h-count, h):
        lng[k][j] = count

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

print(ans)

Solution (Python):
import sys

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

def main():
    h, w = map(int, read().split())
    s = [list(read()) for _ in range(h)]
    row = [[0 for _ in range(w)] for _ in range(h)]
    col = [[0 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        c = 0
        for j in range(w):
            if s[i][j] == "
                for k in range(j - c, j):
                    row[i][k] = c
                c = 0
            else:
                c += 1
        for k in range(w - c, w):
            row[i][k] = c
    for i in range(w):
        c = 0
        for j in range(h):
            if s[j][i] == "
                for k in range(j - c, j):
                    col[k][i] = c
                c = 0
            else:
                c += 1
        for k in range(h - c, h):
            col[k][i] = c
    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(row[i][j] + col[i][j], ans)
    print(ans - 1)

if __name__ == '__main__':
    main()

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

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

for i in range(h):
    for j in range(w):
        ri, rj = h-1-i, w-1-j
        if S[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1
        if S[ri][rj] == '.':
            if rj == w-1:
                R[ri][rj] = 1
            else:
                R[ri][rj] = R[ri][rj+1] + 1
            if ri == h-1:
                D[ri][rj] = 1
            else:
                D[ri][rj] = D[ri+1][rj] + 1

ans = 0

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

print(ans)

Solution (Python):
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
hs = [[0]*w for _ in range(h)]
ws = [[0]*w for _ in range(h)]
for y in range(h):
    for x in range(w):
        if s[y][x] == ".":
            if 1<=x<w and ws[y][x-1]:
                ws[y][x] = ws[y][x-1]
                continue
            if x<w and s[y][x]==".":
                for x_ in range(x, w):
                    if s[y][x_] == ".": 
                        ws[y][x] += 1
                    else:
                        break
for x in range(w):
    for y in range(h):
        if s[y][x] == ".":
            if 1<=y<h and hs[y-1][x]:
                hs[y][x] = hs[y-1][x]
                continue
            if y<h and s[y][x]==".":
                for y_ in range(y, h):
                    if s[y_][x] == ".": 
                        hs[y][x] += 1
                    else:
                        break
ans = hs[0][0] + ws[0][0] -1 
for i in range(h):
    for j in range(w):
        ans = max(ans, hs[i][j] + ws[i][j] -1)
print(ans)

Solution (Python):
H,W = map(int,input().split())
s = [[] for i in range(H)]
for i in range(H): s[i] = list(input())
l = [[0]*W for i in range(H)]
r = [[0]*W for i in range(H)]
d = [[0]*W for i in range(H)]
u = [[0]*W for i in range(H)]

for h in range(H):
    if s[h][0] == ".": l[h][0] = 1
    for w in range(1,W):
        if s[h][w] == ".": l[h][w] = l[h][w-1] + 1
    if s[h][W-1] == ".": r[h][W-1] = 1
    for w in range(1,W):
        if s[h][W-1-w] == ".": r[h][W-1-w] = r[h][W-w] + 1

for w in range(W):
    if s[0][w] == ".": d[0][w] = 1
    for h in range(1,H):
        if s[h][w] == ".": d[h][w] = d[h-1][w] + 1
    if s[H-1][w] == ".": u[H-1][w] = 1
    for h in range(1,H):
        if s[H-1-h][w] == ".": u[H-1-h][w] = u[H-h][w] + 1
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, l[h][w]+r[h][w]+u[h][w]+d[h][w]-3)

print(ans)

Solution (Python):
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
T = [[0] * (W + 1) for _ in range(H + 1)]
U = [[0] * (W + 1) for _ in range(H + 1)]


for y in range(H):
    for x in range(W):
        if S[y][x] == '.':
            if x == 0 or S[y][x - 1] == '
                start = x
            if x == W - 1 or S[y][x + 1] == '
                end = x
                long = end - start + 1
                T[y][start] += long
                T[y][end + 1] -= long

for y in range(H):
    for x in range(W):
        T[y][x + 1] += T[y][x]


for x in range(W):
    for y in range(H):
        if S[y][x] == '.':
            if y == 0 or S[y - 1][x] == '
                start = y
            if y == H - 1 or S[y + 1][x] == '
                end = y
                long = end - start + 1
                U[start][x] += long
                U[end + 1][x] -= long

for x in range(W):
    for y in range(H):
        U[y + 1][x] += U[y][x]


M = 0
for x in range(W):
    for y in range(H):
        M = max(M, T[y][x] + U[y][x] - 1)
print(M)

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    h, w = MII()
    ss = []
    for i in range(h):
        ss.append(IS())
    

    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 ss[i][j] == '
            if j == 0: L[i][j] = 1; continue
            if j > 0: L[i][j] = L[i][j-1] + 1; continue

    for i in range(h):
        for j in reversed(range(w)):
            if ss[i][j] == '
            if j == w-1: R[i][j] = 1; continue
            if j < w-1: R[i][j] = R[i][j+1] + 1; continue

    for i in range(h):
        for j in range(w):
            if ss[i][j] == '
            if i == 0: D[i][j] = 1; continue
            if i > 0: D[i][j] = D[i-1][j] + 1; continue

    for i in reversed(range(h)):
        for j in range(w):
            if ss[i][j] == '
            if i == h-1: U[i][j] = 1; continue
            if i < h-1: U[i][j] = U[i+1][j] + 1; continue

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

if __name__ == '__main__':
    main()

Solution (Python):
H, W  = map(int, input().split())
grid = [input() for _ in range(H)]
ans = [[0] * W for _ in range(H)]
for i in range(H):
    tmp = 0
    for k in range(W):
        if grid[i][k] == '.':
            tmp += 1
        else:
            ans[i][k] = 0
            for t in range(k-tmp,k):
                ans[i][t] = tmp
            tmp = 0
    for t in range(W-tmp,W):
        ans[i][t] = tmp
a = 0
for i in range(W):
    tmp = 0
    for k in range(H):
        if grid[k][i] == '.':
            tmp += 1
        else:
            for t in range(k-tmp,k):
                a = max(ans[t][i]+tmp-1,a)
            tmp = 0
    for t in range(H-tmp,H):
        a = max(ans[t][i]+tmp-1,a)
print(a)

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

Solution (Python):


import sys
import math
import collections
import itertools
from functools import lru_cache
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

H, W = LI()
S = RS(H)

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

for i in range(H):
    lf = 0
    rf = 0
    for j in range(W):
        if S[i][j] == ".":
            lf += 1
            L[i][j] = lf
        else:
            lf = 0

        if S[i][W-1-j] == ".":
            rf += 1
            R[i][W-1-j] = rf
        else:
            rf = 0

for i in range(W):
    uf = 0
    df = 0
    for j in range(H):
        if S[j][i] == ".":
            df += 1
            D[j][i] = df
        else:
            df = 0

        if S[H-1-j][i] == ".":
            uf += 1
            U[H-1-j][i] = uf
        else:
            uf = 0

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, U[i][j]+D[i][j]+L[i][j]+R[i][j]-3)

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)]
res=0
for i in range(H):
    for j in range(W):
        if(S[i][j]=='
            L[i][j]=0
        elif(j==0):
            L[i][j]=1
        else:
            L[i][j]=L[i][j-1]+1
    for j in reversed(range(W)):
        if(S[i][j]=='
            R[i][j]=0
        elif(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):
        if(S[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)):
        if(S[i][j]=='
            D[i][j]=0
        elif(i==H-1):
            D[i][j]=1
        else:
            D[i][j]=D[i+1][j]+1
for i in range(H):
    for j in range(W):
        res=max(res,U[i][j]+D[i][j]+L[i][j]+R[i][j]-3)
print(res)

Solution (Python):

import sys
input = sys.stdin.readline









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

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


for h in range(H):
    cnt = 0
    for w in range(W):
        if S[h][w] == "
            cnt = 0
        else:
            cnt += 1
        LR[h][w] = cnt
for h in range(H):
    cnt = 0
    for w in range(W):
        if LR[h][W-1-w] == 0:
            cnt = 0
        else:
            if cnt==0:
                cnt = LR[h][W-1-w]
            else:
                LR[h][W-1-w] = cnt


for w in range(W):
    cnt = 0
    for h in range(H):
        if S[h][w] == "
            cnt = 0
        else:
            cnt += 1
        UD[h][w] = cnt
for w in range(W):
    cnt = 0
    for h in range(H):
        if UD[H-1-h][w] == 0:
            cnt = 0
        else:
            if cnt==0:
                cnt = UD[H-1-h][w]
            else:
                UD[H-1-h][w] = cnt

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

print(ans)

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 = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S], np.bool)
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]

answer = ((up + down + left + right) * S).max() + 1
print(answer)

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 = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]

answer = ((up + down + left + right) * S).max() + 1
print(answer)

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 = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])
up = np.ones((H, W), np.int32)
up *= S
down = np.ones((H, W), np.int32)
down *= S
right = np.ones((H, W), np.int32)
right *= S
left = np.ones((H, W), np.int32)
left *= S
for i in range(H-1):
    up[i+1] += up[i]
    up[i+1] *= S[i+1]
for i in range(H-1, 0, -1):
    down[i-1] += down[i]
    down[i-1] *= S[i-1]
for i in range(W-1):
    left[:, i+1] += left[:, i]
    left[:, i+1] *= S[:, i+1]
for i in range(W-1, 0, -1):
    right[:, i-1] += right[:, i]
    right[:, i-1] *= S[:, i-1]

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

Solution (Python):


import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

H, W = list(map(int, sys.stdin.readline().split()))

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

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

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 = [list(sr()) for _ in range(H)]
up = np.array([[1 if x == '.' else 0 for x in row] for row in S])
down = up.copy()
right = up.copy()
left = up.copy()
S = up.copy()
for i in range(H-1):
    up[i+1] += up[i]
    up[i+1] *= S[i+1]
for i in range(H-1, 0, -1):
    down[i-1] += down[i]
    down[i-1] *= S[i-1]
for i in range(W-1):
    left[:, i+1] += left[:, i]
    left[:, i+1] *= S[:, i+1]
for i in range(W-1, 0, -1):
    right[:, i-1] += right[:, i]
    right[:, i-1] *= S[:, i-1]

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

Solution (Python):
h, w = map(int, input().split())
grid = [['
for i in range(h):
  grid.append(['
grid.append(['

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

for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '
    U[i][j] = U[i-1][j] + 1
    L[i][j] = L[i][j-1] + 1
for i in range(h, 0, -1):
  for j in range(w, 0, -1):
    if grid[i][j] == '
    D[i][j] = D[i+1][j] + 1
    R[i][j] = R[i][j+1] + 1

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