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
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

h, w = na()
s = nsn(h)

l = [[0] * w for _ in range(h)]
r = [[0] * w for _ in range(h)]
u = [[0] * w for _ in range(h)]
d = [[0] * w for _ in range(h)]

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

for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if s[i][j] == '
            r[i][j] = 0
            d[i][j] = 0
        else:
            if j == w - 1:
                r[i][j] = 1
            else:
                r[i][j] = r[i][j + 1] + 1
            
            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):
        ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3)

print(ans)

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


def main():
    H, W = map(int, input().split())
    S = [[s for s in input()] for _ in range(H)]

    hori = [[0 for _ in range(W)] for _ in range(H)]
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][j] == '.':
                cnt += 1
                hori[i][j] = cnt
            else:
                cnt = 0
        res = 0
        for j in range(W - 1, -1, -1):
            if S[i][j] == '.':
                res = max(res, hori[i][j])
                hori[i][j] = res
            else:
                res = 0

    vert = [[0 for _ in range(W)] for _ in range(H)]
    for i in range(W):
        cnt = 0
        for j in range(H):
            if S[j][i] == '.':
                cnt += 1
                vert[j][i] = cnt
            else:
                cnt = 0
        res = 0
        for j in range(H - 1, -1, -1):
            if S[j][i] == '.':
                res = max(res, vert[j][i])
                vert[j][i] = res
            else:
                res = 0

    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                ans = max(ans, hori[i][j] + vert[i][j] - 1)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

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)

