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):
import sys, math, heapq
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()







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


import numpy as np
L, R, U, D = [np.zeros((H, W), int) for _ in range(4)]
grid_np = np.zeros((H,W), int)


for i in range(H):
    row = list(" ".join(input()).split())
    grid.append(row)
    grid_np[i] = np.array(row) == '.'

def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)

            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

def solve_np():
    ans = 0

    for j in range(W):
        
        if j == 0:
            L[:, j] = 1 * grid_np[:, j]
            R[:, -j - 1] = 1 * grid_np[:, -j - 1]
        else:
            L[:, j] = (L[:, j - 1] + 1) * grid_np[:, j]
            R[:, -j - 1] = (R[:, -j] + 1) * grid_np[:, -j - 1]

    for i in range(H):
        if i == 0:
            U[i] = 1 * grid_np[i]
            D[-i -1] = 1 * grid_np[-i -1]
        else:
            U[i] = (U[i - 1] + 1) * grid_np[i]
            D[-i - 1] = (D[-i] + 1) * grid_np[-i - 1]
    ans = np.max((L+R+U+D) -3)
    return ans

if __name__ == "__main__":
    
    print(solve_np())

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

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

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

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

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[h-(i-1)-1][j-1]==".":
            d[h+1-i][j]=d[h+1-i+1][j]+1
        else:
            d[h+1-i][j]=0
ans=0
for y in range(1,h+1):
    for x in range(1,w+1):
        sum=r[y][x]+l[y][x]+u[y][x]+d[y][x]-3
        if ans<sum:
            ans=sum
print(ans)

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

row = [[0] * W for _ in range(H)]
line = [[0] * W for _ in range(H)]
ans = 0

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            if i != 0:
                if row[i-1][j] != 0:
                    row[i][j] = row[i-1][j]
                    continue
            c = 1
            if i+c == H:
                row[i][j] = c
                continue
            while S[i+c][j] == '.':
                c += 1
                if i+c == H:
                    break
            row[i][j] = c

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            if j != 0:
                if line[i][j-1] != 0:
                    line[i][j] = line[i][j-1]
                    ans = max(ans, row[i][j]+line[i][j]-1)
                    continue
            c = 1
            if j+c == W:
                line[i][j] = c
                ans = max(ans, row[i][j]+line[i][j]-1)
                continue
            while S[i][j+c] == '.':
                c += 1
                if j+c == W:
                    break
            line[i][j] = c
            ans = max(ans, row[i][j]+line[i][j]-1)


print(ans)

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

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

for r in range(H):
    for c in range(W):
        if s[r][c] == '.':
            if c == 0:
                L[r][c] = 1
            else:
                L[r][c] = L[r][c - 1] + 1
        else:
            L[r][c] = 0

for r in range(H):
    for c in reversed(range(W)):
        if s[r][c] == '.':
            if c == W - 1:
                R[r][c] = 1
            else:
                R[r][c] = R[r][c + 1] + 1
        else:
            R[r][c] = 0

for r in range(H):
    for c in range(W):
        if s[r][c] == '.':
            if r == 0:
                U[r][c] = 1
            else:
                U[r][c] = U[r - 1][c] + 1
        else:
            U[r][c] = 0

for r in reversed(range(H)):
    for c in range(W):
        if s[r][c] == '.':
            if r == H - 1:
                D[r][c] = 1
            else:
                D[r][c] = D[r + 1][c] + 1
        else:
            D[r][c] = 0

ans = 0
for r in range(H):
    for c in range(W):
        ans = max(ans, L[r][c] + R[r][c] + D[r][c] + U[r][c] - 3)
print(ans)

Solution (Python):



import sys
import numpy as np


