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())
raw = []
for _ in range(h):
  raw.append(input())
ver = [[] for _ in range(h)]
hrz = [[] for _ in range(h)]
for x in range(h):
  st = 0
  for y in range(w):
    if raw[x][y] == '
      for k in range(st,y):
        ver[x].append(y-st)
      ver[x].append(0)
      st = y + 1
  for k in range(st,w):
    ver[x].append(w-st)

for y in range(w):
  st = 0
  for x in range(h):
    if raw[x][y] == '
      for k in range(st,x):
        hrz[k].append(x-st)
      hrz[x].append(0)
      st = x + 1
  for k in range(st,h):
    hrz[k].append(h-st)

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

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
r = [[0] * w for i in range(h)]
l = [[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 range(h):
    s[i] = input()


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

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

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

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

def main():
    H, W = map(int, input().split())

    map_ = np.array([list(input().strip()) for i in range(H)]) == "."

    up = np.zeros((H, W), dtype=int)
    down = np.zeros((H, W), dtype=int)
    left = np.zeros((H, W), dtype=int)
    right = np.zeros((H, W), dtype=int)

    for i in range(1, H):
        up[i] = (up[i-1] + 1) * map_[i-1]
    for i in range(H-2, -1, -1):
        down[i] = (down[i+1] + 1) * map_[i+1]
    for j in range(1, W):
        left[:,j] = (left[:,j-1] + 1) * map_[:,j-1]
    for j in range(W-2, -1, -1):
        right[:,j] = (right[:,j+1] + 1) * map_[:,j+1]
    
    print(((up + down + left + right + 1) * map_).max())


if __name__ == "__main__":
    main()

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

M_W = [[0] * W for i in range(H)]
M_H = [[0] * W for i in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      if j == 0:
        M_W[i][j] = 1
      else:
        M_W[i][j] = M_W[i][j - 1] + 1
  for j in range(W-2,-1,-1):
    if S[i][j] == '.' and S[i][j+1] == '.':
      M_W[i][j] = M_W[i][j+1]

for j in range(W):
  for i in range(H):
    if S[i][j] == '.':
      if i == 0:
        M_H[i][j] = 1
      else:
        M_H[i][j] = M_H[i-1][j] + 1
  for i in range(H-2,-1,-1):
    if S[i][j] == '.' and S[i+1][j] == '.':
      M_H[i][j] = M_H[i+1][j]




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

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

yoko=[[0]*2005 for _ in range(2005)]
tate=[[0]*2005 for _ in range(2005)]

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

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

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

Solution (Python):
h,w=map(int,input().split())
data=[list(input()) for i in range(h)]
yoko=[[0]*w for i in range(h)]
for i in range(h):
	j=0
	while j <w:
		if data[i][j]=='
			j+=1
		else:
			start=j
			while j<w-1:
				j+=1
				if data[i][j]=='
					for k in range(start,j):
						yoko[i][k]=j-start-1
					j+=1
					break
			else:
				j+=1
				for k in range(start,j):
					yoko[i][k]=j-start-1
				j+=1



for j in range(w):
	i=0
	while i <h:
		if data[i][j]=='
			i+=1
		else:
			start=i
			while i<h-1:
				i+=1
				if data[i][j]=='
					for k in range(start,i):
						yoko[k][j]+=i-start-1
					i+=1
					break
			else:
				i+=1
				for k in range(start,i):
					yoko[k][j]+=i-start-1
				i+=1


for i in range(h):
	
	yoko[i]=max(yoko[i])
print(max(yoko)+1)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    L = [[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 i == 0:
                U[i][j] = 1 if s[i][j] == "." else 0
                D[-i-1][j] = 1 if s[-i-1][j] == "." else 0
            else:
                U[i][j] = U[i-1][j] + 1 if s[i][j] == "." else 0
                D[-i-1][j] = D[-i][j] + 1 if s[-i-1][j] == "." else 0
            if j == 0:
                L[i][j] = 1 if s[i][j] == "." else 0
                R[i][-j-1] = 1 if s[i][-j-1] == "." else 0
            else:
                L[i][j] = L[i][j-1] + 1 if s[i][j] == "." else 0
                R[i][-j-1] = R[i][-j] + 1 if s[i][-j-1] == "." else 0
    m_l = 0
    for i in range(h):
        for j in range(w):
            m_l = max(m_l, R[i][j] + L[i][j] + U[i][j] + D[i][j] - 3)
    print(m_l)


if __name__ == '__main__':
    slove()

Solution (Python):

h,w = map(int,input().split())
raw = []
for x in range(h):
  raw.append(input())
xx = []
for x in range(h):
  now = []
  tmp = 0
  for y in range(w):
    if raw[x][y] == '.':
      tmp += 1
    else:
      now += [tmp] * tmp
      tmp = 0
      now.append(0)
  now += [tmp] * tmp
  xx.append(now)
yy = []
for y in range(w):
  now = []
  tmp = 0
  for x in range(h):
    if raw[x][y] == '.':
      tmp += 1
    else:
      now += [tmp] * tmp
      tmp = 0
      now.append(0)
  now += [tmp] * tmp
  yy.append(now)
'''
for x in range(h):
  print(xx[x])
for y in range(w):
  print(yy[y])
'''
maxi = 0
for x in range(h):
  for y in range(w):
    maxi = max(maxi,xx[x][y]+yy[y][x]-1)
print(maxi)

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


def main():
    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)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if j != 0:
                L[i][j] = L[i][j - 1]
            if s[i][j] == ".":
                L[i][j] += 1
            else:
                L[i][j] = 0
    for i in range(h):
        for j in range(w - 1, -1, -1):
            if j != w - 1:
                R[i][j] = R[i][j + 1]
            if s[i][j] == ".":
                R[i][j] += 1
            else:
                R[i][j] = 0
    for j in range(w):
        for i in range(h):
            if i != 0:
                U[i][j] = U[i - 1][j]
            if s[i][j] == ".":
                U[i][j] += 1
            else:
                U[i][j] = 0
    for j in range(w):
        for i in range(h - 1, -1, -1):
            if i != h - 1:
                D[i][j] = D[i + 1][j]
            if s[i][j] == ".":
                D[i][j] += 1
            else:
                D[i][j] = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    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)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if j != 0:
                L[i][j] = L[i][j - 1]
            if s[i][j] == ".":
                L[i][j] += 1
            else:
                L[i][j] = 0
    for i in range(h):
        for j in range(w - 1, -1, -1):
            if j != w - 1:
                R[i][j] = R[i][j + 1]
            if s[i][j] == ".":
                R[i][j] += 1
            else:
                R[i][j] = 0
    for j in range(w):
        for i in range(h):
            if i != 0:
                U[i][j] = U[i - 1][j]
            if s[i][j] == ".":
                U[i][j] += 1
            else:
                U[i][j] = 0
    for j in range(w):
        for i in range(h - 1, -1, -1):
            if i != h - 1:
                D[i][j] = D[i + 1][j]
            if s[i][j] == ".":
                D[i][j] += 1
            else:
                D[i][j] = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    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)]
ans = 0
for i in range(h):
    for j in range(w):
        if j != 0:
            L[i][j] = L[i][j - 1]
        if s[i][j] == ".":
            L[i][j] += 1
        else:
            L[i][j] = 0
for i in range(h):
    for j in range(w - 1, -1, -1):
        if j != w - 1:
            R[i][j] = R[i][j + 1]
        if s[i][j] == ".":
            R[i][j] += 1
        else:
            R[i][j] = 0
for j in range(w):
    for i in range(h):
        if i != 0:
            U[i][j] = U[i - 1][j]
        if s[i][j] == ".":
            U[i][j] += 1
        else:
            U[i][j] = 0
for j in range(w):
    for i in range(h - 1, -1, -1):
        if i != h - 1:
            D[i][j] = D[i + 1][j]
        if s[i][j] == ".":
            D[i][j] += 1
        else:
            D[i][j] = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            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())