Solution (Python):
h,w = map(int,input().split())
grid = []
grid_num1 = []
grid_num2 = []
for i in range(h):
    lst = list(input())
    lst.append("
    grid.append(lst)
    grid_num1.append([0]*w)
grid.append(["
for j in range(w):
    grid_num2.append([0]*h)

grid_t = [list(x) for x in zip(*grid)]

for i in range(h):
    sw = []
    tar_row = grid[i]
    for j in range(w+1):
        if j == 0 and tar_row[j] == ".":
            sw.append(j)
        elif tar_row[j] == "." and tar_row[j-1] == "
            sw.append(j)
        elif tar_row[j] == "
            sw.append(j)
    for j in range(0,len(sw),2):
        l = sw[j]
        r = sw[j+1]
        for k in range(l, r):
            grid_num1[i][k] += r-l

for i in range(w):
    sw = []
    tar_row = grid_t[i]
    for j in range(h+1):
        if j == 0 and tar_row[j] == ".":
            sw.append(j)
        elif tar_row[j] == "." and tar_row[j-1] == "
            sw.append(j)
        elif tar_row[j] == "
            sw.append(j)
    for j in range(0,len(sw),2):
        l = sw[j]
        r = sw[j+1]
        for k in range(l, r):
            grid_num2[i][k] += r-l


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

Solution (Python):
h,w = map(int,input().split())
grid = []
grid_num1 = []
grid_num2 = []
for i in range(h):
    lst = list(input())
    lst.append("
    grid.append(lst)
    grid_num1.append([0]*w)
grid.append(["
for j in range(w):
    grid_num2.append([0]*h)

grid_t = [list(x) for x in zip(*grid)]

for i in range(h):
    sw = []
    tar_row = grid[i]
    for j in range(w+1):
        if j == 0 and tar_row[j] == ".":
            sw.append(j)
        elif tar_row[j] == "." and tar_row[j-1] == "
            sw.append(j)
        elif tar_row[j] == "
            sw.append(j)
    for j in range(0,len(sw),2):
        l = sw[j]
        r = sw[j+1]
        for k in range(l, r):
            grid_num1[i][k] += r-l

for i in range(w):
    sw = []
    tar_row = grid_t[i]
    for j in range(h+1):
        if j == 0 and tar_row[j] == ".":
            sw.append(j)
        elif tar_row[j] == "." and tar_row[j-1] == "
            sw.append(j)
        elif tar_row[j] == "
            sw.append(j)
    for j in range(0,len(sw),2):
        l = sw[j]
        r = sw[j+1]
        for k in range(l, r):
            grid_num2[i][k] += r-l
grid_num2 = [list(x) for x in zip(*grid_num2)]

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

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

l = [[0] * w for _ in range(h)]
r = [[0] * w for _ in range(h)]
u = [[0] * w for _ in range(h)]
d = [[0] * w for _ in range(h)]

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

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

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

for i in range(h-1, -1 ,-1):
    for j in range(w):
        if s[i][j] == '
            d[i][j] = 0
        else:
            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):
        ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3)

print(ans)

Solution (Python):
h,w = map(int,input().split())
c = [[] for i in range(h)]
d = [[1]*w for _ in range(h)]
e = [[1]*w for _ in range(h)]
for i in range(h):
    c[i] = input()
    if c[i][0] == "
        d[i][0] = 0
for i in range(w):
    if c[0][i] == "
        e[0][i] = 0
    
for i in range(h):
    for j in range(w-1):
        if c[i][j+1] == "
            d[i][j+1] = 0
        else:
            d[i][j+1] = d[i][j] + 1
            
for i in range(h-1):
    for j in range(w):
        if c[i+1][j] == "
            e[i+1][j] = 0
        else:
            e[i+1][j] = e[i][j] + 1
            
for i in range(h):
    for j in range(w-2,-1,-1):
        if d[i][j] != 0 and d[i][j+1] != 0:
            d[i][j] = d[i][j+1]
        elif d[i][j] != 0 and d[i][j+1] == 0:
            continue
        else:
            d[i][j] = 0
            
for i in range(h-2,-1,-1):
    for j in range(w):
        if e[i][j] != 0 and e[i+1][j] != 0:
            e[i][j] = e[i+1][j]
        elif e[i][j] != 0 and e[i+1][j] == 0:
            continue
        else:
            e[i][j] = 0
            
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans , d[i][j]+e[i][j])
        
print(ans-1)

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

result = [[0]*W for _ in range(H)]
for i in range(H):
    c = 0
    start = 0
    for j in range(W):
        if T[i][j] == "
            for k in range(start,j):
                result[i][k] += c
            start = j + 1
            c = 0
        elif j == W-1:
            c += 1
            for k in range(start,j+1):
                result[i][k] += c
        else:
            c += 1

for i in range(W):
    c = 0
    start = 0
    for j in range(H):
        if T[j][i] == "
            for k in range(start,j):
                result[k][i] += c
            start = j + 1
            c = 0
        elif j == H-1:
            c += 1
            for k in range(start,j+1):
                result[k][i] += c
        else:
            c += 1

ans = 0
for i in range(H):
    for j in range(W):
        if T[i][j] == ".":
            ans = max(ans,result[i][j]-1)
        else:
            ans = max(ans,result[i][j])
print(ans)

Solution (Python):
def main():
    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        s = list(input())
        S.append(s)
    R = [[0]*W for _ in range(H)]
    L = [[0]*W for _ in range(H)]
    U = [[0]*W for _ in range(H)]
    D = [[0]*W for _ in range(H)]
    for i in range(H):
        cnt1 = 0
        cnt2 = 0
        for j in range(W):
            if S[i][j]=='
                cnt1 = 0
            else:
                cnt1 += 1
                L[i][j] = cnt1
        for j in range(W-1, -1, -1):
            if S[i][j]=='
                cnt2 = 0
            else:
                cnt2 += 1
                R[i][j] = cnt2

    for j in range(W):
        cnt1 = 0
        cnt2 = 0
        for i in range(H):
            if S[i][j]=='
                cnt1 = 0
            else:
                cnt1 += 1
                U[i][j] = cnt1
        for i in range(H-1,-1,-1):
            if S[i][j]=='
                cnt2 = 0
            else:
                cnt2 += 1
                D[i][j] = cnt2

    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)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        s = list(input())
        S.append(s)
    R = [[0]*W for _ in range(H)]
    L = [[0]*W for _ in range(H)]
    U = [[0]*W for _ in range(H)]
    D = [[0]*W for _ in range(H)]
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][j]=='
                cnt = 0
            else:
                cnt += 1
                L[i][j] = cnt
    for i in range(H):
        cnt = 0
        for j in range(W-1, -1, -1):
            if S[i][j]=='
                cnt = 0
            else:
                cnt += 1
                R[i][j] = cnt
    for j in range(W):
        cnt = 0
        for i in range(H):
            if S[i][j]=='
                cnt = 0
            else:
                cnt += 1
                U[i][j] = cnt
    for j in range(W):
        cnt = 0
        for i in range(H-1,-1,-1):
            if S[i][j]=='
                cnt = 0
            else:
                cnt += 1
                D[i][j] = cnt
    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)


