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

Solution (Python):
import numpy as np

H,W = map(int,input().split())
temp = np.array([list(input()) for _ in range(H)])

grid = np.ones((H+2,W+2),dtype=np.bool)
grid[1:-1,1:-1] = (temp == '


def F(transpose):
  x = grid.copy()
  if transpose:
    x = x.T
  x = np.ravel(x) 
  
  zero_idx = np.nonzero(x)[0]
  zero_span = np.diff(zero_idx) - 1 
  
  y = np.zeros(x.shape[0],dtype=np.int32)
  y[1:][zero_idx[:-1]] = zero_span 
  y[zero_idx[1:]] -= zero_span 
  y = y.cumsum()
  if transpose:
    y = y.reshape(grid.T.shape).T
  else:
    y = y.reshape(grid.shape)
  return y

answer = (F(True) + F(False)).max() - 1
print(answer)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))


def main():
    n,m = LI()
    a = [[c=='
    b = [[0] * m for _ in range(n)]
    c = [[0] * m for _ in range(n)]
    for i in range(n):
        j = 0
        ai = a[i]
        while j < m:
            if ai[j]:
                j += 1
                continue
            k = j+1
            while k < m and not ai[k]:
                k += 1
            s = k - j
            for l in range(j,k):
                b[i][l] = s
            j = k

    for i in range(m):
        j = 0
        while j < n:
            if a[j][i]:
                j += 1
                continue
            k = j+1
            while k < n and not a[k][i]:
                k += 1
            s = k - j
            for l in range(j,k):
                c[l][i] = s
            j = k

    r = 0
    for i in range(n):
        bi = b[i]
        ci = c[i]
        for j in range(m):
            t = bi[j] + ci[j] - 1
            if r < t:
                r = t

    return r


print(main())

Solution (Python):
import numpy as np

H,W = map(int,input().split())
temp = np.array([list(input()) for _ in range(H)])

map = np.ones((H+2,W+2),dtype=np.bool)
map[1:-1,1:-1] = (temp == '


def F(transpose):
  x = map.copy()
  if transpose:
    x = x.T
  x = np.ravel(x) 
  
  zero_idx = np.nonzero(x)[0]
  zero_span = np.diff(zero_idx) - 1 
  y = np.zeros(len(x),dtype=np.int32)
  y[1:][zero_idx[:-1]] = zero_span
  y[zero_idx[1:]] -= zero_span
  y = y.cumsum()
  if transpose:
    y = y.reshape(map.T.shape).T
  else:
    y = y.reshape(map.shape)
  return y

answer = np.zeros(map.shape,dtype=np.int32)
for t in [True,False]:
  answer += F(t)
    
answer = answer.max() - 1
print(answer)

Solution (Python):
H, W = map(int, input().split())
dungeon = []
for i in range(0, H):
	dungeon.append(input())
across = []
for i in range(0, H):
	lst = []
	r = []
	for j in range(0, W):
		if dungeon[i][j] == '.':
			if r == []: r.append(j)
		else:
			if r != []:
				r.append(j)
				lst.append(r)
				r = []
	if r != []:
		r.append(W)
		lst.append(r)
	across.append(lst)
acrossdungeon = []
for i in range(0, H):
	lst = []
	index = 0
	for j in range(0, W):
		if dungeon[i][j] == '.':
			lst.append(across[i][index][1]-across[i][index][0])
		else:
			if j != 0:
				if lst[-1] != -1:
					index += 1
			lst.append(-1)
	acrossdungeon.append(lst)
down = []
for i in range(0, W):
	lst = []
	r = []
	for j in range(0, H):
		if dungeon[j][i] == '.':
			if r == []: r.append(j)
		else:
			if r != []:
				r.append(j)
				lst.append(r)
				r = []
	if r != []:
		r.append(H)
		lst.append(r)
	down.append(lst)
downdungeon = []
for i in range(0, W):
	lst = []
	index = 0
	for j in range(0, H):
		if dungeon[j][i] == '.':
			lst.append(down[i][index][1]-down[i][index][0])
		else:
			if j != 0:
				if lst[-1] != -1:
					index += 1
			lst.append(-1)
	downdungeon.append(lst)
max = 0
for i in range(0, H):
	for j in range(0, W):
		if dungeon[i][j] != '
			lights = acrossdungeon[i][j] + downdungeon[j][i] - 1
			if max < lights: max = lights
print(max)

Solution (Python):
import numpy as np

h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
grid = (np.array(grid) == ".") * 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 j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]

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

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10



H, W = [int(x) for x in stdin.readline().rstrip().split()]
S = [stdin.readline().rstrip() for _ in range(H)]



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


for i in range(H):
    for j in range(W):
        if S[i][j] == "
            L[i][j] = 0
            continue

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


for i in range(H-1, -1, -1):
    for j in range(W-1, -1, -1):
        if S[i][j] == "
            R[i][j] = 0
            continue

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


for j in range(W):
    for i in range(H):
        if S[i][j] == "
            U[i][j] = 0
            continue

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


for j in range(W-1, -1, -1):
    for i in range(H-1, -1, -1):
        if S[i][j] == "
            D[i][j] = 0
            continue

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


ans = -INF

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








print(ans)

Solution (Python):
import numpy as np

h, w = map(int, input().split())
grid = []
for i in range(h):
    grid.append(list(input()))
grid = (np.array(grid) == ".")

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 j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]

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

Solution (Python):
import numpy as np

H,W = map(int,input().split())
temp = np.array([list(input()) for _ in range(H)])

map = np.zeros((H+2,W+2),dtype=np.int32)
map[1:-1,1:-1][temp == '.'] = 1


def F(transpose,reverse):
  x = map.copy()
  if transpose:
    x = x.T
  x = np.ravel(x)
  if reverse:
    x = x[::-1]
  zero_idx = np.nonzero(x==0)[0]
  x[zero_idx[1:]] = 1-np.diff(zero_idx) 
  x = x.cumsum()
  if reverse:
    x = x[::-1]
  if transpose:
    x = x.reshape(map.T.shape).T
  else:
    x = x.reshape(map.shape)
  return x

answer = np.zeros_like(map)
for t in [True,False]:
  for r in [True,False]:
    answer += F(t,r)
    
answer = answer.max() - 3
print(answer)

Solution (Python):
import numpy as np

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

grid = []
for i in range(h):
    grid.append(list(input()))
grid = (np.array(grid) == ".") * 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 j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]

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

