AtCoder Beginner Contest 129 - Lamp

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-----
4 6
#..#..
.....#
....#.
#.#...

-----Sample Output-----
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.

Difficulty: MEDIUM_HARD

Starter code:

Solutions:
(h, w) = map(int, input().split())
grid = [[c == '.' for c in input()] for _ in range(h)]
(L, R, U, D) = eval('[[0]*(w+2) for _ in range(h+2)],' * 4)
for y in range(h):
	for x in range(w):
		if grid[y][x]:
			L[y + 1][x + 1] = L[y + 1][x] + 1
		if grid[y][w - x - 1]:
			R[y + 1][w - x] = R[y + 1][w - x + 1] + 1
for x in range(w):
	for y in range(h):
		if grid[y][x]:
			U[y + 1][x + 1] = U[y][x + 1] + 1
		if grid[h - y - 1][x]:
			D[h - y][x + 1] = D[h - y + 1][x + 1] + 1
a = 0
for y in range(1, h + 1):
	for x in range(1, w + 1):
		a = max(a, L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3)
print(a)


a = []
(h, w) = map(int, input().split())
for i in range(h):
	a.append(input() + '#')
a.append('#' * (w + 1))
b = [[0] * (w + 1) for i in range(h + 1)]
c = [[0] * (w + 1) for i in range(h + 1)]
for i in range(h + 1):
	t = 0
	for j in range(w + 1):
		if a[i][j] == '#':
			for k in range(t):
				b[i][j - k - 1] = t
			t = 0
		else:
			t += 1
for j in range(w + 1):
	t = 0
	for i in range(h + 1):
		if a[i][j] == '#':
			for k in range(t):
				c[i - k - 1][j] = t
			t = 0
		else:
			t += 1
ans = 0
for i in range(h + 1):
	for j in range(w + 1):
		ans = max(b[i][j] + c[i][j] - 1, ans)
print(ans)


(h, w) = map(int, input().split())
s = []
for i in range(h):
	s += [input()]
sh = [[0 for _ in range(h)] for _ in range(w)]
sw = [[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] == '.':
			c += 1
		else:
			sw[i][j - c:j] = [c] * c
			c = 0
	if c > 0:
		sw[i][w - c:w] = [c] * c
for j in range(w):
	c = 0
	for i in range(h):
		if s[i][j] == '.':
			c += 1
		else:
			sh[j][i - c:i] = [c] * c
			c = 0
	if c > 0:
		sh[j][h - c:h] = [c] * c
print(max([sw[i][j] + sh[j][i] for i in range(h) for j in range(w)]) - 1)


(h, w) = map(int, input().split())
ans = [[-3] * w for _ in range(h)]
s = [input() for _ in range(h)]
for i in range(h):
	tmp = 0
	for j in range(w):
		if s[i][j] == '#':
			tmp = 0
		else:
			tmp += 1
		ans[i][j] += tmp
	tmp = 0
	for j in range(w - 1, -1, -1):
		if s[i][j] == '#':
			tmp = 0
		else:
			tmp += 1
		ans[i][j] += tmp
for j in range(w):
	tmp = 0
	for i in range(h):
		if s[i][j] == '#':
			tmp = 0
		else:
			tmp += 1
		ans[i][j] += tmp
	tmp = 0
	for i in range(h - 1, -1, -1):
		if s[i][j] == '#':
			tmp = 0
		else:
			tmp += 1
		ans[i][j] += tmp
print(max((max(ans[i]) for i in range(h))))


import numpy as np
(H, W) = list(map(int, input().split()))
M = [list(input()) for _ in range(H)]
M = (np.array(M) == '.') * 1
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
for i in range(W):
	if i == 0:
		L[:, i] = M[:, i]
		R[:, W - i - 1] = M[:, W - i - 1]
	else:
		L[:, i] = (L[:, i - 1] + 1) * M[:, i]
		R[:, W - i - 1] = (R[:, W - i] + 1) * M[:, W - i - 1]
for i in range(H):
	if i == 0:
		U[i, :] = M[i, :]
		D[H - i - 1, :] = M[H - i - 1, :]
	else:
		U[i, :] = (U[i - 1, :] + 1) * M[i, :]
		D[H - i - 1, :] = (D[H - i, :] + 1) * M[H - i - 1, :]
print(max(np.max(L + R + D + U - 3), 0))


import sys
(H, W) = map(int, next(sys.stdin).split())
xs = [[0] * (W + 2) for _ in range(H + 2)]
ys = [[0] * (W + 2) for _ in range(H + 2)]
for i in range(1, H + 1):
	row = next(sys.stdin)
	for j in range(1, W + 1):
		if row[j - 1] != '.':
			continue
		xs[i][j] = 1 + xs[i][j - 1]
		ys[i][j] = 1 + ys[i - 1][j]
ans = 0
for i in range(H, 0, -1):
	for j in range(W, 0, -1):
		if xs[i][j] == 0:
			continue
		x = xs[i][j] = max(xs[i][j], xs[i][j + 1])
		y = ys[i][j] = max(ys[i][j], ys[i + 1][j])
		ans = max(ans, x + y - 1)
print(ans)


(H, W) = map(int, input().split())
frame = [''.join(['#' for _ in range(W + 2)])]
S = frame + ['#' + input() + '#' for _ in range(H)] + frame
score = [[0 for _ in range(W + 2)] for _ in range(H + 2)]
for i in range(H + 2):
	sharp_j = 0
	for j in range(W + 2):
		if S[i][j] == '#':
			for k in range(sharp_j + 1, j):
				score[i][k] += j - sharp_j - 1
			sharp_j = j
for j in range(W + 2):
	sharp_i = 0
	for i in range(H + 2):
		if S[i][j] == '#':
			for k in range(sharp_i + 1, i):
				score[k][j] += i - sharp_i - 2
			sharp_i = i
ans = 0
for i in range(H + 2):
	for j in range(W + 2):
		ans = max(ans, score[i][j])
print(ans)


(H, W) = map(int, input().split())
S = [input() for _ in range(H)]
up = [[0] * (W + 2) for _ in range(H + 2)]
down = [[0] * (W + 2) for _ in range(H + 2)]
left = [[0] * (W + 2) for _ in range(H + 2)]
right = [[0] * (W + 2) for _ in range(H + 2)]
for i in range(1, H + 1):
	for j in range(1, W + 1):
		if S[i - 1][j - 1] == '.':
			up[i][j] = up[i - 1][j] + 1
			left[i][j] = left[i][j - 1] + 1
		if S[-i][-j] == '.':
			down[-1 - i][-1 - j] = down[-i][-1 - j] + 1
			right[-1 - i][-1 - j] = right[-1 - i][-j] + 1
ans = 0
for i in range(1, H + 1):
	for j in range(1, W + 1):
		ans = max(ans, up[i][j] + down[i][j] + left[i][j] + right[i][j] - 3)
print(ans)


def main():
	import sys
	import numpy as np

	def input():
		return sys.stdin.readline().rstrip()
	(h, w) = map(int, input().split())
	g = np.zeros((h, w), dtype=int)
	for i in range(h):
		g[i] = [int(s == '.') for s in input()]
	L = g.copy()
	R = g.copy()
	U = g.copy()
	D = g.copy()
	for i in range(1, h):
		U[i] = (U[i - 1] + 1) * g[i]
		D[~i] = (D[~i + 1] + 1) * g[~i]
	for j in range(1, w):
		L[:, j] = (L[:, j - 1] + 1) * g[:, j]
		R[:, ~j] = (R[:, ~j + 1] + 1) * g[:, ~j]
	ans = np.max(L + R + U + D - 3)
	print(ans)

def __starting_point():
	main()
__starting_point()


(h, w) = map(lambda x: range(int(x)), input().split())
g = [[c == '.' for c in input()] for _ in h]
a = [[-3] * len(w) for _ in h]
for i in h:
	l = r = 0
	for j in w:
		l = -~l * g[i][j]
		a[i][j] += l
		r = -~r * g[i][~j]
		a[i][~j] += r
for i in w:
	d = u = 0
	for j in h:
		d = -~d * g[j][i]
		a[j][i] += d
		u = -~u * g[~j][i]
		a[~j][i] += u
print(max((a[i][j] for i in h for j in w)))


import sys
import numpy as np
(h, w) = map(int, sys.stdin.readline().split())
grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(h)], dtype='U')
grid = np.pad(grid, 1, mode='constant')

def main():
	cnt = np.zeros((h + 2, w + 2))
	cnt[grid == '.'] = np.inf
	l = cnt.copy()
	r = cnt.copy()
	u = cnt.copy()
	d = cnt.copy()
	for i in range(1, w + 1):
		l[1:h + 1, i] = np.minimum(l[1:h + 1, i], l[1:h + 1, i - 1] + 1)
		i = w + 1 - i
		r[1:h + 1, i] = np.minimum(r[1:h + 1, i], r[1:h + 1, i + 1] + 1)
	for i in range(1, h + 1):
		u[i, 1:w + 1] = np.minimum(u[i, 1:w + 1], u[i - 1, 1:w + 1] + 1)
		i = h + 1 - i
		d[i, 1:w + 1] = np.minimum(d[i, 1:w + 1], d[i + 1, 1:w + 1] + 1)
	res = np.maximum(l + r + u + d - 3, 0).astype(np.int64)
	return np.amax(res)

def __starting_point():
	ans = main()
	print(ans)
__starting_point()


(h, w) = map(int, input().split())
f = lambda : [[0] * w for _ in range(h)]
g = [input() for _ in range(h)]
(l, r) = (f(), f())
for i in range(h):
	lc = rc = 0
	for j in range(w):
		if g[i][j] == '.':
			lc += 1
			l[i][j] = lc
		else:
			lc = 0
		if g[i][-1 - j] == '.':
			rc += 1
			r[i][-1 - j] = rc
		else:
			rc = 0
(d, u) = (f(), f())
for i in range(w):
	dc = uc = 0
	for j in range(h):
		if g[j][i] == '.':
			dc += 1
			d[j][i] = dc
		else:
			dc = 0
		if g[-1 - j][i] == '.':
			uc += 1
			u[-1 - j][i] = uc
		else:
			uc = 0
print(max((l[i][j] + r[i][j] + d[i][j] + u[i][j] - 3 for i in range(h) for j in range(w))))


(h, w) = list(map(int, input().split()))
m = []
for i in range(h):
	mm = []
	for j in input():
		mm.append(1 if j == '#' else 0)
	m.append(mm)
wl = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
	s = 0
	t = 0
	while t < w:
		while t < w and m[i][t] == 0:
			t += 1
		for j in range(s, t):
			wl[i][j] = t - s
		s = t + 1
		t = t + 1
mx = 0
for i in range(w):
	s = 0
	t = 0
	while t < h:
		while t < h and m[t][i] == 0:
			t += 1
		for j in range(s, t):
			k = wl[j][i]
			if mx < k + t - s:
				mx = k + t - s
		s = t + 1
		t = t + 1
print(mx - 1)


import numpy as np
(H, W) = list(map(int, input().split()))
S = np.ones((H, W), dtype=np.bool)
for i in range(H):
	S[i] = [s == '.' for s in input()]
up = np.zeros((H, W), dtype=np.int16)
down = np.zeros((H, W), dtype=np.int16)
left = np.zeros((H, W), dtype=np.int16)
right = np.zeros((H, W), dtype=np.int16)
up[0, :] = S[0, :]
for h in range(1, H):
	up[h, :] = up[h - 1, :] + 1
	up[h, :] *= S[h, :]