def main():
    buffer = sys.stdin.buffer
    H, W = list(map(int,buffer.readline().split()))
    S = np.frombuffer(buffer.read(H*(W+1)), dtype="B") == ord(".")
    S = S.reshape((H,W+1))[:,:-1]
    L = np.empty((H,W), dtype="i4")
    R = np.empty((H,W), dtype="i4")
    U = np.empty((H,W), dtype="i4")
    D = np.empty((H,W), dtype="i4")

    L[:,0] = S[:,0]
    for i in range(1,W):
        L[:,i] = (L[:,i-1] + 1) * S[:,i]

    R[:,-1] = S[:,-1]
    for i in range(1,W):
        R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]

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

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

    score = L + R + U + D - 3
    print(int(score.max()))


if __name__ == "__main__":
    main()

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):
def main():
	H, W = map(int, input().split())
	S = [""]*H
	for i in range(H):
		S[i] = input()
	r = [[0 for _ in range(W)] for _ in range(H)]
	c = [[0 for _ in range(W)] for _ in range(H)]
	for i in range(H):
		for j in range(W):
			if S[i][j] == "
				continue
			r[i][j] = r[i][j-1]+1 if j > 0 else 1
		for j in range(W-2, -1, -1):
			if r[i][j+1] == 0 or r[i][j] == 0:
				continue
			r[i][j] = r[i][j+1]

	for j in range(W):
		for i in range(H):
			if S[i][j] == "
				continue
			c[i][j] = c[i-1][j]+1 if i > 0 else 1
		for i in range(H-2, -1, -1):
			if c[i+1][j] == 0 or c[i][j] == 0:
				continue
			c[i][j] = c[i+1][j]

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


if __name__ == '__main__':
	main()

Solution (Python):

import numpy as np
import sys


sin = sys.stdin.buffer
H, W = map(int, sin.readline().split())
grid = [[None] * W for _ in range(H)]
for h in range(H):
    grid[h] = list(input())
grid = (np.array(grid) == ".") * 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] = grid[0]
for i in range(1, H):
    T[i] = (T[i - 1] + 1) * grid[i]

B[-1] = grid[-1]
for i in range(H - 2, -1, -1):
    B[i] = (B[i + 1] + 1) * grid[i]

L[:, 0] = grid[:, 0]
for i in range(1, W):
    L[:, i] = (L[:, i - 1] + 1) * grid[:, i]

R[:, -1] = grid[:, -1]
for i in range(W - 2, -1, -1):
    R[:, i] = (R[:, i + 1] + 1) * grid[:, i]

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

Solution (Python):

import numpy as np
import sys