Solution (Python):
import numpy as np

h, w = map(int, input().split())
grid = [[False for j in range(w)] for i in range(h)]

for i in range(h):
    s = input()
    for j in range(w):
        if s[j] == '.':
            grid[i][j] = 1
        else:
            grid[i][j] = 0

grid = np.array(grid)

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 j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]

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

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

sum_s = [[], []]

for y in range(H):
	count, line = 0, []
	for x in range(W):
		if STAGE[y][x] == ".":
			count += 1
		else:
			if 0 < count:
				line += [count] * count
			line += [0]
			count = 0
	else:
		if 0 < count:
			line += [count] * count
	sum_s[0] += [line]

for x in range(W):
	count, line = 0, []
	for y in range(H):
		if STAGE[y][x] == ".":
			count += 1
		else:
			if 0 < count:
				line += [count] * count
			line += [0]
			count = 0
	else:
		if 0 < count:
			line += [count] * count
	sum_s[1] += [line]
"""
for line in sum_s[0]:
	print(*line)
print()
for line in sum_s[1]:
	print(*line)
"""
max_score = 0
for y in range(H):
	for x in range(W):
		max_score = max(max_score, sum_s[0][y][x] + sum_s[1][x][y] - 1)

print(max_score)

Solution (Python):
from sys import stdin
import math
import fractions
from collections import deque
import itertools

INF = 10 ** 10



H, W = [int(x) for x in stdin.readline().rstrip().split()]
S = [[x for x in stdin.readline().rstrip()] for _ in range(H)]



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


for i in range(H):
    for j in range(W):
        if S[i][j] == "
            L[i][j] = 0
            continue

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


for i in range(H-1, -1, -1):
    for j in range(W-1, -1, -1):
        if S[i][j] == "
            R[i][j] = 0
            continue

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


for j in range(W):
    for i in range(H):
        if S[i][j] == "
            U[i][j] = 0
            continue

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


for j in range(W-1, -1, -1):
    for i in range(H-1, -1, -1):
        if S[i][j] == "
            D[i][j] = 0
            continue

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


ans = -INF

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








print(ans)

Solution (Python):
h,w=map(int,input().split())
sl=[input() for i in range(h)]
ll=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if sl[i][j]=='.':
            if j==0:
                ll[i][j]=1
            else:
                ll[i][j]=ll[i][j-1]+1
        else:
            ll[i][j]=0
