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

Solution (Python):
h,w=map(int,input().split())
s=[]
l=[[0 for i in range(w)]for j in range(h)]
 
for i in range(h):
    a=input()
    s.append(a)

yoko=[[0 for j in range(w)] for j in range(h)]
tate=[[0 for j in range(w)] for j in range(h)]

for i in range(h):
    p=0
    for j in range(w):
        if s[i][j]=="
            if s[i][j]==".":
                for k in range(p):
                    yoko[i][j-k-1]+=p+1
                yoko[i][j]+=p+1
            else:
                for k in range(p):
                    yoko[i][j-k-1]+=p
            p=0
        elif s[i][j]==".":
            p+=1
for i in range(w):
    p=0
    for j in range(h):
        if s[j][i]=="
            if s[j][i]==".":
                for k in range(p):
                    tate[j-k-1][i]+=p+1
                yoko[j][i]+=p+1
            else:
                for k in range(p):
                    tate[j-k-1][i]+=p
            p=0
        elif s[j][i]==".":
            p+=1
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,yoko[i][j]+tate[i][j]-1)

print(ans)

Solution (Python):

H, W = map(int, input().split())    
S_arr = []
for _ in range(H):
    S_arr.append(list(input()))

point_arr = [[0]*W for _ in range(H)]

start = 0
stop = W
for y in range(H):
    start = 0
    stop = W
    for x in range(W):
        if S_arr[y][x] == "
            stop = x
            for i in range(start, stop):
                point_arr[y][i] += stop - start
            start = stop + 1
    for i in range(start, W):
        point_arr[y][i] += W - start


for x in range(W):  
    start = 0
    stop = H
    for y in range(H):
        if S_arr[y][x] == "
            stop = y
            for i in range(start, stop):
                point_arr[i][x] += stop - start
            start = stop + 1
    for i in range(start, H):
        point_arr[i][x] += H - start

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

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

light_space = [[1 for i in range(w)] for j in range(h)]
max_light = 0
for i in range(w):
    light = -1
    light_right = -1
    for j in range(h):
        low_point = len(space)-j-1

        if space[j][i] == "
            light = -1
            light_space[j][i] = 0
        else:
            light += 1
            light_space[j][i] += light

        if space[low_point][i] == "
            light_right = -1
            light_space[low_point][i] = 0
        else:
            light_right += 1
            light_space[low_point][i] += light_right

for j in range(h):
    light = -1
    light_right = -1
    for i in range(w):
        right_point = len(space[j])-i-1

        if space[j][i] == "
            light = -1
            light_space[j][i] = 0
        else:
            light += 1
            light_space[j][i] += light
        
        if space[j][right_point] == "
            light_right = -1
            light_space[j][right_point] = 0
        else:
            light_right += 1
            light_space[j][right_point] += light_right

        max_light = max(max_light,light_space[j][right_point],light_space[j][i])


print(max_light)

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
import sys


def get_data(stream):
    buf = b''
    b = stream.buffer.read(1)
    while b != b'\n':
        buf += b
        b = stream.buffer.read(1)
    H, W = map(int, buf.split())
    c = stream.buffer.read(H * (W + 1))
    arr = np.array(c.split())
    arr = np.frombuffer(arr, dtype='S1').reshape((H, W))
    return H, W, arr


def main():
    H, W, arr = get_data(sys.stdin)
    a = arr == b'.'
    L = np.empty((H, W), dtype='i8')
    R = np.empty((H, W), dtype='i8')
    T = np.empty((H, W), dtype='i8')
    B = np.empty((H, W), dtype='i8')
    T[0] = a[0]
    for i in range(1, H):
        T[i] = (T[i - 1] + 1) * a[i]
    B[-1] = a[-1]
    for i in range(H - 2, -1, -1):
        B[i] = (B[i + 1] + 1) * a[i]
    L[:, 0] = a[:, 0]
    for i in range(1, W):
        L[:, i] = (L[:, i - 1] + 1) * a[:, i]
    R[:, -1] = a[:, -1]
    for i in range(W - 2, -1, -1):
        R[:, i] = (R[:, i + 1] + 1) * a[:, i]

    print((T + B + L + R - 3).max())


