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
from collections import deque, defaultdict, Counter

import math
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [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 S[i][j] == '
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		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 i in range(H):
	for j in range(W):
		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 range(H-1, -1, -1):
	for j in range(W):
		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

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):

import numpy as np

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

s = [list(input()) for i in range(h)]
b = np.array(s)
b = np.where(b == '.', 1, 0)

u = np.zeros((h, w), dtype=np.int)
for i in range(1, h):
    u[i] += (u[i - 1] + 1) * b[i - 1]

d = np.zeros((h, w), dtype=np.int)
for i in range(h - 2, -1, -1):
    d[i] += (d[i + 1] + 1) * b[i + 1]

l = np.zeros((h, w), dtype=np.int)
for j in range(1, w):
    l[:, j] += (l[:, j - 1] + 1) * b[:, j - 1]

r = np.zeros((h, w), dtype=np.int)
for j in range(w - 2, -1, -1):
    r[:, j] += (r[:, j + 1] + 1) * b[:, j + 1]

print(((u + d + l + r) * b).max() + 1)

Solution (Python):
from __future__ import print_function


import sys
input = sys.stdin.readline

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return




































import random




def main():
    row,col = map(int, input().split())
    grid = [[] for _ in range(row)]
    cnt_grid_row = [[0]*col for _ in range(row)]
    cnt_grid_col = [[0]*col for _ in range(row)]
    
    for i in range(row):
        grid[i] = input()
    

    for i in range(len(grid)):
        cnt_temp=0
        start_temp=0
        for j in range(len(grid[i])):
            if grid[i][j]=='.':
                cnt_temp+=1
            if grid[i][j]=='
                for k in range(start_temp,j):
                    cnt_grid_row[i][k]=cnt_temp
                start_temp=j+1
                cnt_temp=0
                cnt_grid_row[i][j]=0
            elif j==col-1:
                for k in range(start_temp,col):
                    cnt_grid_row[i][k]=cnt_temp




    for i in range(col):
        cnt_temp=0
        start_temp=0
        for j in range(row):
            if grid[j][i]=='.':
                cnt_temp+=1
            if grid[j][i]=='
                for k in range(start_temp,j):
                    cnt_grid_col[k][i]=cnt_temp
                start_temp=j+1
                cnt_temp=0
                cnt_grid_col[j][i]=0
            elif j==row-1:
                for k in range(start_temp,row):
                    cnt_grid_col[k][i]=cnt_temp

    
    
    
    

    

    
    
    
    

    max=0
    for i in range(row):
        for j in range(col):
            if grid[i][j]!='
                if cnt_grid_col[i][j]+cnt_grid_row[i][j]-1>max:
                    max=cnt_grid_col[i][j]+cnt_grid_row[i][j]-1
    print(max)

    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from collections import deque, defaultdict, Counter

from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [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 S[i][j] == '
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		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 i in range(H):
	for j in range(W):
		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 range(H-1, -1, -1):
	for j in range(W):
		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

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):
import sys



from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [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 S[i][j] == '
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		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 i in range(H):
	for j in range(W):
		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 range(H-1, -1, -1):
	for j in range(W):
		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

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):
import sys





from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [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 S[i][j] == '
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		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 i in range(H):
	for j in range(W):
		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 range(H-1, -1, -1):
	for j in range(W):
		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

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):
import sys






from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [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 S[i][j] == '
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		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 i in range(H):
	for j in range(W):
		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 range(H-1, -1, -1):
	for j in range(W):
		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

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):
import sys










def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