M = []
for i in range(h):
    M.append(input())
L = []
R = []
U = []
D = []
Total = []
for i in range(h):
    s = [0]*w
    L.append(s)
for i in range(h):
    s = [0]*w
    R.append(s)
for i in range(h):
    s = [0]*w
    U.append(s)
for i in range(h):
    s = [0]*w
    D.append(s)
for i in range(h):
    s = [0]*w
    Total.append(s)
for i in range(h):
    for j in range(w):
        if M[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1]+1
for i in range(h):
    for j in range(w-1,-1,-1):
        if M[i][j] == '.':
            if 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 M[i][j] == '.':
            if 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 M[i][j] == '.':
            if 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):
        Total[i][j] += L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,Total[i][j])
print(ans)

Solution (Python):
h,w = map(int,input().split())
M = []
for i in range(h):
    M.append(input())
L = []
R = []
U = []
D = []
Total = []
for i in range(h):
    s = [0]*w
    L.append(s)
for i in range(h):
    s = [0]*w
    R.append(s)
for i in range(h):
    s = [0]*w
    U.append(s)
for i in range(h):
    s = [0]*w
    D.append(s)
for i in range(h):
    s = [0]*w
    Total.append(s)
for i in range(h):
    for j in range(w):
        if M[i][j] == '
            None
        else:
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1]+1
for i in range(h):
    for j in range(w-1,-1,-1):
        if M[i][j] == '
            None
        else:
            if 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 M[i][j] == '
            None
        else:
            if 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 M[i][j] == '
            None
        else:
            if 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):
        Total[i][j] += L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
ans = 0
for i in range(h):
    for j in range(w):
        if Total[i][j] > ans:
            ans = Total[i][j]
print(ans)