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

Solution (Python):
import sys
input=sys.stdin.readline
H, W = [int(x) for x in input().split()]
board = []
for _ in range(H):
    board.append(input())

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 board[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j - 1] + 1

for i in range(H):
    for j in reversed(range(W)):
        if board[i][j] == '.':
            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 board[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i - 1][j] + 1

for j in range(W):
    for i in reversed(range(H)):
        if board[i][j] == '.':
            if i == H - 1:
                D[i][j] = 1
            else:
                D[i][j] = D[i + 1][j] + 1

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

Solution (Python):
import sys
import copy

input = sys.stdin.readline

def mymax(a, b, c=None):
    """
        最大値を返すメソッド.
        値が2, 3つの場合のみ対応している.
    """
    if c == None:
        if a > b:
            return a
        else:
            return b

    if a > b:
        if c > a:
            return c
        else:
            return a
    else:
        if c > b:
            return c
        else:
            return b

def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(list(input()[:-1]))
    
    L = [[0] * W for _ in range(H)]
    R = copy.deepcopy(L)
    U = copy.deepcopy(L)
    D = copy.deepcopy(L)
    
    for h in range(H):
        cntL, cntR = 0, 0
        for w in range(W):
            wreverse = W - w - 1
            if grid[h][w] == '.':
                cntL += 1
            else:
                cntL = 0
            if grid[h][wreverse] == '.':
                cntR += 1
            else:
                cntR = 0
            L[h][w] = cntL
            R[h][wreverse] = cntR

    for w in range(W):
        cntU, cntD = 0, 0
        for h in range(H):
            hreverse = H - h - 1
            if grid[h][w] == '.':
                cntU += 1
            else:
                cntU = 0
            if grid[hreverse][w] == '.':
                cntD += 1
            else:
                cntD = 0
            U[h][w] = cntU
            D[hreverse][w] = cntD
    
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = mymax(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3)

    print(ans)
        
if __name__ == "__main__":
    main()

Solution (Python):
import sys
import copy

input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(list(input()[:-1]))
    
    L = [[0] * W for _ in range(H)]
    R = copy.deepcopy(L)
    U = copy.deepcopy(L)
    D = copy.deepcopy(L)
    
    for h in range(H):
        cntL, cntR = 0, 0
        for w in range(W):
            wreverse = W - w - 1
            if grid[h][w] == '.':
                cntL += 1
            else:
                cntL = 0
            if grid[h][wreverse] == '.':
                cntR += 1
            else:
                cntR = 0
            L[h][w] = cntL
            R[h][wreverse] = cntR

    for w in range(W):
        cntU, cntD = 0, 0
        for h in range(H):
            hreverse = H - h - 1
            if grid[h][w] == '.':
                cntU += 1
            else:
                cntU = 0
            if grid[hreverse][w] == '.':
                cntD += 1
            else:
                cntD = 0
            U[h][w] = cntU
            D[hreverse][w] = cntD
    
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3)

    print(ans)
        
if __name__ == "__main__":
    main()

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

graph = []
for i in range(H):
    graph.append(input())

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


for y in range(H):
    for x in range(W):
        if graph[y][x] == "
            L[y][x] = 0
        elif x == 0:
            L[y][x] = 1
        else:
            L[y][x] = L[y][x-1] + 1

for x in range(W):
    for y in range(H):
        if graph[y][x] == "
            U[y][x] = 0
        elif y == 0:
            U[y][x] = 1
        else:
            U[y][x] = U[y-1][x] + 1

for x in range(W):
    for y in range(H-1, -1, -1):
        if graph[y][x] == "
            D[y][x] = 0
        elif y == H-1:
            D[y][x] = 1
        else:
            D[y][x] = D[y+1][x] + 1

for y in range(H):
    for x in range(W-1, -1, -1):
        if graph[y][x] == "
            R[y][x] = 0
        elif x == W-1:
            R[y][x] = 1
        else:
            R[y][x] = R[y][x+1] + 1

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

print(ans)

Solution (Python):