rl=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w-1,-1,-1):
        if sl[i][j]=='.':
            if j==w-1:
                rl[i][j]=1
            else:
                rl[i][j]=rl[i][j+1]+1
        else:
            rl[i][j]=0
ul=[[0]*w for i in range(h)]
for j in range(w):
    for i in range(h):
        if sl[i][j]=='.':
            if i==0:
                ul[i][j]=1
            else:
                ul[i][j]=ul[i-1][j]+1
        else:
            ul[i][j]=0
dl=[[0]*w for i in range(h)]
for j in range(w):
    for i in range(h-1,-1,-1):
        if sl[i][j]=='.':
            if i==h-1:
                dl[i][j]=1
            else:
                dl[i][j]=dl[i+1][j]+1
        else:
            dl[i][j]=0
ans=0
for i in range(h):
    for j in range(w):
            ans=max(ans,ll[i][j]+rl[i][j]+ul[i][j]+dl[i][j]-3)
print(ans)

Solution (Python):
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)

Solution (Python):

"""解説
https://www.youtube.com/watch?v=L8grWxBlIZ4

PDFに書いてある実装をする。

....
..
.

それぞれのマスについて、

・左マスを照らせる個数: L[i][j]
・右マスを照らせる個数: R[i][j]
・上マスを照らせる個数: U[i][j]
・下マスを照らせる個数: D[i][j]

をそれぞれ計算する。

左マスを照らす漸化式L[i][j]は、

・i行j列に障害物がある場合はL[i][j] = 0
・そうでないとき、j=1ならば、L[i][j] = 1
・そうでないとき、j>1ならば、L[i][j] = L[i][j-1] + 1

求める答えは、L[i][j]+R[i][j]+U[i][j]+D[i][j]-3 の最大値


計算量はO(HW)。

H,W = 2000なので、O(HW)はO(4*10**6)。 Pythonでこの計算量は無理だろと思って実装を諦めたが、いけるっぽい。認識を改めた。というかPyPyもあるし。

と思ったら普通に無理だった。

numpyを使ったらfor文を一個減らせる。計算量が減ったかどうかは内部処理によるので知らんけどACした。結論：numpyの行列計算は速い。

・参考にした他人のコード
https://atcoder.jp/contests/abc129/submissions/5861992

"""
import numpy as np

def solve():
    H, W = list(map(int, input().split()))
    grid = []
    for i in range(H):
        grid.append(list(input()))
    grid = (np.array(grid) == ".") * 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 j in range(W):
        if j == 0:
            L[:, j] = grid[:, j]
        else:
            L[:, j] = (L[:, j-1] + 1) * grid[:, j]
    
    for j in range(W-1, -1, -1):
        if j == W-1:
            R[:, j] = grid[:, j]
        else:
            R[:, j] = (R[:, j+1] + 1) * grid[:, j]

    for i in range(H):
        if i == 0:
            U[i] = grid[i] * 1
        else:
            U[i] = (U[i-1] + 1) * grid[i]
    
    for i in range(H-1, -1, -1):
        if i == H-1:
            D[i] = grid[i]
        else:
            D[i] = (D[i+1] + 1) * grid[i]

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


if __name__ == "__main__":
    solve()

Solution (Python):

"""解説
https://www.youtube.com/watch?v=L8grWxBlIZ4

PDFに書いてある実装をする。

....
..
.

それぞれのマスについて、

・左マスを照らせる個数: L[i][j]
・右マスを照らせる個数: R[i][j]
・上マスを照らせる個数: U[i][j]
・下マスを照らせる個数: D[i][j]

をそれぞれ計算する。

左マスを照らす漸化式L[i][j]は、

・i行j列に障害物がある場合はL[i][j] = 0
・そうでないとき、j=1ならば、L[i][j] = 1
・そうでないとき、j>1ならば、L[i][j] = L[i][j-1] + 1

求める答えは、L[i][j]+R[i][j]+U[i][j]+D[i][j]-3 の最大値


計算量はO(HW)。

H,W = 2000なので、O(HW)はO(4*10**6)。 Pythonでこの計算量は無理だろと思って実装を諦めたが、いけるっぽい。認識を改めた。というかPyPyもあるし。

と思ったら普通に無理だった。

numpyを使ったらfor文を一個減らせる。計算量が減ったかどうかは内部処理によるので知らんけどACした。結論：numpyの行列計算は速い。

"""
import numpy as np