if __name__ == "__main__":
    main()

Solution (Python):
from numpy import*
h,*s=open(0)
h,w=int32(h.split())
s=int32([[u>'
a,b,c,d=eval('copy(s),'*4)
for i in range(1,h+w):
 if i<w:a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
 if i<h:c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(amax(a+b+c+d)-3)

Solution (Python):
from numpy import*
h,*s=open(0)
h,w=int32(h.split())
s=int32([[u>'
a,b,c,d=eval('copy(s),'*4)
for i in range(w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in range(1,h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(amax(a+b+c+d)-3)

Solution (Python):
from numpy import*
h,*s=open(0)
h,w=int32(h.split())
r=range
s=int32([[u>'
a,b,c,d=eval('copy(s),'*4)
for i in r(w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in r(1,h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(int((a+b+c+d).max())-3)

Solution (Python):
from numpy import*
h,*s=open(0)
h,w=int64(h.split())
r=range
s=int32([[u>'
a,b,c,d=eval('copy(s),'*4)
for i in r(1,w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in r(1,h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(int((a+b+c+d).max())-3)

Solution (Python):
from numpy import*
h,*s=open(0)
h,w=int64(h.split())
r=range
s=int32([[u>'
a,b,c,d=eval('s.copy(),'*4)
for i in r(1,w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in r(1,h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(int((a+b+c+d).max())-3)

Solution (Python):
from numpy import*
h,*s=open(0)
h,w=int64(h.split())
r=range
s=int64([[u>'
a,b,c,d=eval('zeros((h,w),"i"),'*4)
for i in r(w):a[:,i],b[:,~i]=-~a[:,i-1]*s[:,i],-~b[:,-i]*s[:,~i]
for i in r(h):c[i,:],d[~i,:]=-~c[i-1,:]*s[i,:],-~d[-i,:]*s[~i,:]
print(int((a+b+c+d).max())-3)

Solution (Python):
from numpy import*
h,*s=open(0)
h,w=int64(h.split())
r=range
s=array([list(t[:-1])for t in s])
a,b,c,d=eval('zeros((h,w),"i"),'*4)
for i in r(w):
    a[:,i]=-~a[:,i-1]*(s[:,i]>'
    b[:,~i]=-~b[:,-i]*(s[:,~i]>'
for i in r(h):
    c[i,:]=-~c[i-1,:]*(s[i,:]>'
    d[~i,:]=-~d[-i,:]*(s[~i,:]>'
print(int((a+b+c+d).max())-3)

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

Solution (Python):


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


H, W = map(int, input().split())
field = []    

for i in range(H):
    field.append(list(input()) + ['
field.append(['

ans = 0

beam_h = [[0] * W for _ in range(H)]
for h in range(H):
    l = 0
    r = 0
    while r < W + 1:
        num = 0
        while field[h][r] == '.':
            r += 1
            num += 1
        if l != r:
            beam_h[h][l:r] = [num] * num
            ans = max(ans, num)
            l = r
        l += 1
        r += 1

beam_w = [[0] * W for _ in range(H)]
for w in range(W):
    l = 0
    r = 0
    while r < H + 1:
        num = 0
        while field[r][w] == '.':
            r += 1
            num += 1
        if l != r:
            
            for i in range(l, r):
                beam_w[i][w] = num
                ans = max(ans, beam_w[i][w] + beam_h[i][w] - 1)
            l = r
        l += 1
        r += 1

print(ans)

Solution (Python):
H,W=map(int,input().split())
S=list(list(input()) for _ in range(H))
ans=0
for i in S:
    for j in range(W):
        if i[j]!='
            ans+=1
        elif i[j]!='
            for k in range(ans+1):
                i[j-k]=ans+1
            ans=0
        else:
            for k in range(1,ans+1):
                i[j-k]=ans
            ans=0
S_t=list(map(list,zip(*S)))
ans=0
for i in S_t:
    for j in range(H):
        if i[j]!='
            ans+=1
        elif i[j]!='
            for k in range(ans+1):
                i[j-k]+=ans+1
            ans=0
        else:
            for k in range(1,ans+1):
                i[j-k]+=ans
            ans=0
            i[j]=0
c=0
for i in S_t:
    c=max(c,max(i))
print(c-1)

Solution (Python):
class UnionFind:
    def __init__(self, n):
        self.v = [-1 for _ in range(n)]  

    def find(self, x):  
        if self.v[x] < 0:  
            return x
        else:  
            self.v[x] = self.find(self.v[x])  
            return self.v[x]

    def unite(self, x, y):  
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if -self.v[x] < -self.v[y]:  
            x, y = y, x  
        self.v[x] += self.v[y]  
        self.v[y] = x  

    def root(self, x):
        return self.v[x] < 0  

    def same(self, x, y):
        return self.find(x) == self.find(y)  

    def size(self, x):
        return -self.v[self.find(x)]  


import sys

input = sys.stdin.readline

H, W = map(int, input().split())
s = tuple(input() for _ in range(H))

uf_r = UnionFind(H * W)
for r in range(H - 1):
    for c in range(W):
        if s[r][c] == '.' and s[r + 1][c] == '.':
            uf_r.unite(r * W + c, (r + 1) * W + c)

uf_c = UnionFind(H * W)
for c in range(W - 1):
    for r in range(H):
        if s[r][c] == '.' and s[r][c + 1] == '.':
            uf_c.unite(r * W + c, r * W + (c + 1))

ans = 0
for r in range(H):
    for c in range(W):
        if s[r][c] == '
        t = uf_r.size(r * W + c) + uf_c.size(r * W + c) - 1
        ans = max(ans, t)
print(ans)

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

from itertools import accumulate

rxs = []

for row in S:
    si = -1
    xs = [0] * (W + 1)
    for i in range(W + 1):
        if row[i] == "
            xs[si + 1] += (i - si - 1)
            xs[i] -= (i - si - 1)
            si = i
    rxs.append(list(accumulate(xs)))

sxs = []


for row in zip(*S):
    si = -1
    xs = [0] * (H + 1)
    for i in range(H + 1):
        if row[i] == "
            xs[si + 1] += (i - si - 1)
            xs[i] -= (i - si - 1)
            si = i
    sxs.append(list(accumulate(xs)))

result = 0

for r1, r2 in zip(rxs, zip(*sxs)):
    r = max(c1 + c2 for c1, c2 in zip(r1, r2)) - 1
    result = max(result, r)

print(result)

Solution (Python):
if __name__ == '__main__':
    h,w = list(map(int, input().split()))
    s = []
    for i in range(h):
        s.append(input())
    
    yoko = [[0 for i in range(w)] for j in range(h)]
    tate = [[0 for i in range(w)] for j in range(h)]
 
    for i in range(h):
        index = 0
        while(index < w):
            count = 0
            for j in range(index, w):
                if(s[i][j] == "
                    break
                count += 1
            
            if(count == 0):
                yoko[i][index] = 0
                index += 1
 
            else:
                for j in range(index, index + count):
                    yoko[i][j] = count
                index += count
 
    for i in range(w):
        index = 0
        while(index < h):
            count = 0
            for j in range(index, h):
                if(s[j][i] == "
                    break
                count += 1
            
            if(count == 0):
                tate[index][i] = 0
                index += 1
 
            else:
                for j in range(index, index + count):
                    tate[j][i] = count
                index += count
 
    result = 0
 
    for i in range(h):
        for j in range(w):
            result = max(result, yoko[i][j] + tate[i][j] - 1)
 
 
    print(result)

Solution (Python):
if __name__ == '__main__':
    h,w = list(map(int, input().split()))
    s = []
    for i in range(h):
        s.append(input())
    
    l = [[0 for i in range(w)] for j in range(h)]
    r = [[0 for i in range(w)] for j in range(h)]
    u = [[0 for i in range(w)] for j in range(h)]
    d = [[0 for i in range(w)] for j in range(h)]

    for i in range(h):
        for j in range(0, w):
            if(s[i][j] == "
                l[i][j] = 0
            elif(j == 0):
                l[i][j] = 1
            else:
                l[i][j] = l[i][j-1] + 1
            
            tw = w-j-1
            if(s[i][tw] == "
                r[i][tw] = 0
            elif(j == 0):
                r[i][tw] = 1
            else:
                r[i][tw] = r[i][tw+1] + 1
            
            if(s[i][j] == "
                u[i][j] = 0
            elif(i == 0):
                u[i][j] = 1
            else:
                u[i][j] = u[i-1][j] + 1
                
            th = h-i-1
            if(s[th][j] == "
                d[th][j] = 0
            elif(i == 0):
                d[th][j] = 1
            else:
                d[th][j] = d[th+1][j] + 1
            
    result = 0

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


    print(result)

Solution (Python):
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
ans_array = [[0] * W for i in range(H)]
block_array = []
for i in range(H):
    block_str = input().rstrip()

    block_array.append([1 if s == "


for i in range(H):
    start = 0
    count = 0
    for j in range(W):
        if block_array[i][j] == 1:
            for k in range(start, j):
                ans_array[i][k] += count
            start = j + 1
            count = 0
        else:
            count += 1
    else:
        for k in range(start, W):
            ans_array[i][k] += count



for i in range(W):
    start = 0
    count = 0
    for j in range(H):
        if block_array[j][i] == 1:
            for k in range(start, j):
                ans_array[k][i] += count
            start = j + 1
            count = 0
        else:
            count += 1
    else:
        for k in range(start, H):
            ans_array[k][i] += count



ans = 0
for ar in ans_array:
    ans = max(ans, max(ar) - 1)
print(ans)

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

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

def count_light(Gs, h, w):
    Gc = np.empty((h,w))
    for i in range(w):
        if i == 0:
            Gc[:, i] = Gs[:, i]
        else:
            Gc[:, i] = (Gc[:, i-1] + 1) * Gs[:, i]

    return Gc

Gs1 = np.asarray(S) == "."
Gn1 = count_light(Gs1, H, W)

Gs2 = np.rot90(Gs1, k=1)
Gn2 = count_light(Gs2, W, H)

Gs3 = np.rot90(Gs2, k=1)
Gn3 = count_light(Gs3, H, W)

Gs4 = np.rot90(Gs3, k=1)
Gn4 = count_light(Gs4, W, H)

Gn2 = np.rot90(Gn2, k=-1)
Gn3 = np.rot90(Gn3, k=-2)
Gn4 = np.rot90(Gn4, k=-3)

Gsum = Gn1+Gn2+Gn3+Gn4
ans = int(np.max(Gsum)-3)
print(ans)

Solution (Python):
import numpy as np

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

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)

best_count = 0

for w in range(W):
    if w == 0:
        L[:, w] = S[:, w]
    else:
        L[:, w] = (L[:, w-1] + 1) * S[:, w]

for w in range(W-1, -1, -1):
    if w == W-1:
        R[:, w] = S[:, w]
    else:
        R[:, w] = (R[:, w+1] + 1) * S[:, w]

for h in range(H):
    if h == 0:
        U[h, :] = S[h, :]
    else:
        U[h, :] = (U[h-1] + 1) * S[h, :]

for h in range(H-1, -1, -1):
    if h == H-1:
        D[h, :] = S[h, :]
    else:
        D[h, :] = (D[h+1, :] + 1) * S[h, :]

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

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

l = [[0 for _ in range(w)] for _ in range(h)]
r = [[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)]

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

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

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

for j in range(w):
  for i in range(h-2, -1, -1):
    if not s[i][j] == '
      d[i][j] = d[i+1][j] + 1

ret = 0
for i in range(h):
  for j in range(w):
    if not s[i][j] == '
      t = l[i][j] + r[i][j] + u[i][j] + d[i][j]
      if ret < t:
        ret = t

print(ret+1)

Solution (Python):
import numpy as np

H,W = map(int, input().split())
s = [list(input()) for j in range(H)]
s = (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 j in range(W):
    if j == 0:
        L[:,j] = s[:,j]
    else:
        L[:,j] = (L[:,j-1] + 1) * s[:,j]
        

for j in reversed(range(W)):
    if j == W-1:
        R[:,j] = s[:,j]
    else:
        R[:,j] = (R[:,j+1] + 1) * s[:,j]


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

for i in reversed(range(H)):
    if i == H-1:
        D[i,:] = s[i,:]
    else:
        D[i,:] = (D[i+1,:] + 1) * s[i,:]

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

Solution (Python):
import numpy as np

h, w = [int(i) for i in 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):
h, w = map(int, input().split())

sq = [input() for _ in range(h)]
up = [[0] * (w + 2) for _ in range(h + 2)]
down = [[0] * (w + 2) for _ in range(h + 2)]
left = [[0] * (w + 2) for _ in range(h + 2)]
right = [[0] * (w + 2) for _ in range(h + 2)]

ans = 0

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if sq[i - 1][j - 1] == '
            left[i][j] = 0
            up[i][j] = 0
        else:
            left[i][j] = left[i][j - 1] + 1
            up[i][j] = up[i - 1][j] + 1
for _i in range(h, 0, -1):
    for _j in range(w, 0, -1):
        if sq[_i - 1][_j - 1] == '
            right[_i][_j] = 0
            down[_i][_j] = 0
        else:
            right[_i][_j] = right[_i][_j + 1] + 1
            down[_i][_j] = down[_i + 1][_j] + 1

            temp = up[_i][_j] + down[_i][_j] + left[_i][_j] + right[_i][_j] 
            if temp > ans:
                ans = temp

print(ans - 3)

Solution (Python):

"""
D - Lamp
https://atcoder.jp/contests/abc129/tasks/abc129_d

"""
import sys


def solve(H, W, grid):
    res_x = [[0]*W for _ in range(H)]
    x, y = 0, 0
    while y < H:
        while x < W:
            if grid[y][x] == '
                x += 1
                continue
            rx = x
            while rx < W and grid[y][rx] != '
                rx += 1
            for xx in range(x, rx):
                res_x[y][xx] = rx-x
            x = rx
        x = 0
        y += 1

    res_y = [[0]*W for _ in range(H)]
    x, y = 0, 0
    while x < W:
        while y < H:
            if grid[y][x] == '
                y += 1
                continue
            ry = y
            while ry < H and grid[ry][x] != '
                ry += 1
            for yy in range(y, ry):
                res_y[yy][x] = ry-y
            y = ry
        y = 0
        x += 1

    ans = 0
    for y in range(H):
        for x in range(W):
            t = res_x[y][x] + res_y[y][x] - 1
            if t > ans:
                ans = t
    return ans


def main(args):
    H, W = map(int, input().split())
    grid = [input() for _ in range(H)]
    ans = solve(H, W, grid)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):
from collections import defaultdict


H, W = map(int, input().split())
mass = list()
for i in range(H):
    mass.append(input())

values_col = defaultdict(int)
values_row = defaultdict(int)

ind_row = [[0 for i in range(W)] for j in range(H)]
ind_col = [[0 for i in range(W)] for j in range(H)]

ind = 0
for i, m_row in enumerate(mass):
    ind += 1
    for j, chr in enumerate(mass[i]):
        if chr == '
            ind += 1
        else:
            values_row[ind] += 1
            ind_row[i][j] = ind







ind = 0
for j in range(W):
    ind += 1
    for i in range(H):
        chr = mass[i][j]
        if chr == '
            ind += 1
        else:
            values_col[ind] += 1
            ind_col[i][j] = ind







ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, values_row[ind_row[i][j]] + values_col[ind_col[i][j]] - 1)
print(ans)

Solution (Python):
import numpy as np

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

SL = 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) * SL[i]
    D[-i-1] = (D[-i] + 1) * SL[-i-1]
for i in range(W):
    L[:, i] = (L[:, i-1] + 1) * SL[:, i]
    R[:, -i-1] = (R[:, -i] + 1) * SL[:, -i-1]   
print(np.max(L+R+U+D) - 3)

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


def main():
    cnt = [[0] * W for _ in range(H)]
    for h in range(H):
        done = [0] * W
        for w in range(W):
            if S[h][w] == '
                continue
            c = 0
            while W > w + c:
                if S[h][w + c] == '
                    break
                c += 1
            for k in range(c):
                cnt[h][w + k] += c
                done[w + k] = 1
    for w in range(W):
        done = [0] * H
        for h in range(H):
            if S[h][w] == '
                continue
            c = 0
            while H > h + c:
                if S[h + c][w] == '
                    break
                c += 1
            for k in range(c):
                cnt[h + k][w] += c
                done[h + k] = 1
    ans = 0
    for r in cnt:
        for c in r:
            ans = max(ans, c - 1)
    print(ans)


main()

Solution (Python):
h,w = map(int,input().split())
s = [list(input()) 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):
  l[i][0] = int(s[i][0] != "
  for j in range(1,w):
    if s[i][j] == "
      l[i][j] = 0
    else:
      l[i][j] = l[i][j-1] + 1
  r[i][w-1] = int(s[i][w-1] != "
  for j in range(w-2,-1,-1):
    if s[i][j] == "
      r[i][j] = 0
    else:
      r[i][j] = r[i][j+1] + 1 
for i in range(w):
  d[0][i] = int(s[0][i] != "
  for j in range(1,h):
    if s[j][i] == "
      d[j][i] = 0
    else:
      d[j][i] = d[j-1][i] + 1
  u[h-1][i] = int(s[h-1][i] != "
  for j in range(h-2,-1,-1):
    if s[j][i] == "
      u[j][i] = 0
    else:
      u[j][i] = u[j+1][i] + 1
ans = 0
for i in range(h):
  for j in range(w):
    cur = l[i][j] + r[i][j] + u[i][j] + d[i][j]
    if cur>ans:
      ans = cur
print(ans - 3)

Solution (Python):
H, W = map( int, input().split())
S = [["
H += 2
W += 2
L = [[0]*(W+2) for _ in range(H+2)]
R = [[0]*(W+2) for _ in range(H+2)]
D = [[0]*(W+2) for _ in range(H+2)]
U = [[0]*(W+2) for _ in range(H+2)]
cnt = 0

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

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

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

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

Solution (Python):
import numpy as np

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

U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)

for h in range(H):
    U[h] = (U[h - 1] + 1) * S[h]
    D[-(h + 1)] = (D[-h] + 1) * S[-(h + 1)]

for w in range(W):
    L[:, w] = (L[:, w - 1] + 1) * S[:, w]
    R[:, -(w + 1)] = (R[:, -w] + 1) * S[:, -(w + 1)]

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

Solution (Python):

words = lambda t : list(map(t, input().split()))



h,w = words(int)
wq = [0] * w

grid = []
for i in range(h):
    grid.append(list(input()))

ans = 0
for i in range(h):
    j = 0
    while j < w:
        
        if grid[i][j] == '
            wq[j] = 0
            j+=1
            continue
        k = 0
        while j+k < w:
            if grid[i][j+k] == '.':
                k += 1
            else:
                break
        
        if k + h > ans:
            for x in range(j,j+k):
                vplus = 0
                if not wq[x] == 0:
                    vplus = wq[x]
                else:
                    for vi in range(i-1,-1,-1):
                        if grid[vi][x] == '
                            break
                        else:
                            vplus += 1
                    for vi in range(i+1,h):
                        if grid[vi][x] == '
                            break
                        else:
                            vplus += 1
                ans = max(ans, vplus+k)
                wq[x] = vplus
        j += k
print(ans)

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

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

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