H, W = MAP()
S = [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 S[i][j] == '
			L[i][j] = 0
		elif j == 0:
			L[i][j] = 1
		else:
			L[i][j] = L[i][j-1] + 1

for i in range(H):
	for j in range(W-1, -1, -1):
		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 i in range(H):
	for j in range(W):
		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 range(H-1, -1, -1):
	for j in range(W):
		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






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):
def solve():
    h, w = map(int, input().split())
    S = list(input() + '
    H = [[0] * w for _ in range(h + 1)]
    W = [[0] * w for _ in range(h + 1)]
    for r in range(h):
        c = 0
        while c < w:
            if S[r][c] == '.':
                t = S[r][c:].find('
                for j in range(c, c + t):
                    W[r][j] = t
                c += t
            c += 1
    for c in range(w):
        r = 0
        while r < h:
            if S[r][c] == '.':
                t = r + 1
                cnt = 1
                while S[t][c] == '.':
                    t += 1
                    cnt += 1
                for i in range(r, t):
                    H[i][c] = cnt
                r = t
            r += 1
    ans = 0
    for r in range(h):
        for c in range(w):
            ans = max(ans, H[r][c] + W[r][c] - 1)
    print(ans)
solve()

Solution (Python):
import numpy as np
import sys

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        S = [0 if c == '
        A.append(S)

    A = np.array(A)
    up = np.zeros((H+1, W), dtype=np.int)
    down = np.zeros((H+1, W), dtype=np.int)
    right = np.zeros((H, W+1), dtype=np.int)
    left = np.zeros((H, W+1), dtype=np.int)

    for i in range(1, H+1):
        up[i] = (up[i-1] + 1) * A[i-1]
        down[H-i] = (down[H-i+1] + 1) * A[H-i]

    for i in range(1, W+1):
        right[:, i] = (right[:, i-1] + 1) * A[:, i-1]
        left[:, W-i] = (left[:, W-i+1] + 1) * A[:, W-i]

    R = (up[1:] + down[:H] - 1) * A
    C = (right[:, 1:] + left[:, :W] - 1) * A
    W = (R + C - 1) * A
    return W.max()


if __name__ == '__main__':
    print(main())

Solution (Python):
h, w = map(int, input().split())
s = [input() for _ in range(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):
  for j in range(w):
    if s[i][j] == '.':
      l[i][j] = l[i][j-1] + 1
      u[i][j] = u[i-1][j] + 1
    if s[i][-j-1] == '.':
      r[i][-j-1] = r[i][-j] + 1
    if s[-i-1][j] == '.':
      d[-i-1][j] = d[-i][j] + 1
    
torch = 0
for i in range(h):
  for j in range(w):
    torch = max(torch, l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)

print(torch)

Solution (Python):
import numpy as np
import sys
 
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] * S[h]
    downs[H - h - 1] = (downs[H - h] + 1) * S[H - h] * S[H - h-1]
for w in range(1, W):
    lefts[:, w] = (lefts[:, w - 1] + 1) * S[:, w - 1] * S[:, w]
    rights[:, W - w - 1] = (rights[:, W - w] + 1) * S[:, W - w] * S[:, W - w-1]
print(((ups + downs + lefts + rights) * S).max() + 1)

Solution (Python):
import numpy as np
import sys

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        S = [0 if c == '
        A.append(S)

    A = np.array(A)
    up = np.zeros((H+1, W), dtype=np.int)
    down = np.zeros((H+1, W), dtype=np.int)
    right = np.zeros((H, W+1), dtype=np.int)
    left = np.zeros((H, W+1), dtype=np.int)

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

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

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

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

    R = (up[1:] + down[:H] - 1) * A
    C = (right[:, 1:] + left[:, :W] - 1) * A
    W = (R + C - 1) * A
    return W.max()


if __name__ == '__main__':
    print(main())

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
hc = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            if j > 0:
                hc[i][j] = hc[i][j - 1] + 1
            else:
                hc[i][j] = 1
for i in range(h):
    for j in range(w - 1, -1, -1):
        if s[i][j] == ".":
            if j < w - 1:
                if hc[i][j] < hc[i][j + 1]:
                    hc[i][j] = hc[i][j + 1]
wc = [[0] * h for i in range(w)]
for i in range(w):
    for j in range(h):
        if s[j][i] == ".":
            if j > 0:
                wc[i][j] = wc[i][j - 1] + 1
            else:
                wc[i][j] = 1
for i in range(w):
    for j in range(h - 1, -1, -1):
        if s[j][i] == ".":
            if j < h - 1:
                if wc[i][j] < wc[i][j + 1]:
                    wc[i][j] = wc[i][j + 1]
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, hc[i][j] + wc[j][i] - 1)
print(ans)

Solution (Python):
h,w = map(int,input().split())
s = [input() for _ in range(h)]
yoko = []
tate = []
for i in range(h):
    l = []
    k = s[i][0]
    m = 1
    for j in range(1,w):
        if s[i][j]!=k:
            if k=='.':
                l += [m]*m
            else:
                l += [0]*m
            m = 1
            k = s[i][j]
        else:
            m += 1
    if k=='.':
        l += [m]*m
    else:
        l += [0]*m
    yoko.append(l)

for i in range(w):
    l = []
    k = s[0][i]
    m = 1
    for j in range(1,h):
        if s[j][i]!=k:
            if k=='.':
                l += [m]*m
            else:
                l += [0]*m
            m = 1
            k = s[j][i]
        else:
            m += 1
    if k=='.':
        l += [m]*m
    else:
        l += [0]*m
    tate.append(l)
ans = 0
for i in range(h):
    for j in range(w):
        if yoko[i][j] and tate[j][i]:
            ans = max(ans,yoko[i][j]+tate[j][i]-1)
print(ans)

Solution (Python):

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

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

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

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):
def sol():
    h,w=map(int,input().split())
    l=[]
    x=[[0]*w for i in range(h)]
    y=[[0]*w for i in range(h)]
    for i in range(h):
        s=input()
        l.append(s)
    for i in range(h):
        for j in range(w):
            if j==0 and l[i][j]==".":
                x[i][j]=1
            elif l[i][j]==".":
                x[i][j]=x[i][j-1]+1
            if i==0 and l[i][j]==".":
                y[i][j]=1
            elif l[i][j]==".":
                y[i][j]=y[i-1][j]+1
    for i in range(h):
        for j in range(w):
            a=-1*(i+1)
            b=-1*(j+1)
            if i==j==0: continue
            if l[a][b]=="
            x[a][b]=max(x[a][b],x[a][b+1])
            if i>0: y[a][b]=max(y[a][b],y[a+1][b])

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

if __name__=="__main__":
    sol()

Solution (Python):

import sys
import math
import numpy as np
import itertools


h,w = (int(i) for i in input().split())  


grid = []
for i in range(h):
    array = list(input())
    grid.append(array)
b = np.array(grid)
b = np.where(b == ".", 1, 0)

a1 = np.zeros((h,w), dtype=np.int)
a2 = np.zeros((h,w), dtype=np.int)
a3 = np.zeros((h,w), dtype=np.int)
a4 = np.zeros((h,w), dtype=np.int)


for i in range(1,h):
    a1[i] += (a1[i-1]+1)*b[i-1]

for i in range(h-2,-1,-1):
    a2[i] += (a2[i+1]+1)*b[i+1]

for i in range(1,w):
    a3[:, i] += (a3[:, i-1]+1)*b[:, i-1]

for i in range(w-2,-1,-1):
    a4[:, i] += (a4[:, i+1]+1)*b[:, i+1]



answer = ( (a1+a2+a3+a4)*b ).max()

print(answer+1)

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

s=[input() for i in range(h)]











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

count=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            count+=1
        if s[i][j]=='
            for k in range(count):
                yoko[i][j-k-1]=count
            count=0
    if count>0:
        for k in range(count):
            yoko[i][j-k]=count
        count=0



for j in range(w):
    for i in range(h):
        if s[i][j]=='.':
            count+=1
        if s[i][j]=='
            for k in range(count):
                tate[i-k-1][j]=count
            count=0
    if count>0:
        for k in range(count):
            tate[i-k][j]=count
        count=0



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

Solution (Python):

import sys
import bisect


def solve(H: int, W: int, S: "List[str]"):
    L = [[0 for _ in range(W)] for _ in range (H)]
    R = [[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):
        for j in range(W):
            if S[i][j] == "
                L[i][j] = 0
            elif 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] == "
                R[i][j] = 0
            elif j < W-1:
                R[i][j] = R[i][j+1] + 1
            else:
                R[i][j] = 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] = U[i-1][j] + 1
            else:
                U[i][j] = 1

        for i in range(H-1,-1,-1):
            if S[i][j] == "
                D[i][j] = 0
            elif i < H-1:
                D[i][j] = D[i+1][j] + 1
            else:
                D[i][j] = 1

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

    print(res)






def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    S = [ next(tokens) for _ in range(H) ]  
    solve(H, W, S)

if __name__ == '__main__':
    main()

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

s = [input() for i in range(h)]

board_w = [[0 for _ in range(w)] for _ in range(h)]
board_h = [[0 for _ in range(w)] for _ in range(h)]


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

    for j in reversed(range(w-1)):
        if board_w[i][j] == 0:
            continue
        board_w[i][j] = max(board_w[i][j], board_w[i][j+1])

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

    for j in reversed(range(h-1)):
        if board_h[j][i] == 0:
            continue
        board_h[j][i] = max(board_h[j][i], board_h[j+1][i])


ans = 0

for i in range(h):
    for j in range(w):
        v = board_w[i][j] + board_h[i][j] - 1
        ans = max(ans, v)

print(ans)

Solution (Python):
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
ans = 0
vert = [[0] * W for _ in range(H)]; hori = [[0] * W for _ in range(H)];
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            hori[i][j] = hori[i][j-1] + 1 if j > 0 else 1
    for j in range(W-2, -1, -1):
        if grid[i][j] == '.' and grid[i][j+1] == '.':
            hori[i][j] = hori[i][j+1] 
for j in range(W):
    for i in range(H):
        if grid[i][j] == '.':
            vert[i][j] = vert[i-1][j] + 1 if i > 0 else 1
    for i in range(H-2, -1, -1):
        if grid[i][j] == '.' and grid[i+1][j] == '.':
            vert[i][j] = vert[i+1][j]
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            ans = max(ans, hori[i][j] + vert[i][j] - 1)
print(ans)

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

    h_count = [[-1 for w in range(W)] for h in range(H)]
    w_count = [[-1 for w in range(W)] for h in range(H)]

    
    for h in range(H):
        row = s_arr[h]
        clearFlag = True
        for w, s in enumerate(row):
            if clearFlag:
                start = w
                end = w
            if s == 0:
                end = w
                clearFlag = False
            else:
                if clearFlag:
                    h_count[h][w] = -1
                else:
                    for iw in range(start, end+1):
                        w_count[h][iw] = end - start + 1
                clearFlag = True
        if clearFlag == False:
            for iw in range(start, max(end + 1, W)):
                w_count[h][iw] = end - start + 1

    
    for w in range(W):
        col = [row[w] for row in s_arr]
        clearFlag = True
        for h, s in enumerate(col):
            if clearFlag:
                start = h
                end = h
            if s == 0:
                end = h
                clearFlag = False
            else:
                if clearFlag:
                    h_count[h][w] = -1
                else:
                    for ih in range(start, end+1):
                        h_count[ih][w] = end - start + 1
                clearFlag = True
        if clearFlag == False:
            for ih in range(start, max(end+1, H)):
                h_count[ih][w] = end - start + 1

    dmatprint(h_count)
    dmatprint(w_count)
    mx_ans = 0
    for h in range(H):
        for w in range(W):
            if s_arr[h][w] == 0:
                ans = h_count[h][w] + w_count[h][w] - 1
                if ans >= mx_ans:
                    mx_ans = ans

    print(mx_ans)
    dmatprint(s_arr)
solve()

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return  sys.stdin.readline
    else:
        return fileobject.readline

def calc(field, H, W):
    ret =  [[0] * (W + 1) for i in range(H + 1)]
    for i in range(H):
        cnt = 0
        cnt_list = []
        for j in range(W + 1):
            if field[i][j] == "
                cnt_list.append(cnt)
                cnt = 0
            else:
                cnt += 1
        k = 0
        for j in range(W + 1):
            if field[i][j] == ".":
                ret[i][j] = cnt_list[k]
            else:
                ret[i][j] = 0
                k+=1
    return ret





def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    field = [["
    field_T = [["
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            field[i][j] = input_raw[0][j]
            field_T[j][i] = field[i][j]
    ret1 = calc(field, H, W)
    ret2 = calc(field_T, W, H)
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, ret1[i][j] + ret2[j][i] - 1)
    print ans

if __name__ == '__main__':
    main()

Solution (Python):
h, w = map(int, input().split())
m = [input().strip() for _ in range(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 y in range(h):
    for x in range(w):
        dy = y
        uy = h - y - 1
        if m[dy][x] == '.':
            if dy == 0:
                d[dy][x] = 1
            else:
                d[dy][x] = d[dy - 1][x] + 1
        if m[uy][x] == '.':
            if uy == (h - 1):
                u[uy][x] = 1
            else:
                u[uy][x] = u[uy + 1][x] + 1

        lx = x
        rx = w - x - 1
        if m[y][lx] == '.':
            if lx == 0:
                l[y][lx] = 1
            else:
                l[y][lx] = l[y][lx - 1] + 1
        if m[y][rx] == '.':
            if rx == (w - 1):
                r[y][rx] = 1
            else:
                r[y][rx] = r[y][rx + 1] + 1

ans = 0
for y in range(h):
    for x in range(w):
        t = l[y][x] + r[y][x] + u[y][x] + d[y][x] - 3
        if t > ans:
            ans = t
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
import numpy

def main():
    H, W = LI()
    S = []
    for i in range(H):
        S.append(list(SI()))
    S = (numpy.array(S) == '.')
    L = numpy.zeros((H, W), dtype=int)
    R = numpy.zeros((H, W), dtype=int)
    T = numpy.zeros((H, W), dtype=int)
    B = numpy.zeros((H, W), dtype=int)
    for i in range(H):
        L[i] = (L[i - 1] + 1) * S[i]
        R[-1 - i] = (R[-i] + 1) * S[-1 - i]
    for i in range(W):
        T[:, i] = (T[:, i - 1] + 1) * S[:, i]
        B[:, -1 - i] = (B[:, -i] + 1) * S[:, -1 - i]
    ans = numpy.max(L + R + T + B) - 3
    return ans

print(main())

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

S_h1 = [[0]*(W+1) for i in range(H)]
S_w1 = [[0]*(H+1) for i in range(W)]
S_h2 = [[0]*(W+1) for i in range(H)]
S_w2 = [[0]*(H+1) for i in range(W)]

for x in range(W):
    for y in range(H):
        if S[y][x] == '
            S_h1[y][x] = 0
            S_w1[x][y] = 0
        else:
            S_h1[y][x] += S_h1[y][x-1]+1
            S_w1[x][y] += S_w1[x][y-1]+1

for x in range(W-1,-1,-1):
    for y in range(H-1,-1,-1):
        if S[y][x] == '
            S_h2[y][x] = 0
            S_w2[x][y] = 0
        else:
            S_h2[y][x] += S_h2[y][x+1]+1
            S_w2[x][y] += S_w2[x][y+1]+1

ans = 0
for x in range(W):
    for y in range(H):
        if S[y][x] == '.':
            ans = max(ans,S_h1[y][x]+S_h2[y][x]+S_w1[x][y]+S_w2[x][y]-3)
 
print(ans)

Solution (Python):


H,W = map(int,input().split())
S = [input() for _ in range(H)]
L,R,D,U = [[[0]*W for _ in range(H)] for i in range(4)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1

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

print(ans)