def solve():
    H, W = list(map(int, input().split()))
    grid = []
    for i in range(H):
        grid.append(list(input()))
    grid = (np.array(grid) == ".") * 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 j in range(W):
        if j == 0:
            L[:, j] = grid[:, j]
        else:
            L[:, j] = (L[:, j-1] + 1) * grid[:, j]
    
    for j in range(W-1, -1, -1):
        if j == W-1:
            R[:, j] = grid[:, j]
        else:
            R[:, j] = (R[:, j+1] + 1) * grid[:, j]

    for i in range(H):
        if i == 0:
            U[i] = grid[i] * 1
        else:
            U[i] = (U[i-1] + 1) * grid[i]
    
    for i in range(H-1, -1, -1):
        if i == H-1:
            D[i] = grid[i]
        else:
            D[i] = (D[i+1] + 1) * grid[i]

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


if __name__ == "__main__":
    solve()

Solution (Python):
def f(h, w):
    t = [input() for _ in range(h)]
    U = [[0] * (w + 2) for _ in range(h + 2)]
    D = [[0] * (w + 2) for _ in range(h + 2)]
    L = [[0] * (w + 2) for _ in range(h + 2)]
    R = [[0] * (w + 2) for _ in range(h + 2)]
    ans = 0
    Ui1 = U[0]
    for i in range(1, 1 + h):
        Ui = U[i]
        Li = L[i]
        ti1 = t[i - 1]
        for j, tk in enumerate(ti1):
            j += 1
            if tk == "
                Ui[j] = 0
                Li[j] = 0
            else:
                Ui[j] = Ui1[j] + 1
                Li[j] = Li[j - 1] + 1
        Ui1 = Ui
        Di1 = D[-1]
    for i in range(h, 0, -1):
        Ui = U[i]
        Li = L[i]
        Di = D[i]
        Ri = R[i]
        ti1 = t[i - 1]
        for j,tk in enumerate(ti1[::-1]):
            j=w-j
            if tk == "
                Di[j] = 0
                Ri[j] = 0
            else:
                Di[j] = Di1[j] + 1
                Ri[j] = Ri[j + 1] + 1
                tmp = Ui[j] + Di[j] + Li[j] + Ri[j]
                if tmp > ans:
                    ans = tmp
        Di1 = Di
    print(ans - 3)

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

Solution (Python):
def f(h, w):
    t = [input() for _ in range(h)]
    U = [[0] * (w + 2) for _ in range(h + 2)]
    D = [[0] * (w + 2) for _ in range(h + 2)]
    L = [[0] * (w + 2) for _ in range(h + 2)]
    R = [[0] * (w + 2) for _ in range(h + 2)]
    ans = 0
    Ui1 = U[0]
    for i in range(1, 1 + h):
        Ui = U[i]
        Li = L[i]
        ti1 = t[i - 1]
        for j, tk in enumerate(ti1):
            j += 1
            if tk == "
                Ui[j] = 0
                Li[j] = 0
            else:
                Ui[j] = Ui1[j] + 1
                Li[j] = Li[j - 1] + 1
        Ui1 = Ui
        Di1 = D[-1]
    for i in range(h, 0, -1):
        Ui = U[i]
        Li = L[i]
        Di = D[i]
        Ri = R[i]
        ti1 = t[i - 1]
        for j in range(w, 0, -1):
            if ti1[j - 1] == "
                Di[j] = 0
                Ri[j] = 0
            else:
                Di[j] = Di1[j] + 1
                Ri[j] = Ri[j + 1] + 1
                tmp = Ui[j] + Di[j] + Li[j] + Ri[j]
                if tmp > ans:
                    ans = tmp
        Di1 = Di
    print(ans - 3)

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

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


"""

Rs = [[0]*W for i in range(H)]
Ls = [[0]*W for i in range(H)]
Ds = [[0]*W for i in range(H)]
Us = [[0]*W for i in range(H)]

for i in range(H):
    tmp = 0
    
    for j in range(W):
        if S[i][j] == '
            tmp = 0
        else:
            tmp += 1
            Ls[i][j] = tmp
    tmp = 0
    
    for j in reversed(range(W)):
        if S[i][j] == '
            tmp = 0
        else:
            tmp += 1
            Rs[i][j] = tmp


for j in range(W):
    tmp = 0
    
    for i in range(H):
        if S[i][j] == '
            tmp = 0
        else:
            tmp += 1
            Us[i][j] = tmp
    tmp = 0
    
    for i in reversed(range(H)):
        if S[i][j] == '
            tmp = 0
        else:
            tmp += 1
            Ds[i][j] = tmp

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '
            continue
        
        tmp = Rs[i][j] + Ls[i][j] + Ds[i][j] + Us[i][j] - 3
        ans = max(ans, tmp)
print(ans)
"""