if __name__ == '__main__':
    main()

Solution (Python):

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


L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
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] == ".":
			if j == 0:
				L[i][j] = 1
			else:
				L[i][j] = L[i][j - 1] + 1
                

for i in range(H):
	for j in range(W - 1, -1, -1):
		if S[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 - 1, -1, -1):
		if S[i][j] == ".":
			if i == H - 1:
				D[i][j] = 1
			else:
				D[i][j] = D[i + 1][j] + 1

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


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

print(ans)

Solution (Python):
def solve():
    H, W = map(int, input().split())
    Sss = ['

    numLss = [[0]*(W+2) for _ in range(H+2)]
    numRss = [[0]*(W+2) for _ in range(H+2)]
    numUss = [[0]*(W+2) for _ in range(H+2)]
    numDss = [[0]*(W+2) for _ in range(H+2)]
    for i in range(1, H+1):
        for j in range(1, W+1):
            if Sss[i][j] == '.':
                numLss[i][j] = numLss[i][j-1] + 1
        for j in reversed(range(1, W+1)):
            if Sss[i][j] == '.':
                numRss[i][j] = numRss[i][j+1] + 1
    for j in range(1, W+1):
        for i in range(1, H+1):
            if Sss[i][j] == '.':
                numUss[i][j] = numUss[i-1][j] + 1
        for i in reversed(range(1, H+1)):
            if Sss[i][j] == '.':
                numDss[i][j] = numDss[i+1][j] + 1

    ans = 0
    for i in range(1, H+1):
        for j in range(1, W+1):
            num = numLss[i][j] + numRss[i][j] + numUss[i][j] + numDss[i][j] - 3
            ans = max(ans, num)

    print(ans)


solve()

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

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

U = [[0 for _ in range(w)] for _  in range(h)]
D = [[0 for _ in range(w)] for _  in range(h)]
L = [[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 maps[y][x] == "
            U[y][x],L[y][x] = 0,0
        else:
            if y == 0 and x >= 1:
                U[0][x] = 1
                L[y][x] += 1 + L[y][x-1]
            elif x == 0 and y >= 1: 
                U[y][x] += 1 + U[y-1][x]
                L[y][0] = 1
            elif x == 0 and y == 0:
                U[y][x] = 1
                L[y][x] = 1
            else:
                U[y][x] += 1 + U[y-1][x]
                L[y][x] += 1 + L[y][x-1]

for y in range(h-1,-1,-1):
    for x in range(w-1,-1,-1):
        if maps[y][x] == "
            D[y][x],R[y][x] = 0,0
        else:
            if y == h-1 and x < w-1:
                D[y][x] = 1
                R[y][x] += 1 + R[y][x+1]
            elif x == w-1 and y < h-1:
                D[y][x] += 1 + D[y+1][x]
                R[y][x] = 1
            elif  x == w-1 and y == h-1:
                D[y][x] = 1
                R[y][x] = 1
            else:
                D[y][x] += 1 + D[y+1][x]
                R[y][x] += 1 + R[y][x+1]

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

Solution (Python):
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
s = [[0]*w for i in range(h)]
for i in range(h):
    count = 0
    for j in range(w):
        if (a[i][j]=='.'):
            count += 1
            
        else:
            for k in range(j-1,j-count-1,-1):
                s[i][k]=count
            count = 0
    for k in range(w-1,w-count-1,-1):
        s[i][k]=count
    count = 0

t = [[0]*w for i in range(h)]
for i in range(w):
    count = 0
    for j in range(h):
        if (a[j][i]=='.'):
            count += 1
            
        else:
            for k in range(j-1,j-count-1,-1):
                t[k][i]=count
            count = 0
    for k in range(h-1,h-count-1,-1):
        t[k][i]=count
    count = 0

ans = 0
for i in range(h):
    for j in range(w):
        if (s[i][j]!=0):
            if (s[i][j]+t[i][j]-1 > ans):
                ans = s[i][j]+t[i][j]-1
print(ans)

Solution (Python):
import numpy as np
h,w = map(int,input().split())
ar = 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):
  u[i] = (u[i-1]+1)*ar[i]
  
  d[-i-1] = (d[-i]+1)*ar[-i-1]
  
  
for j in range(w):
  l[:,j] = (l[:,j-1]+1)*ar[:,j]
  
  r[:,-j-1] = (r[:,-j]+1)*ar[:,-j-1]
  
print(np.max(u+d+l+r)-3)

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

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():
  x = map.copy()
  for row in range(1,H+1):
    zero_idx = np.nonzero(x[row]==0)[0]
    x[row, zero_idx[1:]] = 1-np.diff(zero_idx) 
  x = x.cumsum(axis = 1)
  return x


def G():
  x = map.T.copy()
  for row in range(1,W+1):
    zero_idx = np.nonzero(x[row]==0)[0]
    x[row, zero_idx[1:]] = 1-np.diff(zero_idx) 
  x = x.cumsum(axis = 1)
  return x.T

answer = np.zeros_like(map)

answer += F()

map = map[:,::-1]
answer += F()[:,::-1]
map = map[:,::-1]


answer += G()

map = map[::-1,:]
answer += G()[::-1,:]

answer = np.max(answer) - 3
print(answer)

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():
  x = map.copy()
  for row in range(1,H+1):
    zero_idx = np.nonzero(x[row]==0)[0]
    x[row, zero_idx[1:]] = 1-np.diff(zero_idx) 
  x = x.cumsum(axis = 1)
  return x


def G():
  x = map.T.copy()
  for row in range(1,W+1):
    zero_idx = np.nonzero(x[row]==0)[0]
    x[row, zero_idx[1:]] = 1-np.diff(zero_idx) 
  x = x.cumsum(axis = 1)
  return x.T

answer = np.zeros_like(map)

answer += F()

map = map[:,::-1]
answer += F()[:,::-1]
map = map[:,::-1]


answer += G()

map = map[::-1,:]
answer += G()[::-1,:]

answer = np.max(answer) - 3
print(answer)

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

ans=0
tate=[]

for i in range(W):
    c=0
    ad=[]
    while(c<H):
        ad.append(S[c][i])
        c+=1
    tate.append(ad)

left=[]
right=[]
up=[]
down=[]

for i in range(H):
    tmp=S[i]
    cnt=0
    al = [0 for _ in range(W)]
    for j in range(W):
        if tmp[j]==".":
            cnt+=1
            al[j]=cnt
        else:
            cnt=0
    left.append(al)

for i in range(H):
    tmp = S[i]
    tmp=tmp[::-1]
    cnt = 0
    ar = [0 for _ in range(W)]
    for j in range(W):
        if tmp[j] == ".":
            cnt += 1
            ar[j] = cnt
        else:
            cnt = 0
    ar=ar[::-1]
    right.append(ar)

for j in range(W):
    tt=tate[j]
    cnt=0
    bl=[0 for i in range(H)]
    for k in range(H):
        if tt[k]==".":
            cnt+=1
            bl[k]=cnt
        else:
            cnt=0
    up.append(bl)

for j in range(W):
    tt=tate[j]
    tt=tt[::-1]
    cnt=0
    br=[0 for i in range(H)]
    for k in range(H):
        if tt[k]==".":
            cnt+=1
            br[k]=cnt
        else:
            cnt=0
    br=br[::-1]
    down.append(br)

for i in range(H):
    for j in range(W):
        gh=left[i][j]+right[i][j]+up[j][i]+down[j][i]-3
        ans=max(gh,ans)

print(ans)

Solution (Python):

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


L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
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] == ".":
			if j == 0:
				L[i][j] = 1
			else:
				L[i][j] = L[i][j - 1] + 1

for i in range(H):
	for j in range(W - 1, -1, -1):
		if S[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 - 1, -1, -1):
		if S[i][j] == ".":
			if i == H - 1:
				D[i][j] = 1
			else:
				D[i][j] = D[i + 1][j] + 1

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


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

print(ans)

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

Solution (Python):
H,W = map(int, input().split())
grid = []
for i in range(H):
    grid.append(input())
horiz = [[None]*W for _ in range(H)]
horiv = [[] for _ in range(H)]
for i in range(H):
    cur = 0
    for j in range(W):
        if grid[i][j] == '.':
            horiz[i][j] = len(horiv[i])
        else:
            horiv[i].append(j - cur)
            cur = j + 1
    horiv[i].append(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, horiv[r][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)

Solution (Python):
"""
参考
blog名  ベスパリブ    
URL     https://takeg.hatenadiary.jp/entry/2019/09/10/234417
id:     takeg
"""

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)

Solution (Python):

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)