def main():
    sin = sys.stdin.buffer
    H, W = map(int, sin.readline().split())
    grid = np.frombuffer(sin.read(H * (W + 1)), dtype="B") == ord(".")
    grid = grid.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] = grid[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * grid[i]

    B[-1] = grid[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * grid[i]

    L[:, 0] = grid[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * grid[:, i]

    R[:, -1] = grid[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * grid[:, i]

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

main()

Solution (Python):
h, w = map(int, raw_input().split())
S = [[0 if c == "." else 1 for c in raw_input()] for i in range(h)]
L = [[0]*w for i in range(h)]
R = [[0]*w for i in range(h)]
U = [[0]*w for i in range(h)]
D = [[0]*w for i in range(h)]

for i in xrange(h):
    ps = 0
    for j in xrange(w):
        if S[i][j] == 1:
            ps = 0
        else:
            ps += 1
            L[i][j] = ps

for j in xrange(w):
    ps = 0
    for i in xrange(h):
        if S[i][j] == 1:
            ps = 0
        else:
            ps += 1
            U[i][j] = ps

for i in xrange(h-1, -1, -1):
    ps = 0
    for j in xrange(w-1, -1, -1):
        if S[i][j] == 1:
            ps = 0
        else:
            ps += 1
            R[i][j] = ps
for j in xrange(w-1, -1, -1):
    ps = 0
    for i in xrange(h-1, -1, -1):
        if S[i][j] == 1:
            ps = 0
        else:
            ps += 1
            D[i][j] = ps
maxLight = 0
for i in xrange(h):
    for j in xrange(w):
        maxLight = max(maxLight, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print maxLight

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

s = []

for i in range(h):
    s.append(input())

_h = [[0 for i in range(w)] for j in range(h)]
_w = [[0 for i in range(w)] for j in range(h)]
_h2 = [[0 for i in range(w)] for j in range(h)]
_w2 = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    _h[i][0] = 1 if s[i][0] == "." else 0

for i in range(w):
    _w[0][i] = 1 if s[0][i] == "." else 0

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

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

for i in range(h):
    _h2[i][w - 1] = 1 if s[i][w - 1] == "." else 0

for i in range(w):
    _w2[h - 1][i] = 1 if s[h - 1][i] == "." else 0

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

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

maximum = 0

for i in range(h):
    for j in range(w):
        ans = _h[i][j] + _h2[i][j] + _w[i][j] + _w2[i][j] - 3
        if ans >= maximum:
            maximum = ans

print(maximum)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    h, w = map(int, input().split())
    ss = [input() for _ in range(h)]

    matl = [[0 for _ in range(w)] for _ in range(h)]
    matr = [[0 for _ in range(w)] for _ in range(h)]
    matu = [[0 for _ in range(w)] for _ in range(h)]
    matd = [[0 for _ in range(w)] for _ in range(h)]

    for j in range(h):
        for i in range(w):
            if ss[j][i] == '
                matd[j][i] = 0
            elif j == 0:
                matd[j][i] = 1
            else:
                matd[j][i] = matd[j - 1][i] + 1

            if ss[h - j - 1][i] == '
                matu[h - j - 1][i] = 0
            elif h - j == h:
                matu[h - j - 1][i] = 1
            else:
                matu[h - j - 1][i] = matu[h - j][i] + 1

            if ss[j][i] == '
                matr[j][i] = 0
            elif i == 0:
                matr[j][i] = 1
            else:
                matr[j][i] = matr[j][i - 1] + 1

            if ss[j][w - i - 1] == '
                matl[j][w - i - 1] = 0
            elif w - i == w:
                matl[j][w - i - 1] = 1
            else:
                matl[j][w - i - 1] = matl[j][w - i] + 1

    maxv = 0
    for j in range(h):
        for i in range(w):
            tmp = matu[j][i] + matd[j][i] + matr[j][i] + matl[j][i]
            if tmp > maxv:
                maxv = tmp
    print(maxv - 3)

if __name__ == '__main__':
    main()

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

    matl = [[0 for _ in range(w)] for _ in range(h)]
    matr = [[0 for _ in range(w)] for _ in range(h)]
    matu = [[0 for _ in range(w)] for _ in range(h)]
    matd = [[0 for _ in range(w)] for _ in range(h)]

    for j in range(h):
        for i in range(w):
            if ss[j][i] == '
                matd[j][i] = 0
            elif j == 0:
                matd[j][i] = 1
            else:
                matd[j][i] = matd[j - 1][i] + 1

            if ss[h - j - 1][i] == '
                matu[h - j - 1][i] = 0
            elif h - j == h:
                matu[h - j - 1][i] = 1
            else:
                matu[h - j - 1][i] = matu[h - j][i] + 1

            if ss[j][i] == '
                matr[j][i] = 0
            elif i == 0:
                matr[j][i] = 1
            else:
                matr[j][i] = matr[j][i - 1] + 1

            if ss[j][w - i - 1] == '
                matl[j][w - i - 1] = 0
            elif w - i == w:
                matl[j][w - i - 1] = 1
            else:
                matl[j][w - i - 1] = matl[j][w - i] + 1

    maxv = 0
    for j in range(h):
        for i in range(w):
            tmp = matu[j][i] + matd[j][i] + matr[j][i] + matl[j][i]
            if tmp > maxv:
                maxv = tmp
    print(maxv - 3)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

readline = sys.stdin.readline

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

vert = [[0]*W for i in range(H)]
hori = [[0]*W for i in range(H)]

for y in range(H):
    for x in range(W):

        if x > 0 and S[y][x - 1] != '
            hori[y][x] = hori[y][x - 1]
        elif S[y][x] == '
            hori[y][x] = 0
        else:
            
            count = 1
            while x + count < W and S[y][x + count] == '.':
                count += 1
            hori[y][x] = count

        if y > 0 and S[y - 1][x] != '
            vert[y][x] = vert[y - 1][x]
        elif S[y][x] == '
            vert[y][x] = 0
        else:
            
            count = 1
            while y + count < H and S[y + count][x] == '.':
                count += 1
            vert[y][x] = count

ans = 0
for y in range(H):
    for x in range(W):
        a = hori[y][x] + vert[y][x] - 1
        ans = max(a, ans)

print(ans)

Solution (Python):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
r = [[0 for _ in range(W)] for _ in range(H)]
l = [[0 for _ in range(W)] for _ in range(H)]
d = [[0 for _ in range(W)] for _ in range(H)]
u = [[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] == ".":
            r[i][j] = c
            c += 1
        else:
            c = 0
for i in range(H):
    c = 0
    for j in range(W)[::-1]:
        if S[i][j] == ".":
            c += 1
            l[i][j] = c
        else:
            c = 0
for i in range(W):
    c = 0
    for j in range(H):
        if S[j][i] == ".":
            d[j][i] = c
            c += 1
        else:
            c = 0
for i in range(W):
    c = 0
    for j in range(H)[::-1]:
        if S[j][i] == ".":
            c += 1
            u[j][i] = c
        else:
            c = 0
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, r[i][j] + l[i][j] + d[i][j] + u[i][j] - 1)
print(ans)

Solution (Python):
h,w = map(int, input().split())
S = [input() for i in range(h)]
U = [[0]*w for i in range(h)]
D = [[0]*w for i in range(h)]
L = [[0]*w for i in range(h)]
R = [[0]*w for i in range(h)]

for i in range(h):
    for j in range(w):
        if S[i][j] == ".":
            if j > 0:
                L[i][j] = L[i][j-1] + 1
            else:
                L[i][j] = 1
    for j in range(w-1,-1,-1):
        if S[i][j] == ".":
            if j < w-1:
                R[i][j] = R[i][j+1] + 1
            else:
                R[i][j] = 1
for i in range(w):
    for j in range(h):
        if S[j][i] == ".":
            if j > 0:
                D[j][i] = D[j-1][i] + 1
            else:
                D[j][i] = 1
    for j in range(h-1,-1,-1):
        if S[j][i] == ".":
            if j < h-1:
                U[j][i] = U[j+1][i] + 1
            else:
                U[j][i] = 1
ans = 0
for i in range(h):
    for j in range(w):
       ans = max(L[i][j]+R[i][j]+U[i][j]+D[i][j]-3,ans)
print(ans)

Solution (Python):
h,w = map(int,input().split())
S = [input() for i in range(h)]
yoko = [[1]*w for _ in range(h)]
tate = [[1]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == '
            yoko[i][j] = 0
        else:
            if j != 0:
                yoko[i][j] += yoko[i][j-1]
for i in range(h):
    for j in range(w-1,-1,-1):
        if yoko[i][j] == 0:
            continue
        else:
            if j != w-1:
                yoko[i][j] = max(yoko[i][j],yoko[i][j+1])
for j in range(w):
    for i in range(h):
        if S[i][j] == '
            tate[i][j] = 0
        else:
            if i != 0:
                tate[i][j] += tate[i-1][j]
for j in range(w):
    for i in range(h-1,-1,-1):
        if tate[i][j] == 0:
            continue
        else:
            if i != h-1:
                tate[i][j] = max(tate[i][j],tate[i+1][j])
res = 0
for i in range(h):
    for j in range(w):
        res = max(res,tate[i][j]+yoko[i][j]-1)
print(res)

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

tate_value = [[0]*W for i in range(H)]
yoko_value = [[0]*W for i in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j] == '
      yoko_value[i][j] = 0
    else:
      if j==0:
        left = 0
        right = W-1
        for k in range(0,W):
          if S[i][k] == '
            right = k-1
            break
        yoko_value[i][j] = right+1
      else:
        if S[i][j-1] == '.':
          yoko_value[i][j] = yoko_value[i][j-1]
        else:
          right = W-1
          for k in range(j,W):
            if S[i][k] == '
              right = k-1
              break
          yoko_value[i][j] = right-j+1

for j in range(W):
  for i in range(H):
    if S[i][j] == '
      tate_value[i][j] = 0
    else:
      if i==0:
        up = 0
        down = H-1
        for k in range(0,H):
          if S[k][j] == '
            down = k-1
            break
        tate_value[i][j] = down+1
      else:
        if S[i-1][j] == '.':
          tate_value[i][j] = tate_value[i-1][j]
        else:
          down = H-1
          for k in range(i,H):
            if S[k][j] == '
              down = k-1
              break
          tate_value[i][j] = down-i+1
          
max = 0
for i in range(H):
  for j in range(W):
    temp = yoko_value[i][j] + tate_value[i][j]-1
    if temp>max:
      max = temp
      
print(max)

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):
inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    score[h]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)

Solution (Python):
H, W = [int(x) for x in input().split()]
S_list = [input() for _ in range(H)]
cnt = [[0] * W for _ in range(H)]

for i in range(H):
    done = [0] * W
    for j in range(W):
        if (S_list[i][j] == '
        elif (done[j]): continue
        else:
            
            k = 0
            while (j+k < W):
                if (S_list[i][j+k] == '
                k += 1
            
            for l in range(k):
                cnt[i][j+l] += k
                done[j+l] = 1
for i in range(W):
    done = [0] * H
    for j in range(H):
        if (S_list[j][i] == '
        elif (done[j]): continue
        else:
            
            k = 0
            while (j+k < H):
                if (S_list[j+k][i] == '
                k += 1
            
            for l in range(k):
                cnt[j+l][i] += k
                done[j+l] = 1
print(max(map(max, cnt))-1)

Solution (Python):

"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

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

A = [""]*H 

INF = 2000


D = [[0]*(W+1) for h in range(H+1)]

for h in range(H):
    A[h] = input()
    for w in range(W):
        if A[h][w] == '.':
            D[h][w] = 1           

def main(): 
    
    
    
    T = [[0]*(W+1) for h in range(H+1)]
    Y = [[0]*(W+1) for h in range(H+1)]
    
    for h in range(H):
        cnt = 0
        for w in range(W):
            if D[h][w] == 0:
                cnt = 0
                continue
            else:
                Y[h][w] += cnt
                cnt+=1    
    for h in range(H):
        for w in reversed(range(W)):
            if D[h][w] == 0:
               continue
            else:
               Y[h][w] = max(Y[h][w], Y[h][w+1])                           
            
    for w in range(W):
        cnt = 0
        for h in range(H):
            if D[h][w] == 0:
                cnt = 0
                continue
            else:
                T[h][w] += cnt
                cnt+=1
    for w in range(W):
        for h in reversed(range(H)):
            if D[h][w] == 0:
                continue
            else:
                T[h][w] = max(T[h][w], T[h+1][w])
    
    
    res = 0
    for w in range(W):
        for h in range(H):
            res = max(res, D[h][w]+Y[h][w]+T[h][w])
    print(int(res))
            
            
                

    
if __name__ == '__main__':
    main()

Solution (Python):
l = input().split()
H = int(l[0])
W = int(l[1])

S = []
for i in range(H):
    l = input().split()
    S.append(l[0])












HL = []
for i in range(H):
    l = 0
    begin = 0
    tmp = []
    for j in range(W):
        if S[i][j] == '.':
            l += 1
        else:
            tmp.extend([l]*(j - begin))
            tmp.append(0)
            begin = j + 1
            l = 0
    if begin != W:
        tmp.extend([l]*(W - begin))
    HL.append(tmp)

WL = []
for i in range(W):
    l = 0
    begin = 0
    tmp = []
    for j in range(H):
        if S[j][i] == '.':
            l += 1
        else:
            tmp.extend([l]*(j - begin))
            tmp.append(0)
            begin = j + 1
            l = 0
    if begin != H:
        tmp.extend([l]*(H - begin))
    WL.append(tmp)

max_l = 0
for i in range(H):
    for j in range(W):
        l = HL[i][j] + WL[j][i]
        max_l = max(l, max_l)
print(max_l - 1)

Solution (Python):
import numpy as np
from pprint import pprint


def solve(MM, H, W):

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

    for i in range(H):
        i_r = H - 1 - i

        
        for j in range(W):
            j_r = W - 1 - j

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

            
            if MM[i][j_r]:
                if j_r == W - 1:
                    R[i][j_r] = 1
                else:
                    R[i][j_r] = R[i][j_r + 1] + 1

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

            
            if MM[i_r][j]:
                if i_r == H - 1:
                    D[i_r][j] = 1
                else:
                    D[i_r][j] = D[i_r + 1][j] + 1

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


def solve2(MM, H, W):
    L, R, U, D = [MM.copy() for _ in range(4)]

    
    for i in range(1, H):
        U[i] = (U[i - 1] + 1) * MM[i]
        i_r = H - 1 - i
        D[i_r] = (D[i_r + 1] + 1) * MM[i_r]

    MM_T = MM.T
    L_T, R_T = L.T, R.T

    
    for i in range(1, W):
        L_T[i] = (L_T[i - 1] + 1) * MM_T[i]
        i_r = W - 1 - i
        R_T[i_r] = (R_T[i_r + 1] + 1) * MM_T[i_r]

    L, R = L_T.T, R_T.T
    print((L + R + U + D).max() - 3)


def stdin():
    H, W = [int(x) for x in input().split()]
    MM = np.zeros((H, W), dtype=int)

    for i in range(H):
        line = str(input())

        for j in range(W):
            if line[j] != '
                MM[i][j] = 1

    solve2(MM, H, W)


if __name__ == '__main__':
    stdin()

Solution (Python):
import sys

import numpy as np


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):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
u = [[0] * (w + 2) for _ in range(h + 2)]
d = [[0] * (w + 2) for _ in range(h + 2)]
l = [[0] * (w + 2) for _ in range(h + 2)]
r = [[0] * (w + 2) for _ in range(h + 2)]

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

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

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

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

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

Solution (Python):
import sys

def calc(a, H, W):
    
    for j in range(H):
        prev = 0
        start = 0
        for i in range(W + 1):
            if a[j][i] > 0:
                if prev == 0:
                    start = i
                    prev = 1
            else:
                if prev == 1:
                    num = i - start
                    for k in range(start, i):
                        a[j][k] = num
                    prev = 0
    
    for i in range(W):
        prev = 0
        start = 0
        for j in range(H + 1):
            if a[j][i] > 0:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    num = j - start
                    for k in range(start, j):
                        a[k][i] += num - 1
                    prev = 0


sin = sys.stdin
H, W = map(int, sin.readline().split())
a = [[0] * (W + 1) for _ in range(H + 1)]

for j in range(H):
    for i, c in enumerate(sin.readline()):
        if c == '.':
            a[j][i] = 1

calc(a, H, W)

ans = 0
for row in a:
    ans = max(ans, max(row))
print(ans)