down[H - 1, :] = S[H - 1, :]
for h in reversed(list(range(0, H - 1))):
	down[h, :] = down[h + 1, :] + 1
	down[h, :] *= S[h, :]
left[:, 0] = S[:, 0]
for w in range(1, W):
	left[:, w] = left[:, w - 1] + 1
	left[:, w] *= S[:, w]
right[:, W - 1] = S[:, W - 1]
for w in reversed(list(range(0, W - 1))):
	right[:, w] = right[:, w + 1] + 1
	right[:, w] *= S[:, w]
ans = np.max(up + down + left + right - 3)
print(ans)


import numpy as np

def main():
	(h, w) = list(map(int, input().split()))
	s = np.array([[i == '.' for i in input()] for _ in range(h)], dtype=int)
	left = s.copy()
	right = s.copy()
	up = s.copy()
	down = s.copy()
	for i in range(w - 1):
		left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
		right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
	for i in range(h - 1):
		up[i + 1] = (up[i] + 1) * s[i + 1]
		down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
	print((left + right + up + down).max() - 3)

def __starting_point():
	main()
__starting_point()


import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)
(H, W) = list(map(int, input().split()))
S = [list('#' * (W + 2))]
for _ in range(H):
	S.append(list('#' + input() + '#'))
S.append(list('#' * (W + 2)))
S = np.array(S)
north = np.zeros_like(S, dtype='int')
for w in range(1, W + 1):
	north[:, w] = north[:, w - 1] + 1
	north[:, w][S[:, w - 1] == '#'] = 0
	north[:, w][S[:, w] == '#'] = 0
south = np.zeros_like(S, dtype='int')
for w in range(W, 0, -1):
	south[:, w] = south[:, w + 1] + 1
	south[:, w][S[:, w + 1] == '#'] = 0
	south[:, w][S[:, w] == '#'] = 0
east = np.zeros_like(S, dtype='int')
for h in range(1, H + 1):
	east[h, :] = east[h - 1, :] + 1
	east[h, :][S[h - 1] == '#'] = 0
	east[h, :][S[h, :] == '#'] = 0
west = np.zeros_like(S, dtype='int')
for h in range(H, 0, -1):
	west[h, :] = west[h + 1, :] + 1
	west[h, :][S[h + 1] == '#'] = 0
	west[h, :][S[h, :] == '#'] = 0
ans = north + south + east + west
print(ans.max() + 1)


(H, W) = map(int, input().split())
S = [input() for i in range(H)]
A = [[0] * W for i in range(H)]
for i in range(H):
	k = 0
	for j in range(W):
		if S[i][j] == '#':
			k = 0
		else:
			k += 1
		A[i][j] = k
	for j in range(W - 1, 0, -1):
		if A[i][j - 1] != 0 and A[i][j] != 0:
			A[i][j - 1] = A[i][j]
B = [[0] * W for i in range(H)]
for j in range(W):
	k = 0
	for i in range(H):
		if S[i][j] == '#':
			k = 0
		else:
			k += 1
		B[i][j] = k
	for i in range(H - 1, 0, -1):
		if B[i][j] != 0 and B[i - 1][j] != 0:
			B[i - 1][j] = B[i][j]
ans = 0
for i in range(H):
	for j in range(W):
		ans = max(ans, A[i][j] + B[i][j])
print(ans - 1)


import numpy as np
(H, W) = list(map(int, input().split()))
S = []
for h in range(H):
	s = list(input())
	S.append(s)
S = np.array(S)
ruit = np.zeros((H, W))
ruit[0, :] = np.where(S[0, :] == '.', 1, 0)
ruil = np.zeros((H, W))
ruil[:, 0] = np.where(S[:, 0] == '.', 1, 0)
ruir = np.zeros((H, W))
ruir[:, -1] = np.where(S[:, -1] == '.', 1, 0)
ruib = np.zeros((H, W))
ruib[-1, :] = np.where(S[-1, :] == '.', 1, 0)
for h in range(1, H):
	nowt = np.where(S[h, :] == '.', 1, 0)
	ruit[h, :] = (ruit[h - 1, :] + nowt) * nowt
	nowb = np.where(S[-(h + 1), :] == '.', 1, 0)
	ruib[-(h + 1), :] = (ruib[-h, :] + nowb) * nowb
for w in range(1, W):
	nowl = np.where(S[:, w] == '.', 1, 0)
	ruil[:, w] = (ruil[:, w - 1] + nowl) * nowl
	nowr = np.where(S[:, -(w + 1)] == '.', 1, 0)
	ruir[:, -(w + 1)] = (ruir[:, -w] + nowr) * nowr
print(int((ruit + ruib + ruil + ruir - 3).max()))


(H, W) = map(int, input().split())
S = [input() for i in range(H)]
l = [[0] * W for i in range(H)]
r = [[0] * W for i in range(H)]
t = [[0] * W for i in range(H)]
b = [[0] * W for i in range(H)]
for h in range(H):
	for w in range(W):
		if S[h][w] == '.':
			l[h][w] = l[h][w - 1] + 1
			t[h][w] = t[h - 1][w] + 1
		if S[h][W - w - 1] == '.':
			r[h][W - w - 1] = r[h][-w] + 1
		if S[H - h - 1][w] == '.':
			b[H - h - 1][w] = b[-h][w] + 1
ans = 0
for h in range(H):
	for w in range(W):
		ans = max(ans, l[h][w] + r[h][w] + t[h][w] + b[h][w] - 3)
print(ans)


(h, w) = map(int, input().split())
l = list()
l.append('#' * (w + 2))
for i in range(h):
	l.append('#' + input() + '#')
l.append('#' * (w + 2))
si = [[0 for i in j] for j in l]
sj = [[0 for i in j] for j in l]
for i in range(h + 2):
	k = 0
	for j in range(w + 2):
		if l[i][j] == '.':
			k += 1
		else:
			for f in range(j - k, j):
				si[i][f] = k
			k = 0
for j in range(w + 2):
	k = 0
	for i in range(h + 2):
		if l[i][j] == '.':
			k += 1
		else:
			for f in range(i - k, i):
				sj[f][j] = k
			k = 0
ans = 0
for i in range(h + 2):
	for j in range(w + 2):
		ans = max(ans, sj[i][j] + si[i][j])
print(ans - 1)


(h, w) = [int(i) for i in input().split()]
b = [input() for i in range(h)]
l = [[0] * w for _ in [0] * h]
r = [[0] * w for _ in [0] * h]
u = [[0] * w for _ in [0] * h]
d = [[0] * w for _ in [0] * h]
for hi in range(h):
	for wj in range(w):
		if b[hi][wj] == '.':
			l[hi][wj] = l[hi][wj - 1] + 1
			u[hi][wj] = u[hi - 1][wj] + 1
		if b[hi][w - wj - 1] == '.':
			r[hi][w - wj - 1] = r[hi][-wj] + 1
		if b[h - hi - 1][wj] == '.':
			d[h - hi - 1][wj] = d[-hi][wj] + 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)


(H, W) = map(int, input().split())
S = [[i == '.' for i in input() + '#'] for _ in range(H)] + [[False] * (W + 1)]
map_ = [[0] * W for _ in range(H)]
for i in range(H):
	cnt = 0
	q = []
	for j in range(W + 1):
		if S[i][j] == False and cnt != 0:
			for Q in q:
				map_[Q[0]][Q[1]] = cnt
			cnt = 0
			q = []
		elif S[i][j]:
			cnt += 1
			q.append([i, j])
for j in range(W):
	cnt = 0
	q = []
	for i in range(H + 1):
		if S[i][j] == False and cnt != 0:
			for Q in q:
				map_[Q[0]][Q[1]] += cnt
			cnt = 0
			q = []
		elif S[i][j]:
			cnt += 1
			q.append([i, j])
print(max([max(i) for i in map_]) - 1)


(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
a = [[None] * w for _ in range(h)]
for i in range(h):
	p = 0
	while p < w:
		j = p
		while j < w and s[i][j] == '.':
			j += 1
		for k in range(p, j):
			a[i][k] = j - p
		p = j + 1
r = 0
for j in range(w):
	p = 0
	while p < h:
		i = p
		while i < h and s[i][j] == '.':
			i += 1
		for k in range(p, i):
			r = max(r, a[k][j] + i - p - 1)
		p = i + 1
print(r)


(h, w) = map(int, input().split())
s = [list(input()) for _ in range(h)]
score = [[0] * w for _ in range(h)]
ans = 0
range_w = range(w)
range_h = range(h)
for i in range_h:
	tmp_1 = 0
	tmp_2 = 0
	for j in range_w:
		if s[i][j] == '#':
			tmp_1 = 0
		else:
			tmp_1 += 1
		score[i][j] += tmp_1
		if s[i][-j - 1] == '#':
			tmp_2 = 0
		else:
			tmp_2 += 1
		score[i][-j - 1] += tmp_2
for j in range_w:
	tmp_3 = 0
	tmp_4 = 0
	for i in range_h:
		if s[i][j] == '#':
			tmp_3 = 0
		else:
			tmp_3 += 1
		score[i][j] += tmp_3
		if s[-i - 1][j] == '#':
			tmp_4 = 0
		else:
			tmp_4 += 1
		score[-i - 1][j] += tmp_4 - 3
for i in range(h):
	for j in range(w):
		ans = max(ans, score[i][j])
print(ans)


import numpy as np
(H, W) = map(int, input().split())
maze = [[] for _ in range(H)]
for i in range(H):
	maze[i] = np.array(list(input())) == '.'
maze = np.array(maze)
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)
for i in range(H):
	up[i] = (up[i - 1] + 1) * maze[i]
	down[-(i + 1)] = (down[-i] + 1) * maze[-(i + 1)]
for i in range(W):
	right[:, i] = (right[:, i - 1] + 1) * maze[:, i]
	left[:, -(i + 1)] = (left[:, -i] + 1) * maze[:, -(i + 1)]
print(np.max(up + down + right + left) - 3)