"""
左・上からゴリゴリ攻めていくパターン
一回通ったかどうかのフラグが必要
"""

cnt = [[0] * (W+1) for i in range(H+1)]

for i in range(H):
    done = [False] * (W+1)
    for j in range(W):
        l = 0
        if done[j]: continue
        if S[i][j] == ".":
            while j+l < W:
                if S[i][j+l] == ".":
                    l += 1
                else:
                    break
        for k in range(j,j+l):
            cnt[i][k] += l
            done[k] = True


for j in range(W):
    done = [False] * (H+1)
    for i in range(H):
        l = 0
        if done[i]: continue
        if S[i][j] == ".":
            while i+l < H:
                if S[i+l][j] == ".":
                    l += 1
                else:
                    break
        for k in range(i,i+l):
            cnt[k][j] += l
            done[k] = True

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

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

h, w = [ int(v) for v in input().split() ]

field = [ list(map(int,input().replace("

yoko = [ copy.deepcopy(field[i]) for i in range(h)]


for i in range(h):
	for j in range(1,w):
		if yoko[i][j] == 0:
			yoko[i][j] = 0
		else:
			yoko[i][j] += yoko[i][j-1]
	for j in range(w-1,0,-1):
		if yoko[i][j-1] != 0:
			yoko[i][j-1] = max(yoko[i][j-1],yoko[i][j])

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

for i in range(w):
	for j in range(1,h):
		if tate[i][j] == 0:
			tate[i][j] = 0
		else:
			tate[i][j] += tate[i][j-1]
	for j in range(h-1,0,-1):
		if tate[i][j-1] != 0:
			tate[i][j-1] = max(tate[i][j-1],tate[i][j])


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

print(ans-1)

Solution (Python):
H, W = map(int, input().split())

P = [[0 if x == "
C = [[-1*P[x][y] for y in range(W)] + [0] for x in range(H)]
W += 1
H += 1
P.append([0] * W)
C.append([0] * W)


for i in range(H):
    cnt = 0
    for j in range(W):
        if P[i][j] == 0:
            for k in range(cnt):
                C[i][j-1-k] += k
            cnt = 0
        else:
            cnt += 1
        C[i][j] += cnt

for j in range(W):
    cnt = 0
    for i in range(H):
        if P[i][j] == 0:
            for k in range(cnt):
                C[i-1-k][j] += k
            cnt = 0
        else:
            cnt += 1
        C[i][j] += cnt


print(max((x for ci in C for x in ci)))

Solution (Python):
import fractions 
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) 

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

lights = [[(0,0) for j in range(W)] for i in range(H)]

def count_ver(i,j):
    cnt = 0
    for x in range(i,W):
        if S[j][x] == ".":
            cnt += 1
        else:
            break
    for x in range(i,i+cnt):
        ver,hor = lights[j][x]
        lights[j][x] = (cnt,hor)
    return cnt


def count_hor(i,j):
    cnt = 0
    for y in range(j,H):
        if S[y][i] == ".":
            cnt += 1
        else:
            break
    for y in range(j,j+cnt):
        ver,hor = lights[y][i]
        lights[y][i] = (ver,cnt)
    return cnt

ans = -1
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ver,hor = lights[i][j]
            if ver == 0:
                ver = count_ver(j,i)
            if hor == 0:
                hor = count_hor(j,i)
            ans = max(ans,hor+ver-1)

print(ans)

Solution (Python):


H, W = map(int, input().split())
lst = [['
lst += [['
lst += [['


lst_ue = [[0] * (W+2) for i in range(H+2)]
lst_shita = [[0] * (W+2) for i in range(H+2)]
lst_migi = [[0] * (W+2) for i in range(H+2)]
lst_hidari = [[0] * (W+2) for i in range(H+2)]

for i in range(1, H+1):
    for j in range(1, W+1):
        lst_hidari[i][j] = 0 if lst[i][j] == '
    for j in range(W, 0, -1):
        lst_migi[i][j] = 0 if lst[i][j] == '

for j in range(1, W+1):
    for i in range(1, H+1):
        lst_ue[i][j] = 0 if lst[i][j] == '
    for i in range(H+1, 0, -1):
        lst_shita[i][j] = 0 if lst[i][j] == '

ans = 0
for i in range(1,H+1):
    for j in range(1, W+1):
        ans = max(ans, lst_ue[i][j]+lst_shita[i][j]+lst_migi[i][j]+lst_hidari[i][j]-3)

print (ans)

Solution (Python):
H,W = map(int,input().split())

S = [input() for i in range(H)]

L = [[0 for x in range(W)] for y in range(H)]
R = [[0 for x in range(W)] for y in range(H)]
U = [[0 for x in range(W)] for y in range(H)]
D = [[0 for x in range(W)] for y in range(H)]


for i in range(H) :
    flg = 0
    for j in range(W) :
        if S[i][j] == "
            flg = 1
        elif flg :
            flg = 0
        elif j == 0 :
            L[i][j] = 0
        else :
            L[i][j] = L[i][j-1] + 1
    
    flg = 0
    for j in range(W-1,-1,-1) :
        if S[i][j] == "
            flg = 1
        elif flg :
            flg = 0
        elif j == W-1 :
            R[i][j] = 0
        else :
            R[i][j] = R[i][j+1] + 1

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

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

ans += 1

print(ans)

Solution (Python):
H,W = map(int,input().split())
List=[input() for i in range(H)]
A =[[] for i in range(H)]
B =[[] for i in range(W)]
for i in range(H):
    k = 0
    a = 0
    while k < W:
        if List[i][k]==".":
            a += 1
            k = k+1
        else:
            for j in range(a):
                A[i].append(a)
            A[i].append(0)
            a = 0
            k = k+1
    for j in range(a):
                A[i].append(a)
for i in range(W):
    k = 0
    a = 0
    while k < H:
        if List[k][i]==".":
            a += 1
            k = k+1
        else:
            for j in range(a):
                B[i].append(a)
            B[i].append(0)
            a = 0
            k = k+1
    for j in range(a):
                B[i].append(a)
max = 0
for i in range(H):
    for j in range(W):
        if max < A[i][j] + B[j][i]:
            max = A[i][j] + B[j][i]
print(max-1)

Solution (Python):
H,W = map(int,input().split())
List=[input() for i in range(H)]
A =[[1]*(W) for i in range(H)]
B =[[1]*(H) for i in range(W)]
for i in range(H):
    k = 0
    a = 0
    while k < W:
        if List[i][k]==".":
            a += 1
            k = k+1
        else:
            for j in range(a):
                A[i][k-j-1]=a
            A[i][k]=a
            a = 0
            k = k+1
    for j in range(a):
                A[i][k-j-1]=a
for i in range(W):
    k = 0
    a = 0
    while k < H:
        if List[k][i]==".":
            a += 1
            k = k+1
        else:
            for j in range(a):
                B[i][k-j-1]=a
            B[i][k] = 0
            a = 0
            k = k+1
    for j in range(a):
                B[i][k-j-1]= a
max = 0
for i in range(H):
    for j in range(W):
        if max < A[i][j] + B[j][i]:
            max = A[i][j] + B[j][i]
print(max-1)

Solution (Python):
import numpy as np

H, W = 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):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]

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

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

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

dw = []
dh = []

for i in range(h):
    cw = []
    for j in range(w):
        if s[i][j] == '
            cw.append(0)
        elif j == 0 or s[i][j - 1] == '
            count = 0
            for k in range(j, w):
                if s[i][k] == '.':
                    count += 1
                    if k == w - 1:
                        cw.append(count)
                else:
                    cw.append(count)
                    break
        else:
            cw.append(cw[j - 1])
    dw.append(cw)

for j in range(w):
    ch = []
    for i in range(h):
        if s[i][j] == '
            ch.append(0)
        elif i == 0 or s[i - 1][j] == '
            count = 0
            for k in range(i, h):
                if s[k][j] == '.':
                    count += 1
                    if k == h - 1:
                        ch.append(count)
                else:
                    ch.append(count)
                    break
        else:
            ch.append(ch[i - 1])
    dh.append(ch)

max = 0
for i in range(h):
    for j in range(w):
        sum = dw[i][j] + dh[j][i]
        if max < sum:
            max = sum
print(max - 1)