def solve(H, W, Si):
    R = [[0] * W for _ in range(H)]
    L = [[0] * W for _ in range(H)]
    D = [[0] * W for _ in range(H)]
    U = [[0] * W for _ in range(H)]

    
    for h in range(H):
        for w in range(W):
            if Si[h][w] == '
                R[h][w] = 0
                continue
            if w == 0:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w - 1] + 1
    
    for h in range(H):
        for w in range(W):
            if Si[h][W - w - 1] == '
                L[h][W - w - 1] = 0
                continue
            if w == 0:
                L[h][W - w - 1] = 1
            else:
                L[h][W - w - 1] = L[h][W - w] + 1
    
    for w in range(W):
        for h in range(H):
            if Si[h][w] == '
                D[h][w] = 0
                continue
            if h == 0:
                D[h][w] = 1
            else:
                D[h][w] = D[h - 1][w] + 1
    
    for w in range(W):
        for h in range(H):
            if Si[H - h - 1][w] == '
                U[H - h - 1][w] = 0
                continue
            if h == 0:
                U[H - h - 1][w] = 1
            else:
                U[H - h - 1][w] = U[H - h][w] + 1

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


if __name__ == '__main__':
    H, W = map(int, input().split())
    Si = [input() for _ in range(H)]

    
    
    
    
    
    
    solve(H, W, Si)

Solution (Python):








def solve(H, W, Si):
    Si = ['
    lamp_map = [[[-1, -1] for _ in range(W + 2)] for _ in range(H + 2)]
    ans = 0
    for h in range(1, H + 2):
        for w in range(1, W + 2):
            
            if Si[h][w] == '
                lamp_map[h][w][0] = 0
                lamp_map[h][w][1] = 0
                continue
            
            if lamp_map[h - 1][w][0] > 0:
                lamp_map[h][w][0] = lamp_map[h - 1][w][0]
            else:
                tmp = 0
                while Si[h + tmp][w] == '.':
                    tmp += 1
                lamp_map[h][w][0] = tmp
            
            if lamp_map[h][w - 1][1] > 0:
                lamp_map[h][w][1] = lamp_map[h][w - 1][1]
            else:
                tmp = 0
                while Si[h][w + tmp] == '.':
                    tmp += 1
                lamp_map[h][w][1] = tmp
            ans = max(ans, sum(lamp_map[h][w]) - 1)
    print(ans)


if __name__ == '__main__':
    H, W = map(int, input().split())
    Si = [input() for _ in range(H)]

    
    
    
    
    
    
    solve(H, W, Si)

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


R = [[0]*w for _ in range(h)]
L = [[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):
    cur = 0
    for j in range(w-1,-1,-1):
        if s[i][j] == '
            cur = 0
        else:
            cur += 1
        R[i][j] = cur

for i in range(h):
    cur = 0
    for j in range(w):
        if s[i][j] == '
            cur = 0
        else:
            cur += 1
        L[i][j] = cur

for j in range(w):
    cur = 0
    for i in range(h):
        if s[i][j] == '
            cur = 0
        else:
            cur += 1
        D[i][j] = cur

for j in range(w):
    cur = 0
    for i in range(h-1,-1,-1):
        if s[i][j] == '
            cur = 0
        else:
            cur += 1
        U[i][j] = cur

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] =='
            continue
        ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)

Solution (Python):
import numpy as np
H, W = map(int,input().split())
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)

Solution (Python):
H, W = map(int,input().split())
s = []
rc = [[[None]*W for _ in range(H)] for _ in range(2)]
for _ in range(H):
    s.append(list(input()))
for j in range(H):
    l = s[j]
    for i in range(W):
        if l[i] == "
            rc[0][j][i] = 0
        elif i > 0:
            rc[0][j][i] = rc[0][j][i-1] + 1
        else:
            rc[0][j][i] = 1
    for i in range(W-1, -1, -1):
        if l[i] == "
            continue
        elif i < W-1:
            rc[0][j][i] = max(rc[0][j][i+1], rc[0][j][i])
for i in range(W):
    for j in range(H):
        if s[j][i] == "
            rc[1][j][i] = 0
        elif j > 0:
            rc[1][j][i] = rc[1][j-1][i] + 1
        else:
            rc[1][j][i] = 1
    for j in range(H-1, -1, -1):
        if s[j][i] == "
            continue
        elif j < H-1:
            rc[1][j][i] = max(rc[1][j+1][i], rc[1][j][i])