(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
hdp = [[0] * w for _ in range(h)]
wdp = [[0] * w for _ in range(h)]
for i in range(h):
	for j in range(w):
		if s[i][j] == '#':
			continue
		if j > 0 and wdp[i][j - 1] > 0:
			wdp[i][j] = wdp[i][j - 1]
		else:
			for k in range(j, w):
				if s[i][k] == '#':
					break
				wdp[i][j] += 1
		if i > 0 and hdp[i - 1][j] > 0:
			hdp[i][j] = hdp[i - 1][j]
		else:
			for k in range(i, h):
				if s[k][j] == '#':
					break
				hdp[i][j] += 1
ans = 0
for i in range(h):
	for j in range(w):
		ans = max(ans, hdp[i][j] + wdp[i][j] - 1)
print(ans)


import numpy as np
(H, W) = map(int, input().split())
S = []
for h in range(H):
	S.append(list(input()))
G = np.array(S)
G = np.where(G == '.', 1, 0)
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
for w in range(1, W):
	L[:, w] = (L[:, w - 1] + 1) * G[:, w - 1]
for w in range(W - 1, 0, -1):
	R[:, w - 1] = (R[:, w] + 1) * G[:, w]
for h in range(1, H):
	U[h] = (U[h - 1] + 1) * G[h - 1]
for h in range(H - 1, 0, -1):
	D[h - 1] = (D[h] + 1) * G[h]
ans = np.max((L + R + U + D) * G) + 1
print(ans)


(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
sy = [0] * w
ret = 0
for y in range(h):
	seqx = 0
	seqy = 0
	for x in range(w):
		if s[y][x] == '.':
			if sy[x] == 0:
				yy = y
				while yy < h and s[yy][x] != '#':
					yy += 1
				sy[x] = yy - y
			seqx += 1
			seqy = max(seqy, sy[x])
			ret = max(ret, seqx + seqy - 1)
		else:
			seqx = 0
			seqy = 0
			sy[x] = 0
print(ret)


from itertools import product
import numpy as np
(h, w) = list(map(int, input().split()))
notwall = []
for _ in range(h):
	s = input()
	notwall.append([int(c == '.') for c in s])
notwall = np.array(notwall)

def getll():
	ls = np.zeros((h, w + 1), dtype=int)
	for i in range(w):
		ls[:, i + 1] = (ls[:, i] + 1) * notwall[:, i]
	ls = ls[:, 1:]
	return ls

def getlr():
	ls = np.zeros((h, w + 1), dtype=int)
	for i in range(w - 1, -1, -1):
		ls[:, i] = (ls[:, i + 1] + 1) * notwall[:, i]
	ls = ls[:, :-1]
	return ls

def getlu():
	ls = np.zeros((h + 1, w), dtype=int)
	for i in range(h):
		ls[i + 1, :] = (ls[i, :] + 1) * notwall[i, :]
	ls = ls[1:, :]
	return ls

def getld():
	ls = np.zeros((h + 1, w), dtype=int)
	for i in range(h - 1, -1, -1):
		ls[i, :] = (ls[i + 1, :] + 1) * notwall[i, :]
	ls = ls[:-1, :]
	return ls
ll = getll()
lr = getlr()
lu = getlu()
ld = getld()
m = max([0, np.max(ll + lr + lu + ld) - 3])
print(m)


import numpy as np
(H, W) = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])
S = np.where(S == '.', 1, 0)
left = np.zeros((H, W))
right = np.zeros((H, W))
top = np.zeros((H, W))
bottom = np.zeros((H, W))
for i in range(W):
	if i == 0:
		left[:, i] = S[:, i]
		right[:, -i - 1] = S[:, -i - 1]
	else:
		left[:, i] = (left[:, i - 1] + 1) * S[:, i]
		right[:, -i - 1] = (right[:, -i] + 1) * S[:, -i - 1]
for i in range(H):
	if i == 0:
		top[i, :] = S[i, :]
		bottom[-1 - i, :] = S[-i - 1, :]
	else:
		top[i, :] = (top[i - 1, :] + 1) * S[i, :]
		bottom[-1 - i, :] = (bottom[-i, :] + 1) * S[-i - 1, :]
ans = left + top + right + bottom - 3
print(int(ans.max()))


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


import numpy as np
(h, w) = map(int, input().split())
grid = np.array([list(input()) for _ in range(h)], dtype='str')
hgrid = np.zeros((h, w), dtype='int')
for hi in range(h):
	hdot = np.array(grid[hi] == '.', dtype='int')
	hgrid[hi] = hgrid[hi - 1] * hdot + hdot
for hi in range(h - 2, -1, -1):
	hi_1 = np.minimum(hgrid[hi + 1], hgrid[hi] * hgrid[hi + 1])
	hgrid[hi] = np.maximum(hgrid[hi], hi_1)
wgrid = np.zeros((h, w), dtype='int')
for wi in range(w):
	wdot = np.array(grid[:, wi] == '.', dtype='int')
	wgrid[:, wi] = wgrid[:, wi - 1] * wdot + wdot
for wi in range(w - 2, -1, -1):
	wi_1 = np.minimum(wgrid[:, wi + 1], wgrid[:, wi] * wgrid[:, wi + 1])
	wgrid[:, wi] = np.maximum(wgrid[:, wi], wi_1)
print(np.max(wgrid + hgrid) - 1)


import numpy as np
(H, W) = map(int, input().split())
S = np.array([list(input().rstrip('\n')) for _ in range(H)]) == '.'
D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
for i in range(H):
	U[i] = (U[i - 1] + 1) * S[i]
	D[-i - 1] = (D[-i] + 1) * S[-i - 1]
for i in range(W):
	L[:, i] = (L[:, i - 1] + 1) * S[:, i]
	R[:, -i - 1] = (R[:, -i] + 1) * S[:, -i - 1]
print(np.max(U + D + L + R) - 3)


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 = np.array(['#' * (W + 2)] + ['#' + sr() + '#' for _ in range(H)] + ['#' * (W + 2)])
S = np.array([[x == '.' for x in row] for row in S])
S = S.astype(np.int16)
left = S.copy()
right = S.copy()
up = S.copy()
down = S.copy()
for i in range(1, W + 1):
	left[:, i] += left[:, i - 1]
	left[:, i] *= S[:, i]
for i in range(W, 0, -1):
	right[:, i] += right[:, i + 1]
	right[:, i] *= S[:, i]
for i in range(1, H + 1):
	up[i, :] += up[i - 1, :]
	up[i, :] *= S[i, :]
for i in range(H, 0, -1):
	down[i, :] += down[i + 1, :]
	down[i, :] *= S[i, :]
answer = (left + right + up + down - 3).max()
print(answer)


import numpy as np
INT = lambda : int(input())
INTM = lambda : map(int, input().split())
STRM = lambda : map(str, input().split())
STR = lambda : str(input())
LIST = lambda : list(map(int, input().split()))
LISTS = lambda : list(map(str, input().split()))

def do():
	(h, w) = INTM()
	ban = np.zeros((h, w), dtype=np.int16)
	for i in range(h):
		s = STR()
		for i1 in range(len(s)):
			if s[i1] == '.':
				ban[i][i1] = 1
	left = np.zeros((h, w), dtype=np.int16)
	right = np.zeros((h, w), dtype=np.int16)
	up = np.zeros((h, w), dtype=np.int16)
	down = np.zeros((h, w), dtype=np.int16)
	for i in range(w):
		i2 = w - 1 - i
		if i == 0:
			left[:, i] = ban[:, i]
			right[:, i2] = ban[:, i2]
		else:
			left[:, i] = ban[:, i] * (left[:, i - 1] + 1)
			right[:, i2] = ban[:, i2] * (right[:, i2 + 1] + 1)
	for i in range(h):
		i2 = h - 1 - i
		if i == 0:
			up[i, :] = ban[i, :]
			down[i2, :] = ban[i2, :]
		else:
			up[i, :] = ban[i, :] * (up[i - 1, :] + 1)
			down[i2, :] = ban[i2, :] * (down[i2 + 1, :] + 1)
	anslist = down + up + right + left
	ans = 0
	for i in anslist:
		ans = max(ans, max(i))
	print(ans - 3)

def __starting_point():
	do()
__starting_point()


import numpy as np
(H, W) = map(int, input().split())
HL = list(range(H))
WL = list(range(W))
Gd = np.array([list(input()) for _ in HL])
Gd = np.where(Gd == '.', 1, 0)
L = np.zeros((H, W), dtype=np.int64)
R = np.zeros((H, W), dtype=np.int64)
U = np.zeros((H, W), dtype=np.int64)
D = np.zeros((H, W), dtype=np.int64)
for w in WL:
	R[:, w] = (R[:, w - 1] + 1) * Gd[:, w]
	L[:, -w - 1] = (L[:, -w] + 1) * Gd[:, -w - 1]
for h in HL:
	D[h, :] = (D[h - 1, :] + 1) * Gd[h, :]
	U[-h - 1, :] = (U[-h, :] + 1) * Gd[-h - 1, :]
print(np.max(D + U + L + R - 3))


(H, W) = map(int, input().split())
Grid = []
for _ in range(H):
	Grid.append(list(input()))
tmp = 0
ans = 0
up = [[0 for _ in range(W)] for _ in range(H)]
down = [[0 for _ in range(W)] for _ in range(H)]
left = [[0 for _ in range(W)] for _ in range(H)]
right = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
	for j in range(W):
		if Grid[i][j] == '.':
			left[i][j] = left[i][j - 1] + 1
			up[i][j] = up[i - 1][j] + 1
		if Grid[H - i - 1][j] == '.':
			down[H - i - 1][j] = down[-i][j] + 1
		if Grid[i][W - j - 1] == '.':
			right[i][W - j - 1] = right[i][-j] + 1
for i in range(H):
	for j in range(W):
		ans = max(ans, left[i][j] + up[i][j] + down[i][j] + right[i][j] - 3)
print(ans)


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


(h, w) = map(int, input().split())
board = [list(input()) + ['#'] for _ in range(h)]
board.append(['#'] * (w + 1))
hacum = [[0] * (w + 1) for _ in range(h + 1)]
wacum = [[0] * (w + 1) for _ in range(h + 1)]
for i in range(h):
	tmp = 0
	for j in range(w + 1):
		if board[i][j] == '#':
			for k in range(tmp, j):
				wacum[i][k] = j - tmp
			tmp = j + 1
for i in range(w):
	tmp = 0
	for j in range(h + 1):
		if board[j][i] == '#':
			for k in range(tmp, j):
				hacum[k][i] = j - tmp
			tmp = j + 1
ans = 0
for i in range(h):
	for j in range(w):
		ans = max(ans, wacum[i][j] + hacum[i][j] - 1)
print(ans)