Solution (Python):
def main():
    h, w = [int(e) for e in input().split()]
    S = [input() for i in range(h)]

    L = [[0] * (w + 2) for i in range(h + 2)]
    R = [[0] * (w + 2) for i in range(h + 2)]
    T = [[0] * (w + 2) for i in range(h + 2)]
    B = [[0] * (w + 2) for i in range(h + 2)]
    for hi in range(1, h + 1):
        for wi in range(1, w + 1):
            if S[hi - 1][wi - 1] == '.':
                L[hi][wi] = L[hi][wi - 1] + 1
                T[hi][wi] = T[hi - 1][wi] + 1

            if S[hi - 1][-wi] == '.':
                R[hi][-wi - 1] = R[hi][-wi] + 1

            if S[-hi][wi - 1] == '.':
                B[-hi - 1][wi] = B[-hi][wi] + 1

    ans = 0
    for hi in range(1, h + 1):
        for wi in range(1, w + 1):
            ans = max(L[hi][wi] + R[hi][wi] + T[hi][wi] + B[hi][wi] - 3, ans)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
H,W=map(int,input().split())
S=[[i for i in list(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):
    count=0
    for j in range(W):
        if S[i][j]=="
            count=0
        else:
            count=count+1
        L[i][j]=count
for i in range(H):
    count=0
    for j in range(W)[::-1]:
        if S[i][j]=="
            count=0
        else:
            count=count+1
        R[i][j]=count
for i in range(W):
    count=0
    for j in range(H):
        if S[j][i]=="
            count=0
        else:
            count=count+1
        U[j][i]=count
for i in range(W):
    count=0
    for j in range(H)[::-1]:
        if S[j][i]=="
            count=0
        else:
            count=count+1
        D[j][i]=count
ans=0
for i in range(H):
    for j in range(W):
        ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)

Solution (Python):
h, w = map(int, input().rsplit())
S = [list(input().rstrip()) for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if S[i][j] == ".":
                L[i][j] = 1
            continue
        if S[i][j] == "
            continue
        else:
            L[i][j] += 1 + L[i][j - 1]
for i in range(h):
    for j in range(w):
        if i == 0:
            if S[i][j] == ".":
                U[i][j] = 1
            continue
        if S[i][j] == "
            continue
        else:
            U[i][j] += 1 + U[i - 1][j]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if j == w - 1:
            if S[i][j] == ".":
                R[i][j] = 1
            continue
        if S[i][j] == "
            continue
        else:
            R[i][j] += 1 + R[i][j + 1]
for i in range(h - 1, -1, -1):
    for j in range(w - 1, -1, -1):
        if i == h - 1:
            if S[i][j] == ".":
                D[i][j] = 1
            continue
        if S[i][j] == "
            continue
        else:
            D[i][j] += 1 + D[i + 1][j]
ans = 0
for i in range(h):
    for j in range(w):
        temp = D[i][j] + U[i][j] + L[i][j] + R[i][j] - 3
        ans = max(temp, ans)
print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]

    left = [[0] * W for _ in range(H)]
    right = [[0] * W for _ in range(H)]
    up = [[0] * W for _ in range(H)]
    down = [[0] * W for _ in range(H)]

    for h in range(H):
        cnt = 0
        for w in range(W):
            if maze[h][w] == "
                cnt = 0
            else:
                cnt += 1
                left[h][w] = cnt

    for h in range(H):
        cnt = 0
        for w in range(W - 1, -1, -1):
            if maze[h][w] == "
                cnt = 0
            else:
                cnt += 1
                right[h][w] = cnt

    for w in range(W):
        cnt = 0
        for h in range(H):
            if maze[h][w] == "
                cnt = 0
            else:
                cnt += 1
                up[h][w] = cnt

    for w in range(W):
        cnt = 0
        for h in range(H - 1, -1, -1):
            if maze[h][w] == "
                cnt = 0
            else:
                cnt += 1
                down[h][w] = cnt

    ans = 0
    for h in range(H):
        for w in range(W):
            tmp = up[h][w] + down[h][w] + left[h][w] + right[h][w] - 3
            if tmp > ans:
                ans = tmp

    print(ans)


if __name__ == "__main__":
    main()