ans = 0
for j in range(H):
    for i in range(W):
        ans = max(rc[0][j][i] + rc[1][j][i] - 1, ans)
print(ans)

Solution (Python):
n,m = map(int, input().split())

S = [[] for _ in range(n)]

for i in range(n):
    S[i] = list(input())

rows = [[] for _ in range(n)]
cols = [[] for _ in range(m)]

start = [[] for _ in range(n)]
end = [[] for _ in range(n)]

for i in range(n):
    rows[i].append(-1)
    for j in range(m):
        if(S[i][j] == '
            rows[i].append(j)
    rows[i].append(m)

    l = 0
    r = 1
    cnt = 0

    for j in range(m):
        if(S[i][j] != '
            start[i].append(rows[i][r] - rows[i][l])
        else:
            start[i].append(0)
        if(j == rows[i][r]):
            l = r
            r = r + 1
ans = 0
for i in range(m):
    cols[i].append(-1)

    for j in range(n):
        if(S[j][i] == '
            cols[i].append(j)
    cols[i].append(n)

    l = 0
    r = 1
    cnt = 0

    for j in range(n):
        if(S[j][i] != '
            end[j].append(cols[i][r] - cols[i][l])
            
        else:
            end[j].append(0)
        if(j == cols[i][r]):
            l = r
            r = r + 1
        



for i in range(n):
    for j in range(m):
        
            ans = max(ans, start[i][j] + end[i][j])

print(ans - 3)

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

tate = [[0] * W for i in range(H)]
yoko = [[0] * W for i in range(H)]

for i in range(H):
	for j in range(W):
		if grid[i][j] == ".":
			if tate[i][j] == 0:
				back = 0
				while(1):
					if 0 > i - back or grid[i - back][j] == "
						break
					else:
						back += 1
				forth = 0
				while(1):
					if i + forth >= H or grid[i + forth][j] == "
						break
					else:
						forth += 1
				for k in range(-back + 1, forth):
					tate[i + k][j] = forth + back - 1
			if yoko[i][j] == 0:
				back = 0
				while(1):
					if 0 > j - back or grid[i][j - back] == "
						break
					else:
						back += 1
				forth = 0
				while(1):
					if j + forth >= W or grid[i][j + forth] == "
						break
					else:
						forth += 1
				for k in range(-back + 1, forth):
					yoko[i][j + k] = forth + back - 1

maxl = 0
for i in range(H):
	for j in range(W):
		maxl = max(maxl, tate[i][j] + yoko[i][j] - 1)
print(maxl)

Solution (Python):
from collections import deque

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

s = [list(input()) for _ in range(h)]

yo = [[0] * w for _ in range(h)]
q = deque([])
c = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1
        
        if s[i][j] == "
            while len(q) > 0:
                x, y = q.pop()
                yo[x][y] = c
            c = 0



m = 0

c = 0
for j in range(w):
    for i in range(h):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1

        if s[i][j] == "
            while len(q) > 0:
                x, y = q.pop()
                m = max(m, yo[x][y] + c - 1)
            c = 0
print(m)

Solution (Python):
H,W=list(map(int,input().split()))
import numpy as np
m=np.array([[0 if i=="
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)

Solution (Python):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
u_light = [[0]*w for _ in range(h)] 
d_light = [[0]*w for _ in range(h)] 
l_light = [[0]*w for _ in range(h)] 
r_light = [[0]*w for _ in range(h)] 

def count_light(i, j):
    if s[i][j] == '.':
        return 1
    else:
        return -10000

for i in range(w):
    d_light[-1][i] = count_light(-1, i)
    u_light[0][i] = count_light(0, i)
for j in range(1, h):
    for i in range(w):
        d_light[-(j+1)][i] = max(d_light[-j][i], 0) + count_light(-(j+1), i)
        u_light[j][i] = max(u_light[j-1][i], 0) + count_light(j, i)

for i in range(h):
    l_light[i][0] = count_light(i, 0)
    r_light[i][-1] = count_light(i, -1)
for j in range(1, w):
    for i in range(h):
        l_light[i][j] = max(l_light[i][j-1], 0) + count_light(i, j)
        r_light[i][-(j+1)] = max(r_light[i][-j], 0) + count_light(i, -(j+1))

score = 0
tmp_score = 0
for i in range(h):
    for j in range(w):
        tmp_score = u_light[i][j] + d_light[i][j] + l_light[i][j] + r_light[i][j]
        if tmp_score > score:
            score = tmp_score
print(score-3)

Solution (Python):
h,w = list(map(int, input().split()))
b = [input() + '
b.append('
ans = [[0]*w for _ in range(h)]

for r in range(h):
    c = 0
    while c < w:
        if b[r][c] == '
            c += 1
        else:
            st = c
            while b[r][c] == '.':
                c += 1
            for i in range(st, c):
                ans[r][i] += (c - st)

for c in range(w):
    r = 0
    while r < h:
        if b[r][c] == '
            r += 1
        else:
            st = r
            while b[r][c] == '.':
                r += 1
            for i in range(st, r):
                ans[i][c] += (r - st)

import itertools
print(max(itertools.chain.from_iterable(ans))-1)

Solution (Python):
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy


import heapq
sys.setrecursionlimit(10**6)

INF = 10**18
import bisect
import statistics
mod = 10**9+7


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

a = [[0 for j in range(W)] for i in range(H)]
b = [[0 for j in range(W)] for i in range(H)]

SS = []

for i in range(H):
    S = input() + "
    j = 0
    while j < W:
        if S[j] == "
            a[i][j] = 0
            j += 1
        else:
            count = 0
            k = j
            while S[k] == ".":
                count += 1
                k += 1
            for l in range(count):
                a[i][j+l] = count
            j = j + count
    SS.append(S)

SS.append("

for j in range(W):
    i = 0
    while i < H:
        if SS[i][j] == "
            b[i][j] = 0
            i += 1
        else:
            count = 0
            k = i
            while SS[k][j] == ".":
                count += 1
                k += 1
            for l in range(count):
                b[i+l][j] = count
            i = i + count

ans = 0
for i in range(H):
    for j in range(W):
        if ans < a[i][j] + b[i][j]:
            ans = a[i][j] + b[i][j]
print(ans-1)

Solution (Python):
r, c = map(int, input().split())
ans = 0

map = []
for i in range(r):
    map.append(input())

L = [[0]*c for i in range(r)]
R = [[0]*c for i in range(r)]
D = [[0]*c for i in range(r)]
U = [[0]*c for i in range(r)]

for i in range(r):
    for j in range(c):
        if map[i][j] == ".":
            L[i][j] = L[i][j - 1] + 1
        else:
            L[i][j] = 0
for i in range(r):
    for j in range(c - 1, -1, -1):
        if j == c - 1:
            if map[i][j] == ".":
                R[i][j] = 1
            continue
        if map[i][j] == ".":
            R[i][j] = R[i][j + 1] + 1
        else:
            R[i][j] = 0
for i in range(r):
    for j in range(c):
        if map[i][j] == ".":
            D[i][j] = D[i - 1][j] + 1
        else:
            D[i][j] = 0
for i in range(r - 1, -1, -1):
    for j in range(c):
        if i == r - 1:
            if map[i][j] == ".":
                U[i][j] = 1
            continue
        if map[i][j] == ".":
            U[i][j] = U[i + 1][j] + 1
        else:
            U[i][j] = 0

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

print(ans)

Solution (Python):
import sys
h, w = [int(x) for x in input().split()]
mat = [input() for _ in range(h)]
cnt = [[0] * w for _ in range(h)]
row_obs = [[-1] for _ in range(h)]
col_obs = [[-1] for _ in range(w)]

def main():
    for i, r in enumerate(mat):
        for j, c in enumerate(r):
            if c == '
                row_obs[i].append(j)
                col_obs[j].append(i)
        row_obs[i].append(w)
    for j in range(w):
        col_obs[j].append(h)

    for i in range(h):
        k = 0
        while True:
            prev, nxt = (row_obs[i][k], row_obs[i][k+1])
            for j in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == w:
                break
            k += 1

    for j in range(w):
        k = 0
        while True:
            prev, nxt = (col_obs[j][k], col_obs[j][k+1])
            for i in range(prev+1, nxt):
                    cnt[i][j] += nxt - prev - 1
            if nxt == h:
                break
            k += 1

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)

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

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    H, W = mi()
    S = [input() for i in range(H)]

    left = [[0]*W for _ in range(H)]
    right = [[0]*W for _ in range(H)]
    top = [[0]*W for _ in range(H)]
    bottom = [[0]*W for _ in range(H)]

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

            if j == 0 or S[i][j-1] == '
                left[i][j] = 1
            else:
                left[i][j] = left[i][j-1] + 1

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

            if j == W-1 or S[i][j+1] == '
                right[i][j] = 1
            else:
                right[i][j] = right[i][j+1] + 1

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

            if i == 0 or S[i-1][j] == '
                top[i][j] = 1
            else:
                top[i][j] = top[i-1][j] + 1

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

            if i == H-1 or S[i+1][j] == '
                bottom[i][j] = 1
            else:
                bottom[i][j] = bottom[i+1][j] + 1


    m = -math.inf

    for i in range(H):
        for j in range(W):
            m = max(left[i][j]+right[i][j]+top[i][j]+bottom[i][j]-3, m)

    print(m)



if __name__ == '__main__':
    main()

Solution (Python):

import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    H, W = MI()
    room = [["" for j in range(W)] for i in range(H)]
    roomT = [["" for i in range(H)] for j in range(W)]
    num_yoko = [[0 for j in range(W)] for i in range(H)]
    for i in range(H):
        row = input()

        splited = list(map(len, row.split('
        tmp = 0
        for j in range(W):
            roomT[j][i] = row[j]
            room[i][j] = row[j]
            if row[j] == "
                num_yoko[i][j] = 0
                tmp += 1
            else:
                num_yoko[i][j] = splited[tmp]

    ans = 0

    for j in range(W):
        target = roomT[j]
        splited = list(map(len, "".join(target).split('
        tmp = 0
        for i in range(H):
            num_tate = 0 if target[i] == "
            ans = max(ans,  num_tate + num_yoko[i][j] - 1)
            if target[i] == "
                tmp += 1
    print(ans)


main()

Solution (Python):

import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    H, W = MI()
    room = [["" for j in range(W)] for i in range(H)]
    roomT = [["" for i in range(H)] for j in range(W)]
    num_yoko = [[0 for j in range(W)] for i in range(H)]
    num_tate = [[0 for j in range(W)] for i in range(H)]
    num_sum = [[0 for j in range(W)] for i in range(H)]
    for i in range(H):
        row = input()

        splited = list(map(len, row.split('
        tmp = 0
        for j in range(W):
            roomT[j][i] = row[j]
            room[i][j] = row[j]
            if row[j] == "
                num_yoko[i][j] = 0
                tmp += 1
            else:
                num_yoko[i][j] = splited[tmp]

    ans = 0

    for j in range(W):
        target = roomT[j]
        splited = list(map(len, "".join(target).split('
        tmp = 0
        for i in range(H):
            if target[i] == "
                num_tate[i][j] == 0
                tmp += 1
            else:
                num_tate[i][j] = splited[tmp]

            num_sum[i][j] = num_tate[i][j] + num_yoko[i][j] - 1
            ans = max(ans, num_sum[i][j])
    print(ans)


main()

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

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





H, W = getNM()
maze = [input() for i in range(H)]

dp_row = [[-1] * W for i in range(H)]
dp_col = [[-1] * W for i in range(H)]


def dfs_row(y, x):
    if dp_row[y][x] >= 0:
        return dp_row[y][x]

    if maze[y][x] == '
        return 0

    res = 1
    nx = x + 1
    if 0 <= nx < W and maze[y][nx] == '.':
        res += dfs_row(y, nx)
    dp_row[y][x] = res
    return res

for i in range(H):
    for j in range(W):
        dfs_row(i, j)
    cnt = 0
    for j in range(1, W):
        if dp_row[i][j] >= 0 and dp_row[i][j - 1] >= 0:
            dp_row[i][j] = dp_row[i][j - 1]


def dfs_col(y, x):
    if dp_col[y][x] >= 0:
        return dp_col[y][x]

    if maze[y][x] == '
        return 0

    res = 1
    ny = y + 1
    if 0 <= ny < H and maze[ny][x] == '.':
        res += dfs_col(ny, x)
    dp_col[y][x] = res
    return res

for i in range(H):
    for j in range(W):
        dfs_col(i, j)

for i in range(1, H):
    for j in range(W):
        if dp_col[i][j] >= 0 and dp_col[i - 1][j] >= 0:
            dp_col[i][j] = dp_col[i - 1][j]

ans = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '.':
            ans = max(ans, dp_row[i][j] + dp_col[i][j] - 1)
print(ans)

Solution (Python):
h, w = map(int, input().split())
tizu = [input() for _ in range(h)]
check = [[False for _ in range(w)] for _ in range(h)]
ans = [[1 for _ in range(w)] for _ in range(h)]

for i in range(h):
    for j in range(w):
        if check[i][j]:
            continue
        if tizu[i][j] == "
            continue
        pos = [i]
        cnt = 0
        for k in range(i + 1, h):
            if tizu[k][j] == "
                break
            pos.append(k)
            cnt += 1
        for k in range(i - 1, -1, -1):
            if tizu[k][j] == "
                break
            pos.append(k)
            cnt += 1
        for l in pos:
            ans[l][j] += cnt
            check[l][j] = True

check = [[False for _ in range(w)] for _ in range(h)]
max_ans = 0
for i in range(h):
    for j in range(w):
        if check[i][j]:
            continue
        if tizu[i][j] == "
            continue
        pos = [j]
        cnt = 0
        for k in range(j + 1, w):
            if tizu[i][k] == "
                break
            pos.append(k)
            cnt += 1
        for k in range(j - 1, -1, -1):
            if tizu[i][k] == "
                break
            pos.append(k)
            cnt += 1
        for l in pos:
            ans[i][l] += cnt
            check[i][l] = True
            max_ans = max(max_ans, ans[i][l])
print(max_ans)

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

Solution (Python):
from itertools import chain
H, W = map(int, input().split())
S = [input()+"
S.append("
A = [[0]*(W) for _ in range(H)]

for i in range(H):
    tmp = 0
    stack = []
    for j in range(W+1):
        if S[i][j] == ".":
            tmp += 1
            stack.append(j)
        
        
        
        
            
        
        
        
        
        else:
            while stack:
                tmp_j = stack.pop()
                A[i][tmp_j] += tmp
            tmp = 0
for j in range(W):
    tmp = 0
    stack = []
    for i in range(H+1):
        if S[i][j] == ".":
            tmp += 1
            stack.append(i)
        
        
        
        
        
        
        
        
        else:
            while stack:
                tmp_i = stack.pop()
                A[tmp_i][j] += tmp
            tmp = 0
ans = max(chain.from_iterable(A))-1
print(ans)

Solution (Python):
from itertools import chain
H, W = map(int, input().split())
S = [input() for _ in range(H)]
A = [[0]*(W) for _ in range(H)]

for i in range(H):
    tmp = 0
    stack = []
    for j in range(W):
        if S[i][j] == "." and j < W-1:
            tmp += 1
            stack.append(j)
        elif j == W-1:
            if S[i][j] == ".":
                tmp += 1
                stack.append(j)
            
            while stack:
                tmp_j = stack.pop()
                A[i][tmp_j] += tmp
            tmp = 0
        else:
            while stack:
                tmp_j = stack.pop()
                A[i][tmp_j] += tmp
            tmp = 0
for j in range(W):
    tmp = 0
    stack = []
    for i in range(H):
        if S[i][j] == "." and i < H-1:
            tmp += 1
            stack.append(i)
        elif i == H-1:
            if S[i][j] == ".":
                tmp += 1
                stack.append(i)
            while stack:
                tmp_i = stack.pop()
                A[tmp_i][j] += tmp
            tmp = 0
        else:
            while stack:
                tmp_i = stack.pop()
                A[tmp_i][j] += tmp
            tmp = 0
ans = max(chain.from_iterable(A))-1
print(ans)