import numpy as np
(H, W) = map(int, input().split())
S = np.array([list(input()) 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 i in range(1, H):
	ups[i, :] = (ups[i - 1, :] + 1) * S[i - 1, :]
for i in range(H - 2, -1, -1):
	downs[i, :] = (downs[i + 1, :] + 1) * S[i + 1, :]
for i in range(1, W):
	rights[:, i] = (rights[:, i - 1] + 1) * S[:, i - 1]
for i in range(W - 2, -1, -1):
	lefts[:, i] = (lefts[:, i + 1] + 1) * S[:, i + 1]
ans = ((ups + downs + lefts + rights) * S).max() + 1
print(ans)


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)


import numpy
(H, W) = map(int, input().split())
S = numpy.array([[1 if i == '.' else 0 for i in input().strip()] for _ in range(H)])
S = numpy.array([S, S])
for w in range(1, W):
	S[0, :, w] += S[0, :, w] * S[0, :, w - 1]
for w in range(W - 2, -1, -1):
	S[0, :, w] = (S[0, :, w] != 0) * numpy.maximum(S[0, :, w], S[0, :, w + 1])
for h in range(1, H):
	S[1, h] += S[1, h] * S[1, h - 1]
for h in range(H - 2, -1, -1):
	S[1, h] = (S[1, h] != 0) * numpy.maximum(S[1, h], S[1, h + 1])
S = S[0] + S[1]
print(numpy.max(S) - 1)


import numpy as np
(h, w) = map(int, input().split())
S = np.array([list(input()) for _ in range(h)])
S = np.where(S == '.', 1, 0)
(left, right, up, down) = [np.zeros((h, w)) for _ in range(4)]
for i in range(w):
	left[:, i] = (left[:, i - 1] + 1) * S[:, i]
	right[:, -i - 1] = (right[:, -i] + 1) * S[:, -i - 1]
for i in range(h):
	up[i] = (up[i - 1] + 1) * S[i]
	down[-i - 1] = (down[-i] + 1) * S[-i - 1]
print(int(np.max(left + right + up + down) - 3))


(h, w) = map(int, input().split())
s = [list(input()) for i in range(h)]
L = [[0 for i in range(w)] for i in range(h)]
x = 0
ct = 0
for i in range(h):
	for j in range(w):
		if s[i][j] == '.':
			if ct == 0:
				x = j
			ct += 1
		if ct != 0 and (s[i][j] == '#' or j == w - 1):
			for k in range(ct):
				L[i][x + k] += ct
			ct = 0
for j in range(w):
	for i in range(h):
		if s[i][j] == '.':
			if ct == 0:
				x = i
			ct += 1
		if ct != 0 and (s[i][j] == '#' or i == h - 1):
			for k in range(ct):
				L[x + k][j] += ct
			ct = 0
ans = []
for i in range(len(L)):
	ans.append(max(L[i]))
print(max(ans) - 1)


import sys
input = sys.stdin.readline
(H, W) = map(int, input().split())
S = [[d for d in input()] for i in range(H)]
ans = [[0 for j in range(W)] for i in range(H)]
t = 0
for i in range(H):
	p = 0
	for j in range(W):
		if S[i][j] == '.':
			p += 1
		else:
			p = 0
		ans[i][j] += p
for i in range(H):
	p = 0
	for j in range(W)[::-1]:
		if S[i][j] == '.':
			p += 1
		else:
			p = 0
		ans[i][j] += p
for j in range(W):
	p = 0
	for i in range(H):
		if S[i][j] == '.':
			p += 1
		else:
			p = 0
		ans[i][j] += p
for j in range(W):
	p = 0
	for i in range(H)[::-1]:
		if S[i][j] == '.':
			p += 1
		else:
			p = 0
		ans[i][j] += p
		t = max(t, ans[i][j])
print(t - 3)


def main():
	_max = max
	(h, w) = map(int, input().split())
	s = [input() + '#' for _ in range(h)]
	s.append('#' * (w + 1))
	rt = [[-1] * w for _ in range(h)]
	tstart = [-1] * (w + 1)
	for i in range(h + 1):
		si = s[i]
		ystart = -1
		for j in range(w + 1):
			if si[j] == '#':
				if ystart != -1:
					for k in range(ystart, j):
						rt[i][k] += j - ystart
					ystart = -1
				if tstart[j] != -1:
					for k in range(tstart[j], i):
						rt[k][j] += i - tstart[j]
					tstart[j] = -1
			else:
				if ystart == -1:
					ystart = j
				if tstart[j] == -1:
					tstart[j] = i
	print(_max((_max(l) for l in rt)))
main()


MOD = 10 ** 9 + 7
(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 j > 0:
			if S[i][j - 1] == '.':
				L[i][j] = L[i][j - 1] + 1
			if S[i][w - j] == '.':
				R[i][w - 1 - j] = R[i][w - j] + 1
		if i > 0:
			if S[i - 1][j] == '.':
				U[i][j] = U[i - 1][j] + 1
			if S[h - i][j] == '.':
				D[h - 1 - i][j] = D[h - i][j] + 1
ans = 0
for i in range(h):
	for j in range(w):
		if S[i][j] == '.':
			temp = L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1
			ans = max(ans, temp)
print(ans)


import numpy as np
(h, w) = list(map(int, input().split()))
s = np.empty((h, w), dtype='i8')
for i in range(h):
	s[i] = [i == '.' for i in list(input())]
right = np.copy(s)
left = np.copy(s)
for i in range(1, w):
	right[:, -i - 1] = (right[:, -i] + 1) * s[:, -i - 1]
	left[:, i] = (left[:, i - 1] + 1) * s[:, i]
up = np.copy(s)
down = np.copy(s)
for i in range(1, h):
	up[i] = (up[i - 1] + 1) * s[i]
	down[-i - 1] = (down[-i] + 1) * s[-i - 1]
print(np.max(right + left + up + down) - 3)


import numpy as np
(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
t = np.zeros((h, w), dtype=np.int32)
for i in range(h):
	for j in range(w):
		if s[i][j] == '.':
			t[i][j] = 1
l = np.zeros((h, w), dtype=np.int32)
r = np.zeros((h, w), dtype=np.int32)
u = np.zeros((h, w), dtype=np.int32)
d = np.zeros((h, w), dtype=np.int32)
for i in range(w):
	if i == 0:
		l[:, i] = t[:, i]
	else:
		l[:, i] = (l[:, i - 1] + 1) * t[:, i]
for i in range(w - 1, -1, -1):
	if i == w - 1:
		r[:, i] = t[:, i]
	else:
		r[:, i] = (r[:, i + 1] + 1) * t[:, i]
for i in range(h):
	if i == 0:
		u[i] = t[i]
	else:
		u[i] = (u[i - 1] + 1) * t[i]
for i in range(h - 1, -1, -1):
	if i == h - 1:
		d[i] = t[i]
	else:
		d[i] = (d[i + 1] + 1) * t[i]
lrud = l + r + u + d - 3
print(np.max(lrud))


(w, h) = map(int, input().split())
s = [input() for i in range(w)]
t = [[[], []] for j in range(w)]
for i in range(w):
	k = 0
	for j in range(h):
		if s[i][j] == '.':
			k += 1
		else:
			t[i][0] += [k for _ in range(k)] + [0]
			k = 0
	t[i][0] += [k for _ in range(k)]
for i in range(h):
	k = 0
	for j in range(w):
		if s[j][i] == '.':
			k += 1
		else:
			for l in range(1, k + 1):
				t[j - l][1] += [k]
			t[j][1] += [0]
			k = 0
	for l in range(1, k + 1):
		t[w - l][1] += [k]
answer = 0
for i in range(w):
	for j in range(h):
		answer = max(t[i][0][j] + t[i][1][j], answer)
print(answer - 1)


(H, W) = map(int, input().split())
S = [list(input()) for _ in range(H)]
X = [[-10 ** 2 for __ in range(W)] for _ in range(H)]
Y = [[-10 ** 2 for __ in range(W)] for _ in range(H)]
for y in range(H):
	last_x = -1
	for x in range(W):
		if S[y][x] == '#':
			for t in range(last_x + 1, x):
				X[y][t] = x - 1 - last_x
			last_x = x
	for t in range(last_x + 1, W):
		X[y][t] = W - 1 - last_x
for x in range(W):
	last_y = -1
	for y in range(H):
		if S[y][x] == '#':
			for t in range(last_y + 1, y):
				Y[t][x] = y - 1 - last_y
			last_y = y
	for t in range(last_y + 1, H):
		Y[t][x] = H - 1 - last_y
ans = 0
for y in range(H):
	for x in range(W):
		ans = max(ans, Y[y][x] + X[y][x])
print(ans - 1)


import sys
(H, W) = map(int, input().split())
G = [sys.stdin.readline() for _ in range(H)]
counts = [[[-1] * 4 for _ in range(W + 1)] for _ in range(H + 1)]
for h in range(H):
	for w in range(W):
		if G[h][w] == '.':
			counts[h][w][0] = counts[h][w - 1][0] + 1
			counts[h][w][1] = counts[h - 1][w][1] + 1
		dih = H - h - 1
		diw = W - w - 1
		if G[dih][diw] == '.':
			counts[dih][diw][2] = counts[dih][diw + 1][2] + 1
			counts[dih][diw][3] = counts[dih + 1][diw][3] + 1
ans = 0
for h in range(H):
	for w in range(W):
		if G[h][w] == '.':
			ans = max(ans, sum(counts[h][w]) + 1)
print(ans)


import numpy as np
from copy import deepcopy

def main():
	(height, width) = list(map(int, input().split()))
	grid = [list(input()) for _ in range(height)]
	grid = (np.array(grid) == '.') * 1
	left = np.zeros((height, width), dtype=int)
	right = deepcopy(left)
	upper = deepcopy(left)
	down = deepcopy(left)
	for i in range(height):
		if i == 0:
			upper[i] = grid[i]
		else:
			upper[i] = (upper[i - 1] + 1) * grid[i]
	for i in range(width):
		if i == 0:
			left[:, i] = grid[:, i]
		else:
			left[:, i] = (left[:, i - 1] + 1) * grid[:, i]
	for i in range(width - 1, -1, -1):
		if i == width - 1:
			right[:, i] = grid[:, i]
		else:
			right[:, i] = (right[:, i + 1] + 1) * grid[:, i]
	for i in range(height - 1, -1, -1):
		if i == height - 1:
			down[i] = grid[i]
		else:
			down[i] = (down[i + 1] + 1) * grid[i]
	print(np.max(left + right + upper + down - 3))

def __starting_point():
	main()
__starting_point()


(H, W) = map(int, input().split())
S = []
for i in range(H):
	S.append(list(input()))
U = [[0] * (W + 1) for h in range(H + 1)]
L = [[0] * (W + 1) for h in range(H + 1)]
for h in range(H):
	for w in range(W):
		if S[h][w] == '#':
			continue
		U[h + 1][w + 1] = U[h][w + 1] + 1
		L[h + 1][w + 1] = L[h + 1][w] + 1
ans = 0
D = [[0] * (W + 1) for h in range(H + 1)]
R = [[0] * (W + 1) for h in range(H + 1)]
for h in range(H - 1, -1, -1):
	for w in range(W - 1, -1, -1):
		if S[h][w] == '#':
			continue
		D[h][w] = D[h + 1][w] + 1
		R[h][w] = R[h][w + 1] + 1
		ans = max(ans, D[h][w] + R[h][w] + U[h + 1][w + 1] + L[h + 1][w + 1] - 3)
print(ans)


(H, W) = map(int, input().split())
S = [input() for _ in range(H)]
l = [[0] * (W + 2) for _ in range(H + 2)]
u = [[0] * (W + 2) for _ in range(H + 2)]
r = [[0] * (W + 2) for _ in range(H + 2)]
d = [[0] * (W + 2) for _ 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
			u[i][j] += u[i - 1][j] + 1
		if S[-i][-j] != '#':
			r[-i - 1][-j - 1] += r[-i - 1][-j] + 1
			d[-i - 1][-j - 1] += d[-i][-j - 1] + 1
ans = 0
for i in range(1, H + 1):
	for j in range(1, W + 1):
		ans = max(ans, l[i][j] + u[i][j] + r[i][j] + d[i][j] - 3)
print(ans)


(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)
maxi = 0
for x in range(h):
	for y in range(w):
		maxi = max(maxi, xx[x][y] + yy[y][x] - 1)
print(maxi)


from itertools import chain
(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
a = [[-1] * w for _ in range(h)]
for i in range(h):
	p = 0
	while p < w:
		j = p
		while j < w and s[i][j] == '.':
			j += 1
		for k in range(p, j):
			a[i][k] += j - p
		p = j + 1
for j in range(w):
	p = 0
	while p < h:
		i = p
		while i < h and s[i][j] == '.':
			i += 1
		for k in range(p, i):
			a[k][j] += i - p
		p = i + 1
print(max(chain.from_iterable(a)))


(h, w) = map(int, input().split())
ans = [[0] * w for _ in range(h)]
S = [['#'] * h for _ in range(w)]
for i in range(h):
	s = input().split('#')
	j = 0
	for c in s:
		for d in list(c):
			S[j][i] = d
			ans[i][j] += len(c)
			j += 1
		j += 1
for i in range(w):
	s = ''.join(S[i]).split('#')
	j = 0
	for c in s:
		for d in list(c):
			ans[j][i] += len(c)
			j += 1
		j += 1
m = 0
for a in ans:
	if m < max(a):
		m = max(a)
print(m - 1)


(h, w) = map(int, input().split())
s = [input() + '#' for _ in range(h)]
s.append('#' * (w + 1))
t = [[-1] * w for _ in range(h + 1)]
tstart = [-1] * (w + 1)
for i in range(h + 1):
	ystart = -1
	for j in range(w + 1):
		if s[i][j] == '#':
			if ystart != -1:
				for k in range(ystart, j):
					t[i][k] += j - ystart
				ystart = -1
			if tstart[j] != -1:
				for k in range(tstart[j], i):
					t[k][j] += i - tstart[j]
				tstart[j] = -1
		else:
			if ystart == -1:
				ystart = j
			if tstart[j] == -1:
				tstart[j] = i
print(max(map(max, t)))


import sys
import numpy as np
input = sys.stdin.readline
(h, w) = map(int, input().split())
s = (np.array([list(input().strip()) for _ in range(h)]) == '.').astype(np.int)
(l, r, u, d) = (s.copy(), s.copy(), s.copy(), s.copy())
for i in range(1, w):
	l[:, i] *= l[:, i - 1] + 1
	r[:, w - i - 1] *= r[:, w - i] + 1
for i in range(1, h):
	u[i] *= u[i - 1] + 1
	d[h - i - 1] *= d[h - i] + 1
print(max([max(i) for i in l + r + u + d - 3]))


import numpy as np
(h, w) = list(map(int, input().split()))
s = []
for _ in range(h):
	si = input()
	si = si.replace('.', '1')
	si = si.replace('#', '0')
	s.append(list(map(int, si)))
s = np.array(s)
left = np.zeros((h, w))
right = np.zeros((h, w))
up = np.zeros((h, w))
down = np.zeros((h, w))
for i in range(w):
	if i == 0:
		left[:, i] = s[:, i]
		right[:, w - i - 1] = s[:, w - i - 1]
	else:
		left[:, i] = (left[:, i - 1] + 1) * s[:, i]
		right[:, w - i - 1] = (right[:, w - i] + 1) * s[:, w - i - 1]
for i in range(h):
	if i == 0:
		down[i, :] = s[i, :]
		up[h - i - 1, :] = s[h - i - 1, :]
	else:
		down[i, :] = (down[i - 1, :] + 1) * s[i, :]
		up[h - i - 1, :] = (up[h - i, :] + 1) * s[h - i - 1, :]
ans = left + right + up + down - 3
print(int(np.max(ans)))


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


from sys import stdin
import numpy as np

def main():
	readline = stdin.readline
	(h, w) = map(int, readline().split())
	grid = [readline().strip() for _ in range(h)]
	grid2 = np.zeros((h, w), dtype='int64')
	for i in range(h):
		for j in range(w):
			if grid[i][j] == '.':
				grid2[i][j] = 1
			else:
				grid2[i][j] = 0
	up = np.zeros((h, w), dtype='int64')
	up[0] = grid2[0]
	for i in range(1, h):
		up[i] = (up[i - 1] + 1) * grid2[i]
	down = np.zeros((h, w), dtype='int64')
	down[-1] = grid2[-1]
	for i in range(h - 2, -1, -1):
		down[i] = (down[i + 1] + 1) * grid2[i]
	left = np.zeros((h, w), dtype='int64')
	left[:, 0] = grid2[:, 0]
	for i in range(1, w):
		left[:, i] = (left[:, i - 1] + 1) * grid2[:, i]
	right = np.zeros((h, w), dtype='int64')
	right[:, -1] = grid2[:, -1]
	for i in range(w - 2, -1, -1):
		right[:, i] = (right[:, i + 1] + 1) * grid2[:, i]
	ans = (up + down + left + right - 3).max()
	print(ans)

def __starting_point():
	main()
__starting_point()


import re
(h, w) = map(int, input().split())
m = []
d = [[0] * w for _ in range(h)]
u = [[0] * w for _ in range(h)]
for _ in range(h):
	t = []
	for i in re.split('(#)', input()):
		if not i == '#':
			t.extend([len(i)] * len(i))
		else:
			t.append(0)
	m.append(t)
for i in range(w):
	for j in range(h):
		if m[j][i] == 0:
			d[j][i] = 0
		elif j != 0:
			d[j][i] = d[j - 1][i] + 1
		else:
			d[j][i] = 1
		if m[h - 1 - j][i] == 0:
			u[h - 1 - j][i] = 0
		elif h - 1 - j == h - 1:
			u[h - 1 - j][i] = 1
		else:
			u[h - 1 - j][i] = u[h - j][i] + 1
ans = 0
for i in range(w):
	for j in range(h):
		ans = max(ans, u[j][i] + d[j][i] + m[j][i])
print(ans - 2)


from itertools import takewhile
(H, W) = map(int, input().split())
S = [input() for _ in range(H)]
x = [[0 for _ in range(W)] for _ in range(H)]
y = [[0 for _ in range(W)] for _ in range(H)]
for (i, j) in ((i, j) for i in range(H) for j in range(W) if S[i][j] == '.'):
	if x[i][j] == 0:
		w = len(list(takewhile(lambda k: S[i][k] == '.', range(j, W))))
		for k in range(j, j + w):
			x[i][k] = w
	if y[i][j] == 0:
		h = len(list(takewhile(lambda k: S[k][j] == '.', range(i, H))))
		for l in range(i, i + h):
			y[l][j] = h
ans = max((x[i][j] + y[i][j] - 1 for i in range(H) for j in range(W)))
print(ans)


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


import numpy as np

def main():
	printl = lambda l: [print(x) for x in l]
	(H, W) = list(map(int, input().split()))
	A = np.array([[1 if i == '.' else 0 for i in input()] for _ in range(H)])
	L = np.zeros((H, W), dtype=np.int)
	R = np.zeros((H, W), dtype=np.int)
	U = np.zeros((H, W), dtype=np.int)
	D = np.zeros((H, W), dtype=np.int)
	L[:, 0] = A[:, 0]
	for w in range(1, W):
		L[:, w] = (L[:, w - 1] + 1) * A[:, w]
	R[:, W - 1] = A[:, W - 1]
	for w in range(W - 2, -1, -1):
		R[:, w] = (R[:, w + 1] + 1) * A[:, w]
	U[0, :] = A[0, :]
	for h in range(1, H):
		U[h, :] = (U[h - 1, :] + 1) * A[h, :]
	D[H - 1, :] = A[H - 1, :]
	for h in range(H - 2, -1, -1):
		D[h, :] = (D[h + 1, :] + 1) * A[h, :]
	print(np.max(L + R + U + D - 3))

def __starting_point():
	main()
__starting_point()


(h, w) = map(int, input().split())
raw = []
for _ in range(h):
	raw.append(input())
ans = [[0 for _ in range(w)] for _ in range(h)]
for x in range(h):
	tmp = 0
	for y in range(w):
		if raw[x][y] == '.':
			tmp += 1
		else:
			for j in range(tmp):
				ans[x][y - j - 1] += tmp
			tmp = 0
	for j in range(tmp):
		ans[x][y - j] += tmp
for y in range(w):
	tmp = 0
	for x in range(h):
		if raw[x][y] == '.':
			tmp += 1
		else:
			for i in range(tmp):
				ans[x - i - 1][y] += tmp
			tmp = 0
	for i in range(tmp):
		ans[x - i - 1][y] += tmp
can = []
for x in range(h):
	can.append(max(ans[x]))
print(max(can) - 1)


import numpy as np
(h, w) = list(map(int, input().split()))
s = np.array([list(input()) 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 i in range(1, h):
	ups[i, :] = (ups[i - 1] + 1) * s[i - 1]
for i in reversed(list(range(h - 1))):
	downs[i, :] = (downs[i + 1] + 1) * s[i + 1]
for i in range(1, w):
	rights[:, i] = (rights[:, i - 1] + 1) * s[:, i - 1]
for i in reversed(list(range(w - 1))):
	lefts[:, i] = (lefts[:, i + 1] + 1) * s[:, i + 1]
ans = ((ups + downs + lefts + rights) * s).max() + 1
print(ans)


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

def __starting_point():
	main()
__starting_point()


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

def sc(s):
	b = None
	nc = 0
	kk = [0] * len(s)
	for (i, c) in enumerate(s):
		if c == '.':
			if c == b:
				nc += 1
			else:
				si = i
		else:
			if b == '.':
				for j in range(si, i):
					kk[j] = i - si
			nc = 0
		b = c
	return kk
d = []
d2 = []
d3 = []
for h in range(H):
	s = input().strip()
	d.append(s)
	d2.append(sc(s + '#'))
d = list(zip(*d))
for s in d:
	d3.append(sc(''.join(s) + '#'))
r = 0
for i in range(H):
	for j in range(W):
		r = max(r, d2[i][j] + d3[j][i] - 1)
print(r)


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 == '#' else 1 for c in input().strip()]
		A.append(S)
	A = np.array(A)
	top = np.zeros((H + 1, W), dtype=np.int)
	bottom = 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):
		top[i] = (top[i - 1] + 1) * A[i - 1]
	for i in range(H - 1, -1, -1):
		bottom[i] = (bottom[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 = (top[1:] + bottom[:H] - 1) * A
	C = (right[:, 1:] + left[:, :W] - 1) * A
	RC = (R + C - 1) * A
	return RC.max()

def __starting_point():
	print(main())
__starting_point()


import numpy as np
(h, w) = map(int, input().split())
g = np.zeros((h + 2, w + 2), dtype=np.int64)
for i in range(h):
	grid = np.array(list(input()))
	g[i + 1, 1:w + 1] = grid == '.'
gW = np.copy(g)
gW = np.ravel(gW)
tWLeft = np.arange((w + 2) * (h + 2))
tWRight = np.copy(tWLeft)
tWLeft[gW == 1] = 0
tWRight[gW[::-1] == 1] = 0
np.maximum.accumulate(tWLeft, out=tWLeft)
np.maximum.accumulate(tWRight, out=tWRight)
tWRight = len(tWRight) - 1 - tWRight[::-1]
tW = tWRight - tWLeft - 1
tW[gW == 0] = 0
tW = tW.reshape(h + 2, w + 2)
gH = np.copy(g.T)
gH = np.ravel(gH)
tHLeft = np.arange((w + 2) * (h + 2))
tHRight = np.copy(tHLeft)
tHLeft[gH == 1] = 0
tHRight[gH[::-1] == 1] = 0
np.maximum.accumulate(tHLeft, out=tHLeft)
np.maximum.accumulate(tHRight, out=tHRight)
tHRight = len(tHRight) - 1 - tHRight[::-1]
tH = tHRight - tHLeft - 1
tH[gH == 0] = 0
tH = tH.reshape(w + 2, h + 2).T
print(np.max(tW + tH - 1))


import numpy as np

def lamp(s):
	h = len(s)
	w = s.size // h
	A = np.zeros((h, w), np.int64)
	for i in range(1, w):
		A[:, i] = np.where(s[:, i - 1] == '.', A[:, i - 1] + 1, 0)
	return A
(H, W) = map(int, input().split())
S = np.array([[*input()] for _ in range(H)])
L = lamp(S)
R = lamp(S[:, ::-1])[:, ::-1]
U = lamp(S.T).T
D = lamp(S.T[:, ::-1])[:, ::-1].T
LRUD = L + R + U + D
print(LRUD[S == '.'].max().max() + 1)


import sys
input = sys.stdin.readline
(h, w) = map(int, input().split())
s = []
for i in range(h):
	s.append(input().rstrip())
num = [[0] * w for _ in range(h)]
for i in range(h):
	p = 0
	for j in range(w):
		if s[i][j] == '.':
			p += 1
			num[i][j] += p
		else:
			p = 0
for i in range(h):
	p = 0
	for j in range(w - 1, -1, -1):
		if s[i][j] == '.':
			p += 1
			num[i][j] += p
		else:
			p = 0
for i in range(w):
	p = 0
	for j in range(h):
		if s[j][i] == '.':
			p += 1
			num[j][i] += p
		else:
			p = 0
for i in range(w):
	p = 0
	for j in range(h - 1, -1, -1):
		if s[j][i] == '.':
			p += 1
			num[j][i] += p
		else:
			p = 0
ans = 0
for i in range(h):
	ans = max(ans, max(num[i]) - 3)
print(ans)


import numpy as np

def main():
	(H, W) = list(map(int, input().split()))
	S = np.array([list(input()) for _ 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(H - 1):
		up[i + 1, :] = (up[i, :] + 1) * S[i, :]
	for i in range(H - 1):
		down[H - 2 - i, :] = (down[H - 1 - i, :] + 1) * S[H - 1 - i, :]
	for i in range(W - 1):
		left[:, i + 1] = (left[:, i] + 1) * S[:, i]
	for i in range(W - 1):
		right[:, W - 2 - i] = (right[:, W - 1 - i] + 1) * S[:, W - 1 - i]
	print(((up + down + left + right) * S).max() + 1)

def __starting_point():
	main()
__starting_point()


(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
yoko = [[0] * w for _ in range(h)]
tate = [[0] * w for _ in range(h)]
count = 0
for i in range(h):
	a = [0]
	for j in range(w):
		if s[i][j] == '#':
			a.append(j + 1)
	a.append(w + 1)
	for j in range(1, len(a)):
		for k in range(a[j - 1], a[j] - 1):
			yoko[i][k] = a[j] - a[j - 1] - 1
for i in range(w):
	a = [0]
	for j in range(h):
		if s[j][i] == '#':
			a.append(j + 1)
	a.append(h + 1)
	for j in range(1, len(a)):
		for k in range(a[j - 1], a[j] - 1):
			tate[k][i] = a[j] - a[j - 1] - 1
ans = 1
for i in range(h):
	for j in range(w):
		ans = max(ans, yoko[i][j] + tate[i][j] - 1)
print(ans)


(H, W) = list(map(int, input().split()))
S = [input() for y in range(H)]
c = [[0 for x in range(W)] for y in range(H)]
for y in range(H):
	s = 0
	for x in range(W):
		if S[y][x] == '#':
			s = 0
		else:
			c[y][x] = 1
			c[y][x] += s
			s += 1
	s = 0
	for x in range(W - 1, -1, -1):
		if S[y][x] == '#':
			s = 0
		else:
			c[y][x] += s
			s += 1
for x in range(W):
	s = 0
	for y in range(H):
		if S[y][x] == '#':
			s = 0
		else:
			c[y][x] += s
			s += 1
	s = 0
	for y in range(H - 1, -1, -1):
		if S[y][x] == '#':
			s = 0
		else:
			c[y][x] += s
			s += 1
print(max(map(max, c)))


import numpy as np
(h, w) = list(map(int, input().split()))
s = np.array([list(input()) for i in range(h)]) == '.'
u = np.zeros((h, w), dtype=int)
d = np.zeros((h, w), dtype=int)
l = np.zeros((h, w), dtype=int)
r = np.zeros((h, w), dtype=int)
for i in range(h):
	u[i] = (u[i - 1] + 1) * s[i]
	d[-i - 1] = (d[-i] + 1) * s[-i - 1]
for i in range(w):
	l[:, i] = (l[:, i - 1] + 1) * s[:, i]
	r[:, -i - 1] = (r[:, -i] + 1) * s[:, -i - 1]
print(np.max(u + d + l + r - 3))


import sys
import numpy as np

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

def main():
	(h, w) = list(map(int, read().split()))
	s = np.array([[i == '.' for i in read()] for _ in range(h)], dtype=int)
	left = s.copy()
	right = s.copy()
	up = s.copy()
	down = s.copy()
	for i in range(w - 1):
		left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
		right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
	for i in range(h - 1):
		up[i + 1] = (up[i] + 1) * s[i + 1]
		down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
	print((left + right + up + down).max() - 3)

def __starting_point():
	main()
__starting_point()


import numpy as np
(H, W) = map(int, input().split())
S = np.zeros((H, W))
for i in range(H):
	Si = np.array([int(s == '.') for s in input()])
	S[i] = Si
top = S.copy()
bottom = S.copy()
left = S.copy()
right = S.copy()
for i in range(1, H):
	top[i] = (top[i - 1] + 1) * S[i]
	bottom[-i - 1] = (bottom[-i] + 1) * S[-i - 1]
for j in range(1, W):
	left[:, j] = (left[:, j - 1] + 1) * S[:, j]
	right[:, -j - 1] = (right[:, -j] + 1) * S[:, -j - 1]
print(np.max((top + bottom + left + right - 3).astype(np.int)))


import numpy as np
(h, w) = map(int, input().split())
s = [list(input()) for i in range(h)]
li = [[0 if s[i][j] == '#' else 1 for j in range(w)] for i in range(h)]
(l, r, u, d) = (np.array(li), np.array(li), np.array(li), np.array(li))
for i in range(1, h):
	u[i] *= u[i - 1] + 1
	d[-i - 1] *= d[-i] + 1
for i in range(1, w):
	l[:, i] *= l[:, i - 1] + 1
	r[:, -i - 1] *= r[:, -i] + 1
print((l + r + u + d - 3).max())


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(list(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(list(range(W - 1))):
	rights[:, w] = (rights[:, w + 1] + 1) * S[:, w + 1]
print(((ups + downs + lefts + rights) * S).max() + 1)


(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
a = [[0] * w for _ in range(h)]
for i in range(h):
	cnt = 0
	for j in range(w):
		if s[i][j] == '.':
			cnt += 1
		else:
			for k in range(cnt):
				a[i][j - k - 1] = cnt
			cnt = 0
	for k in range(cnt):
		a[i][j - k] = cnt
for i in range(w):
	cnt = 0
	for j in range(h):
		if s[j][i] == '.':
			cnt += 1
		else:
			for k in range(cnt):
				a[j - k - 1][i] += cnt
			cnt = 0
	for k in range(cnt):
		a[j - k][i] += cnt
ans = 0
for i in range(h):
	for j in range(w):
		ans = max(ans, a[i][j])
print(ans - 1)


(H, W) = (int(x) for x in input().split())
S = [list(input()) for i in range(H)]
import numpy as np
S_np = (np.array(S) == '.') * 1
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
for i in range(W):
	if i == 0:
		L[:, i] = S_np[:, i]
		R[:, W - i - 1] = S_np[:, W - i - 1]
	else:
		L[:, i] = (L[:, i - 1] + 1) * S_np[:, i]
		R[:, W - i - 1] = (R[:, W - i] + 1) * S_np[:, W - i - 1]
for i in range(H):
	if i == 0:
		D[i, :] = S_np[i, :]
		U[H - i - 1, :] = S_np[H - i - 1, :]
	else:
		D[i, :] = (D[i - 1, :] + 1) * S_np[i, :]
		U[H - i - 1, :] = (U[H - i, :] + 1) * S_np[H - i - 1, :]
light = L + R + D + U - 3
light_max = np.max(light)
print(light_max)


from itertools import product
(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, j) in product(range(h), range(w)):
	l = S[i][j]
	r = S[i][w - 1 - j]
	u = S[i][j]
	d = S[h - 1 - i][j]
	if l == '.':
		L[i][j] = L[i][max(0, j - 1)] + 1
	if r == '.':
		R[i][w - 1 - j] = R[i][min(w - 1, w - j)] + 1
	if u == '.':
		U[i][j] = U[max(0, i - 1)][j] + 1
	if d == '.':
		D[h - 1 - i][j] = D[min(h - 1, h - i)][j] + 1
A = [L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for (i, j) in product(range(h), range(w))]
print(max(A))


(H, W) = map(int, input().split())
S = ['#' * (W + 2)] + ['#' + input() + '#' for _ in range(H)] + ['#' * (W + 2)]
ST = list(map(''.join, zip(*S)))
ansX = [[None] * (W + 2) for _ in range(H + 2)]
ansY = [[None] * (H + 2) for _ in range(W + 2)]
final = 0
for y in range(1, H + 1):
	Sy = S[y]
	ansXy = ansX[y]
	for x in range(1, W + 1):
		if Sy[x] == '#':
			continue
		if ansX[y][x] is None:
			t = Sy.find('#', x)
			ansXy[x:t] = [t - x] * (t - x)
		if ansY[x][y] is None:
			t = ST[x].find('#', y)
			ansY[x][y:t] = [t - y] * (t - y)
		a = ansXy[x] + ansY[x][y] - 1
		final = a if a > final else final
print(final)


(h, w) = map(int, input().split())
s = [list('#' * (w + 2))]
for _ in range(h):
	s += [list('#' + input() + '#')]
s += [list('#' * (w + 2))]
L = [[0] * (w + 2) for _ in range(h + 2)]
U = [[0] * (w + 2) for _ in range(h + 2)]
R = [[0] * (w + 2) for _ in range(h + 2)]
D = [[0] * (w + 2) for _ in range(h + 2)]
for i in range(1, h + 1):
	for j in range(1, w + 1):
		if s[i][j] == '#':
			continue
		L[i][j] = L[i][j - 1] + 1
		U[i][j] = U[i - 1][j] + 1
ans = 0
for i in range(h, 0, -1):
	for j in range(w, 0, -1):
		if s[i][j] == '#':
			continue
		R[i][j] = R[i][j + 1] + 1
		D[i][j] = D[i + 1][j] + 1
		lit = L[i][j] + U[i][j] + R[i][j] + D[i][j] - 3
		ans = max(ans, lit)
print(ans)


import numpy as np
(h, w) = map(int, input().split())
sn = [[0] * w for i in range(h)]
for i in range(h):
	s = input()
	for j in range(w):
		if s[j] == '.':
			sn[i][j] = 1
sn = np.array(sn)
score = np.zeros_like(sn)
total = np.zeros_like(sn)
score[0] += sn[0]
for i in range(1, h):
	score[i] = (score[i - 1] + sn[i]) * sn[i]
total += score
score[h - 1] = sn[h - 1]
for i in range(h - 2, -1, -1):
	score[i] = (score[i + 1] + sn[i]) * sn[i]
total += score
score[:, 0] = sn[:, 0]
for i in range(1, w):
	score[:, i] = (score[:, i - 1] + sn[:, i]) * sn[:, i]
total += score
score[:, w - 1] = sn[:, w - 1]
for i in range(w - 2, -1, -1):
	score[:, i] = (score[:, i + 1] + sn[:, i]) * sn[:, i]
total += score
print(total.max() - 3)


import numpy as np
(h, w) = map(int, input().split())
S = list((list(input()) for _ in range(h)))
S = np.array(S)
S_int = np.zeros_like(S, dtype=int)
S_int[S == '.'] = 1

def getLR(d, width, height):
	L = np.zeros_like(d)
	R = L.copy()
	L[:][0] = 0
	R[:][-1] = 0
	for i in range(1, width):
		ridx = width - 1 - i
		L[:, i] = d[:, i] * (L[:, i - 1] + d[:, i - 1])
		R[:, ridx] = d[:, ridx] * (R[:, ridx + 1] + d[:, ridx + 1])
	return (L, R)
(L, R) = getLR(S_int, w, h)
(U, D) = getLR(S_int.T, h, w)
print((L + R + U.T + D.T).max() + 1)


(h, w) = map(int, input().split())
ans = [[0] * (w + 2) for _ in range(h + 2)]
grid = []
grid.append(['#'] * (w + 2))
for _ in range(h):
	s = list(input())
	grid.append(['#'] + s + ['#'])
grid.append(['#'] * (w + 2))
for i in range(1, h + 1):
	for j in range(0, w + 2):
		if grid[i][j] == '#':
			if j >= 1:
				for k in range(j - start):
					ans[i][start + k] += j - start
			start = j + 1
for j in range(1, w + 1):
	for i in range(0, h + 2):
		if grid[i][j] == '#':
			if i >= 1:
				for k in range(i - start):
					ans[start + k][j] += i - start
			start = i + 1
print(max(list(map(lambda x: max(x), ans))) - 1)


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)


(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 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 - w - 1] == '.':
			R[h][-w - 1] = R[h][-w] + 1
		if S[H - h - 1][w] == '.':
			D[-h - 1][w] = D[-h][w] + 1
ans = 0
for h in range(H):
	for w in range(W):
		ans = max(ans, R[h][w] + L[h][w] + U[h][w] + D[h][w] - 3)
print(ans)


import numpy as np
(h, w) = list(map(int, input().split()))
s = np.array([list(input()) for _ in range(h)]) == '.'
L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)
for i in range(h):
	D[i] = (D[i - 1] + 1) * s[i]
	U[-i - 1] = (U[-i] + 1) * s[-i - 1]
for i in range(w):
	R[:, i] = (R[:, i - 1] + 1) * s[:, i]
	L[:, -i - 1] = (L[:, -i] + 1) * s[:, -i - 1]
print(np.max(D + U + R + L) - 3)


(h, w) = map(int, input().split())
area = [[0] * w for _ in range(h)]
s = [input() for _ in range(h)]
for (i, row) in enumerate(s):
	cnt = 0
	for (j, x) in enumerate(row):
		if x == '#':
			for k in range(j - cnt, j):
				area[i][k] = cnt
			cnt = 0
		else:
			cnt += 1
	for k in range(w - cnt, w):
		area[i][k] = cnt
for i in range(w):
	cnt = 0
	for j in range(h):
		x = s[j][i]
		if x == '#':
			for k in range(j - cnt, j):
				area[k][i] += cnt - 1
			cnt = 0
		else:
			cnt += 1
	for k in range(h - cnt, h):
		area[k][i] += cnt - 1
ans = 0
for i in range(h):
	for j in range(w):
		ans = max(ans, area[i][j])
print(ans)


(t, *grid) = open(0)
(h, w) = map(int, t.split())
(L, R, U, D) = eval('[[0]*(w+2) for _ in range(h+2)],' * 4)
for y in range(h):
	for x in range(w):
		if grid[y][x] == '.':
			L[y + 1][x + 1] = L[y + 1][x] + 1
		if grid[y][w - x - 1] == '.':
			R[y + 1][w - x] = R[y + 1][w - x + 1] + 1
for x in range(w):
	for y in range(h):
		if grid[y][x] == '.':
			U[y + 1][x + 1] = U[y][x + 1] + 1
		if grid[h - y - 1][x] == '.':
			D[h - y][x + 1] = D[h - y + 1][x + 1] + 1
print(max((L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3 for y in range(1, h + 1) for x in range(1, w + 1))))


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


import numpy as np
(H, W) = list(map(int, input().split()))
G = []
for _ in range(H):
	G.append([1 if x == '.' else 0 for x in input()])
G = np.array(G)
North = np.cumsum(np.ones_like(G), axis=0)
North *= 1 - G
North = np.maximum.accumulate(North, axis=0) * G
South = np.cumsum(np.ones_like(G), axis=0)
South *= np.flipud(1 - G)
South = np.maximum.accumulate(South, axis=0)
South = (H - np.flipud(South)) * G
West = np.cumsum(np.ones_like(G), axis=1)
West *= 1 - G
West = np.maximum.accumulate(West, axis=1) * G
East = np.cumsum(np.ones_like(G), axis=1)
East *= np.fliplr(1 - G)
East = np.maximum.accumulate(East, axis=1)
East = (W - np.fliplr(East)) * G
print(np.amax(South - North + East - West) - 1)


from bisect import bisect
(H, W) = map(int, input().split())
S = [input() for i in range(H)]
sec_x = [[-1] for i in range(H)]
sec_y = [[-1] for i in range(W)]
for y in range(H):
	for x in range(W):
		if S[y][x] == '#':
			sec_x[y].append(x)
	sec_x[y].append(W)
for x in range(W):
	for y in range(H):
		if S[y][x] == '#':
			sec_y[x].append(y)
	sec_y[x].append(H)
ans = 0
for y in range(H):
	l = 1
	for x in range(W):
		if S[y][x] == '#':
			l += 1
		else:
			b = bisect(sec_y[x], y)
			ans = max(ans, sec_x[y][l] - sec_x[y][l - 1] + sec_y[x][b] - sec_y[x][b - 1] - 3)
print(ans)


from itertools import groupby
[H, W] = map(int, input().split())
Ss = [list(map(lambda x: int(x == '.'), list(input()))) for _ in range(H)]
res = 0
count = [[-Ss[i][j] for j in range(W)] for i in range(H)]
for i in range(H):
	j = 0
	for x in groupby(Ss[i]):
		k = len(list(x[1]))
		for _ in range(k):
			count[i][j] += k * x[0]
			j += 1
for j in range(W):
	i = 0
	for x in groupby([Ss[i][j] for i in range(H)]):
		k = len(list(x[1]))
		for _ in range(k):
			new_res = count[i][j] + k * x[0]
			if res < new_res:
				res = new_res
			i += 1
print(res)


(H, W) = list(map(int, input().split()))
import numpy as np
m = np.array([[0 if i == '#' else 1 for i in input()] for i in range(H)])
(l, r, u, d) = np.zeros((4, H, W))
for i in range(H):
	u[i] = (u[i - 1] + 1) * m[i]
	d[-i - 1] = (d[-i] + 1) * m[-i - 1]
for i in range(W):
	r[:, i] = (r[:, i - 1] + 1) * m[:, i]
	l[:, -i - 1] = (l[:, -i] + 1) * m[:, -i - 1]
print(int(np.max(u + r + l + d)) - 3)


def main():
	NEG = -10 ** 6
	(H, W) = list(map(int, input().split()))
	S = [input() for _ in range(H)]
	T = [[NEG] * W for _ in range(H)]
	for w in range(W):
		b = NEG
		for h in range(H):
			if S[h][w] == '.':
				if b == NEG:
					b = h
			elif b != NEG:
				for j in range(b, h):
					T[j][w] = h - b
				b = NEG
		if b != NEG:
			for j in range(b, h + 1):
				T[j][w] = h + 1 - b
	m = 0
	for (s, t) in zip(S, T):
		b = NEG
		for i in range(len(s)):
			if s[i] == '#':
				if b != NEG:
					m = max(m, i - b - 1 + max(t[b:i]))
					b = NEG
			elif b == NEG:
				b = i
		if b != NEG:
			m = max(m, i - b + max(t[b:i + 1]))
	print(m)
main()


import numpy as np
(H, W) = list(map(int, input().split(' ')))
S = np.array([[int(c == '.') for c in input()] for _ in range(H)])
up = S.copy()
down = S.copy()
left = S.copy()
right = S.copy()
for i in range(1, H):
	up[i] = (up[i - 1] + 1) * up[i]
	down[-i - 1] = (down[-i] + 1) * down[-i - 1]
for i in range(1, W):
	left[:, i] = (left[:, i - 1] + 1) * left[:, i]
	right[:, -i - 1] = (right[:, -i] + 1) * right[:, -i - 1]
print(np.max(up + down + left + right) - 3)


import numpy as np
(H, W) = (int(x) for x in input().split())
map1 = [list(input()) for i in range(H)]
map_np = (np.array(map1) == '.') * 1
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
L[:, 0] = map_np[:, 0]
for i in range(1, W):
	L[:, i] = (L[:, i - 1] + 1) * map_np[:, i]
R[:, W - 1] = map_np[:, W - 1]
for i in range(W - 1 - 1, -1, -1):
	R[:, i] = (R[:, i + 1] + 1) * map_np[:, i]
U[0, :] = map_np[0, :]
for i in range(1, H):
	U[i, :] = (U[i - 1, :] + 1) * map_np[i, :]
D[H - 1, :] = map_np[H - 1, :]
for i in range(H - 1 - 1, -1, -1):
	D[i, :] = (D[i + 1, :] + 1) * map_np[i, :]
ans = L + R + U + D - 3
print(np.max(ans))


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


(H, W) = map(int, input().split())
S = [input() for _ in range(H)]
tate = [[0] * W for _ in range(H)]
yoko = [[0] * W for _ in range(H)]
for i in range(W):
	j = 0
	while j < H:
		x = 0
		while j + x < H and S[j + x][i] == '.':
			x += 1
		if x == 0:
			tate[j][i] = 0
			j += 1
		else:
			for t in range(x):
				tate[j + t][i] = x
			j += x
for i in range(H):
	j = 0
	while j < W:
		x = 0
		while j + x < W and S[i][j + x] == '.':
			x += 1
		if x == 0:
			yoko[i][j] = 0
			j += 1
		else:
			for t in range(x):
				yoko[i][j + t] = x
			j += x
print(max([max([tate[i][j] + yoko[i][j] - 1 for j in range(W)]) for i in range(H)]))


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)


import numpy as np
(H, W) = map(int, input().split())
l = np.zeros((H, W), dtype=int)
r = np.zeros((H, W), dtype=int)
d = np.zeros((H, W), dtype=int)
u = np.zeros((H, W), dtype=int)
s = np.array([list(input()) for _ in range(H)]) == '.'
for i in range(H):
	u[i] = (u[i - 1] + 1) * s[i]
	d[-i - 1] = (d[-i] + 1) * s[-i - 1]
for i in range(W):
	l[:, i] = (l[:, i - 1] + 1) * s[:, i]
	r[:, -i - 1] = (r[:, -i] + 1) * s[:, -i - 1]
print(np.max(u + d + l + r) - 3)


import numpy as np

def main():
	(H, W) = list(map(int, input().split(' ')))
	field = np.array([list(input()) for _ in range(H)])
	field = np.where(field == '#', 0, 1)
	(left, right, up, down) = [np.zeros((H, W)) for _ in range(4)]
	for w in range(W):
		left[:, w] = (left[:, w - 1] + 1) * field[:, w]
		right[:, -w - 1] = (right[:, -w] + 1) * field[:, -w - 1]
	for h in range(H):
		up[h, :] = (up[h - 1, :] + 1) * field[h, :]
		down[-h - 1, :] = (down[-h, :] + 1) * field[-h - 1, :]
	s = left + right + up + down - 3
	print(int(np.max(s)))

def __starting_point():
	main()
__starting_point()


import numpy as np
(H, W) = list(map(int, input().split()))
field = [[c == '.' for c in input()] for _ in range(H)]
field = np.array(field, dtype=np.int16)
u = field.copy()
d = field.copy()
l = field.copy()
r = field.copy()
for i in range(1, H):
	u[i] = (u[i - 1] + 1) * u[i]
	d[-i - 1] = (d[-i] + 1) * d[-i - 1]
for j in range(1, W):
	l[:, j] = (l[:, j - 1] + 1) * l[:, j]
	r[:, -j - 1] = (r[:, -j] + 1) * r[:, -j - 1]
print((u + d + l + r - 3).max())


(h, w) = map(int, input().split())
l = [list(input()) for i in range(h)]
cl = [[0] * w for i in range(h)]
for i in range(h):
	s = 0
	for j in range(w):
		if l[i][j] == '#':
			for x in range(s, j):
				cl[i][x] += j - s
			s = j + 1
		elif j == w - 1:
			for x in range(s, j + 1):
				cl[i][x] += j - s + 1
for i in range(w):
	s = 0
	for j in range(h):
		if l[j][i] == '#':
			for x in range(s, j):
				cl[x][i] += j - s
			s = j + 1
		elif j == h - 1:
			for x in range(s, j + 1):
				cl[x][i] += j - s + 1
print(max([max(x) for x in cl]) - 1)


(h, w) = map(int, input().split())
s = [input() + '#' for i in range(h)]
s.append('#' * (w + 1))
h1 = [[0] * (w + 1) for i in range(h + 1)]
w1 = [[0] * (w + 1) for i in range(h + 1)]
for j in range(h):
	r = 0
	for i in range(w + 1):
		if s[j][i] == '#':
			for k in range(i - r, i + 1):
				h1[j][k] = r
			r = 0
			h1[j][i] = 0
		else:
			r += 1
for j in range(w):
	r = 0
	for i in range(h + 1):
		if s[i][j] == '#':
			for k in range(i - r, i + 1):
				w1[k][j] = r
			r = 0
			w1[i][j] = 0
		else:
			r += 1
ans = 0
for i in range(h):
	for j in range(w):
		ans = max(ans, h1[i][j] + w1[i][j] - 1)
print(ans)


from itertools import accumulate

def solve(string):
	(h, w, *s) = string.split()
	(h, w) = map(int, [h, w])
	t = [[1 if __s == '#' else 0 for __s in _s] for _s in s]
	hi = [list(accumulate(_t)) for _t in t]
	vi = [list(accumulate(_t)) for _t in zip(*t)]
	hg = [list(map(len, _s.split('#'))) for _s in s]
	vg = [list(map(len, ''.join(_s).split('#'))) for _s in zip(*s)]
	ans = 0
	for i in range(h):
		for j in range(w):
			ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]])
	return str(ans - 1)
(n, m) = map(int, input().split())
print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


(H, W) = map(int, input().split())
grid = []
for i in range(H):
	grid.append(input())
horiz = [[0] * W for _ in range(H)]
for i in range(H):
	cur = 0
	for j in range(W):
		if grid[i][j] == '#':
			for k in range(cur, j):
				horiz[i][k] = j - cur
			cur = j + 1
	for k in range(cur, W):
		horiz[i][k] = W - cur
maxv = 0
for c in range(W):
	cur = 0
	besth = 0
	for r in range(H):
		if grid[r][c] == '.':
			besth = max(besth, horiz[r][c])
		else:
			maxv = max(maxv, r - cur + besth - 1)
			cur = r + 1
			besth = 0
	maxv = max(maxv, H - cur + besth - 1)
print(maxv)


import copy
(H, W) = map(int, input().split())
grid = [[1 if c == '.' else 0 for c in input()] for _ in range(H)]
L = copy.deepcopy(grid)
R = copy.deepcopy(grid)
U = copy.deepcopy(grid)
D = copy.deepcopy(grid)
for i in range(H):
	for j in range(1, W):
		L[i][j] = (L[i][j - 1] + 1) * L[i][j]
		R[i][-1 - j] = (R[i][-j] + 1) * R[i][-1 - j]
for j in range(W):
	for i in range(1, H):
		U[i][j] = (U[i - 1][j] + 1) * U[i][j]
		D[-1 - i][j] = (D[-i][j] + 1) * D[-1 - 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, 0)
print(ans)


(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
cnt = [[-3] * w for _ in range(h)]
for i in range(h):
	c = 1
	for j in range(w):
		if s[i][j] == '#':
			c = 1
		else:
			cnt[i][j] += c
			c += 1
	c = 1
	for j in range(w)[::-1]:
		if s[i][j] == '#':
			c = 1
		else:
			cnt[i][j] += c
			c += 1
for j in range(w):
	c = 1
	for i in range(h):
		if s[i][j] == '#':
			c = 1
		else:
			cnt[i][j] += c
			c += 1
	c = 1
	for i in range(h)[::-1]:
		if s[i][j] == '#':
			c = 1
		else:
			cnt[i][j] += c
			c += 1
print(max((max(i) for i in cnt)))


(h, w) = map(int, input().split())
s = [input() for _ in range(h)]
d1 = [[0] * (w + 1) for _ in range(h + 1)]
d2 = [[0] * (w + 1) for _ in range(h + 1)]
for i in range(h):
	k = 1
	for j in range(w):
		if s[i][j] == '.':
			d1[i + 1][k] += 1
		else:
			k = j + 2
	for j in range(w):
		if s[i][j] == '.':
			d1[i + 1][j + 1] += d1[i + 1][j]
for j in range(w):
	k = 1
	for i in range(h):
		if s[i][j] == '.':
			d2[k][j + 1] += 1
		else:
			k = i + 2
	for i in range(h):
		if s[i][j] == '.':
			d2[i + 1][j + 1] += d2[i][j + 1]
ans = 0
for i in range(1, h + 1):
	for j in range(1, w + 1):
		d1[i][j] += d2[i][j] - 1
	ans = max(ans, max(d1[i]))
print(ans)


def main():
	import numpy as np
	(h, w) = map(int, input().split())
	grid = np.array([list(input()) for i in range(h)])
	grid = np.where(grid == '.', 1, 0)
	left = np.zeros((h, w), dtype=np.int64)
	right = np.zeros((h, w), dtype=np.int64)
	up = np.zeros((h, w), dtype=np.int64)
	down = np.zeros((h, w), dtype=np.int64)
	for i in range(w):
		left[:, i] = (left[:, i - 1] + 1) * grid[:, i]
		right[:, -i - 1] = (right[:, -i] + 1) * grid[:, -i - 1]
	for i in range(h):
		up[i] = (up[i - 1] + 1) * grid[i]
		down[-i - 1] = (down[-i] + 1) * grid[-i - 1]
	print(np.max(left + right + up + down) - 3)

def __starting_point():
	main()
__starting_point()


import numpy as np
(h, w) = map(int, input().split())
g = np.array([list(input()) for _ in range(h)])
g = np.where(g == '.', 1, 0)
l = np.zeros((h, w), dtype=np.int)
r = np.zeros((h, w), dtype=np.int)
u = np.zeros((h, w), dtype=np.int)
d = np.zeros((h, w), dtype=np.int)
for i in range(w):
	l[:, i] = (l[:, i - 1] + 1) * g[:, i]
	r[:, -i - 1] = (r[:, -i] + 1) * g[:, -i - 1]
for i in range(h):
	u[i, :] = (u[i - 1, :] + 1) * g[i, :]
	d[-i - 1, :] = (d[-i, :] + 1) * g[-i - 1, :]
print(np.max(l + r + u + d) - 3)


(h, w) = map(int, input().split())
s = []
ans = []
for i in range(h):
	s.append(input())
for hi in range(h):
	index = 0
	tmpans = []
	si = '#' + s[hi] + '#'
	for wi in range(w + 2):
		if si[wi] == '#':
			tmpans += [wi - index - 1] * (wi - index - 1)
			index = wi
			tmpans += [0]
	ans.append(tmpans[1:-1])
for wi in range(w):
	index = 0
	tmpans = []
	si = '#' + ''.join([s[x][wi] for x in range(h)]) + '#'
	for hi in range(h + 2):
		if si[hi] == '#':
			tmpans += [hi - index - 1] * (hi - index - 1)
			index = hi
			tmpans += [0]
	for j in range(h):
		tmp = tmpans[j + 1]
		ans[j][wi] += tmp
print(max([max(ans[hi]) for hi in range(h)]) - 1)


import sys
input = lambda : sys.stdin.readline().strip()
(h, w) = [int(x) for x in input().split()]
g = [input() for i in range(h)]
dirs = [(-1, 0), (1, 0), (0, -1), (0, 1)]
hit = [[[0 for j in range(w)] for i in range(h)] for dire in dirs]
for (d, dire) in enumerate(dirs):
	(di, dj) = dire
	for i in range(h) if di < 0 else reversed(range(h)):
		for j in range(w) if dj < 0 else reversed(range(w)):
			if g[i][j] != '#':
				hit[d][i][j] = (hit[d][i + di][j + dj] if 0 <= i + di < h and 0 <= j + dj < w else 0) + 1
print(max((sum((hit[d][i][j] for d in range(len(dirs)))) - 3 for i in range(h) for j in range(w) if g[i][j] != '#')))


import numpy as np
(H, W) = list(map(int, input().split()))
S = np.array([list(input()) for _ in range(H)])
S = np.where(S == '.', 1, 0)
L = np.zeros((H, W), dtype=np.int)
R = np.zeros((H, W), dtype=np.int)
U = np.zeros((H, W), dtype=np.int)
D = np.zeros((H, W), dtype=np.int)
for i in range(W):
	L[:, i] = (L[:, i - 1] + 1) * S[:, i]
	R[:, -i - 1] = (R[:, -i] + 1) * S[:, -i - 1]
for j in range(H):
	U[j, :] = (U[j - 1, :] + 1) * S[j, :]
	D[-j - 1, :] = (D[-j, :] + 1) * S[-j - 1, :]
print(np.max(L + R + U + D) - 3)


(h, w) = map(int, input().split())
s = [input() for i in range(h)]
c = [[0 for i in range(w)] for i in range(h)]
t = 0
for H in range(h):
	for W in range(w):
		if s[H][W] == '#':
			for l in range(1, t + 1):
				c[H][W - l] = t
			t = 0
		else:
			t += 1
	for l in range(1, t + 1):
		c[H][-l] = t
	t = 0
ans = 0
for W in range(w):
	for H in range(h):
		if s[H][W] == '#':
			for l in range(1, t + 1):
				ans = max(c[H - l][W] + t, ans)
			t = 0
		else:
			t += 1
	for l in range(1, t + 1):
		ans = max(c[-l][W] + t, ans)
	t = 0
print(max(ans - 1, 0))


(h, w) = map(int, input().split())
s = [[*map(lambda c: c == '.', input())] for _ in [0] * h]
for i in 'LRUD':
	exec(i + '= [[0] * w for _ in [0] * h]')
for i in range(h):
	for j in range(w):
		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
for j in range(w):
	for i in range(h):
		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
print(max((L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(h) for j in range(w))))