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 = [list(input()) for _ in range(H)]
X = [[-10**2 for __ in range(W)] for _ in range(H)]
Y = [[-10**2 for __ in range(W)] for _ in range(H)]
last_ys = [-1] * W
for y in range(H):
  last_x = -1
  for x in range(W):
    if S[y][x] == "
      for t in range(last_x+1,x):
        X[y][t] = x-1-last_x
      for t in range(last_ys[x]+1,y):
        Y[t][x] = y-1-last_ys[x]
      last_x = x
      last_ys[x] = y
  for t in range(last_x+1,W):
    X[y][t] = W-1-last_x
for x in range(W):
  for t in range(last_ys[x]+1,H):
    Y[t][x] = H-1-last_ys[x]
ans = 0
for y in range(H):
  for x in range(W):
    ans = max(ans, Y[y][x]+X[y][x])
print(ans-1)

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

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



s_ = [list(x) for x in zip(*s)]

ho = [[0]*w for i in range(h)]
he = [[0]*h for i in range(w)]

for j,str in enumerate(s):
    count = 0
    col = 0
    for i, eachstr in enumerate(str):
        if eachstr == "
            if i == 0:
                pass
            else:
                for k in range(col,i):
                    ho[j][k] = count
            col = i + 1
            count = 0
        else:
            count += 1
    else:
        if col < w:
            for k in range(col,i+1):
                ho[j][k] = count

for j,str in enumerate(s_):
    count = 0
    col = 0
    for i, eachstr in enumerate(str):
        if eachstr == "
            if i == 0:
                pass
            else:
                for k in range(col,i):
                    he[j][k] = count
            col = i + 1
            count = 0
        else:
            count += 1
    else:
        if col < w:
            for k in range(col,i+1):
                he[j][k] = count

he_ = [list(x) for x in zip(*he)]

ans = 0
for i,j in zip(ho,he_):
    for ss, tt in zip(i,j):
        ans = max(ans, ss+tt)
print(ans-1)

Solution (Python):


import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

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

    h_path = [[] for _ in range(H)]
    for h in range(H):
        c = 0
        for w in range(W):
            if grid[h][w] == '
                if c > 0:
                    h_path[h].append(c)
                    c = 0
                h_path[h].append(0)
            else:
                c += 1
        if c > 0:
            h_path[h].append(c)
    

    h_query = [[0] * W for _ in range(H)]
    for h in range(H):
        path = h_path[h]
        index = 0
        for p in path:
            l = p if p > 0 else 1
            while l > 0:
                h_query[h][index] = p
                l -= 1
                index += 1

    

    w_path = [[] for _ in range(W)]
    for w in range(W):
        c = 0
        for h in range(H):
            if grid[h][w] == '
                if c > 0:
                    w_path[w].append(c)
                    c = 0
                w_path[w].append(0)
            else:
                c += 1
        if c > 0:
            w_path[w].append(c)
    

    w_query = [[0] * W for _ in range(H)]
    for w in range(W):
        path = w_path[w]
        index = 0
        for p in path:
            l = p if p > 0 else 1
            while l > 0:
                w_query[index][w] = p
                l -= 1
                index += 1

    
    
    def count(i, j):
        h_val = h_query[i][j]
        w_val = w_query[i][j]
        val = h_val + w_val
        if h_val > 0 and w_val > 0:
            val -= 1
        return val

    ans = 0
    for h in range(H):
        for w in range(W):
            if grid[h][w] != '
                
                ans = max(ans, count(h, w))
                pass
    print(ans)


if __name__ == '__main__':
    main()

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

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

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

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

ans = 0
for h in range(H):
  for w in range(W):
    if ('
      if ((0 < h) & ('
        mh = MH[h-1][w]
      else:
        mh = 0
        for h2 in range(h,H):
          if ('
            break
          mh += 1
      MH[h][w] = mh
      if ((0 < w) & ('
        mw = MW[h][w-1]
      else:
        mw = 0
        for w2 in range(w,W):
          if ('
            break
          mw += 1
      MW[h][w] = mw
      a = (mh + mw) - 1
      if (ans < a):
        ans = a
      
print(ans)

Solution (Python):
from itertools import chain

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

for j in range(w):
    p = 0
    while p < h:
        i = p
        while i < h and s[i][j] == '.':
            i += 1
        for k in range(p, i):
            a[k][j] += i - p
        p = i + 1

print(max(chain.from_iterable(a)))

Solution (Python):
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W = Is()
mat = [[0]*W for i in range(H)]
inp = []
for i in range(H):
    inp.append(list(S()))
for i in range(H):
    t = 0
    for j in range(W):
        if inp[i][j] == ".":
            t += 1
            if j == W-1:
                for k in range(j+1-t,j+1):
                    mat[i][k] += t
        elif inp[i][j] == "
            for k in range(j-t,j):
                mat[i][k] += t
            t = 0

for j in range(W):
    t = 0
    for i in range(H):
        if inp[i][j] == ".":
            t += 1
            if i == H-1:
                for k in range(i+1-t,i+1):
                    mat[k][j] += t
        elif inp[i][j] == "
            for k in range(i-t,i):
                mat[k][j] += t
            t = 0    

ans = 0
for e in mat:
    ans = max(ans,max(e))
print(max(0,ans-1))

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

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):
    for j in range(W):
        if j == 0 and S[i][0] == '.':
            l[i][j] = 1
        elif S[i][j] == '.':
            l[i][j] = l[i][j-1] + 1
    for j in range(W-2, -1, -1):
        if S[i][j] == '.' and S[i][j+1] == '.':
            r[i][j] = r[i][j+1] + 1
for j in range(W):
    for i in range(H):
        if i == 0 and S[0][j] == '.':
            u[i][j] = 1
        elif S[i][j] == '.':
            u[i][j] = u[i-1][j] + 1
    for i in range(H-2, -1, -1):
        if S[i][j] == '.' and S[i+1][j] == '.':
            d[i][j] = d[i+1][j] + 1
m = 0
for i in range(H):
    for j in range(W):
        tmp = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 1
        if tmp > m:
            m = tmp
print(m)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    h, w = map(int, input().split())
    mat = [input() for _ in range(h)]

    hor = [[0] * (w + 1) for _ in range(h)]
    ver = [[0] * (h + 1) for _ in range(w)]

    for i, row in enumerate(mat):
        hi = hor[i]
        for j in range(w):
            if row[j] == '.':
                hi[j + 1] = hi[j] + 1
            else:
                hi[j + 1] = 0
        for j in reversed(range(w)):
            if hi[j]:
                hi[j] = max(hi[j], hi[j + 1])
        del hi[0]

    for i, col in enumerate(zip(*mat)):
        vi = ver[i]
        for j in range(h):
            if col[j] == '.':
                vi[j + 1] = vi[j] + 1
            else:
                vi[j + 1] = 0
        for j in reversed(range(h)):
            if vi[j]:
                vi[j] = max(vi[j], vi[j + 1])
        del vi[0]

    ver = list(zip(*ver))

    res = 0
    for i in range(h):
        hi = hor[i]
        vi = ver[i]
        for j in range(w):
            res = max(res, hi[j] + vi[j] - 1)

    print(res)




BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")



if __name__ == "__main__":
    main()

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

room = [[True if c == "." else False for c in input()] for _ in range(H)]

count = []

for i in range(H):
    count.append([0] * W)

for row in range(H):
    start = 0
    for col in range(W):
        if not room[row][col]:
            if col != 0:
                plus = col - start
                for i in range(start, col):
                    count[row][i] += plus
            start = col + 1
    if room[row][W - 1]:
        plus = W - start
        for i in range(start, W):
            count [row][i] += plus

for col in range(W):
    start = 0
    for row in range(H):
        if not room[row][col]:
            if row != 0:
                plus = row - start
                for i in range(start, row):
                    count[i][col] += plus
            start = row + 1
    if room[H - 1][col]:
        plus = H - start
        for i in range(start, H):
            count[i][col] += plus

ans = 0

for rowline in count:
    ans = max(max(rowline), ans)

print((ans - 1))

Solution (Python):
H,W = (int(i) for i in input().split())
s = [[-1] * (W + 2) for i in range(H+2)]
t = [[-1] * (W + 2) for i in range(H+2)]

for i in range(1, H+1):
    SS = input()
    for j in range(W):
        if SS[j] == "
            s[i][j+1] = -1
            t[i][j+1] = -1
        else:
            s[i][j+1] = 0
            t[i][j+1] = 0

tmp = []
num = 0
for i in range(1, H+1):
    for j in range(1, W+2):
        if s[i][j] == -1 :
            if num != 0:
                for tp in tmp:
                    s[i][tp] = num
                tmp = []
                num =0
        else:
            tmp.append(j)
            num += 1

tmp = []
num = 0
for j in range(1, W+1):
    for i in range(1, H+2):
        if t[i][j] == -1 :
            if num != 0:
                for tp in tmp:
                    t[tp][j] = num
                tmp = []
                num =0
        else:
            tmp.append(i)
            num += 1

ref = 0
for i in range(H+2):
    for j in range(W+2):
        ref = max(s[i][j] + t[i][j], ref)

print(ref-1)

Solution (Python):
h,w = map(int,input().split())

table = []
table.append(["
for i in range(h):
    s = input()
    table.append(["
table.append(["


yoko_cnt = []
for i in range(1,h+1):
    cnt = 0

    yoko = []
    for j in range(1,w+2):
        if table[i][j] == "
            if cnt != 0:
                yoko.append(cnt)
            yoko.append(0)
            cnt = 0
            continue
        else:
            cnt += 1
    yoko_cnt.append(yoko[:-1])


tate_cnt = []
for i in range(1,w+1):
    cnt = 0

    tate = []
    for j in range(1,h+2):
        if table[j][i] == "
            if cnt != 0:
                tate.append(cnt)
            tate.append(0)
            cnt = 0
            continue
        else:
            cnt += 1
    tate_cnt.append(tate[:-1])

yoko_cnt_mod = []
for l in yoko_cnt:
    hoge = []
    for i in l:
        if i == 0:
            hoge.append(0)
        else:
            hoge.extend([i for _ in range(i)])
    yoko_cnt_mod.append(hoge)


tate_cnt_mod = []
for l in tate_cnt:
    hoge = []
    for i in l:
        if i == 0:
            hoge.append(0)
        else:
            hoge.extend([i for _ in range(i)])
    tate_cnt_mod.append(hoge)


result = 0
for i in range(h):
    for j in range(w):
        tt = tate_cnt_mod[j][i]
        yy = yoko_cnt_mod[i][j]
        
        if tt == 0 or yy ==0:
            continue
        else:
            c = tt + yy - 1
            if result < c:
                result = c
                
print(result)

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

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

for h in range(H-1,-1,-1):
  cnt = 0
  for w in range(W-1,-1,-1):
    if grid[h][w] == "
      cnt = 0
    elif cnt == 0:
      cnt = cntW[h][w]
    else:
      cntW[h][w] = cnt

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

for w in range(W-1,-1,-1):
  cnt = 0
  for h in range(H-1,-1,-1):
    if grid[h][w] == "
      cnt = 0
    elif cnt == 0:
      cnt = cntH[h][w]
    else:
      cntH[h][w] = cnt

ans = 0
for h in range(H):
  for w in range(W):
    ans = max(ans,cntW[h][w]+cntH[h][w])

print(ans-1)

Solution (Python):
H,W=map(int,input().split())
map_matrix=[]
calc_matrix=[]
for i in range(H):
  line=[True if s=="." else False for s in input()]
  map_matrix.append(line)
  calc_matrix.append([0]*W)

map_matrix_h=[]
for h in range(H):
  line=[i for i, x in enumerate(map_matrix[h]) if not x]
  map_matrix_h.append([-1]+line+[W])


score_matrix_h=[]
for i in range(H):
  h2list = map_matrix_h[i]  
  score = [W]*W
  for j in range(len(h2list)-1):
    hl=h2list[j]
    hr=h2list[j+1]    
    
    if hl==-1 and hr==W:
      score=[W]*W
    elif hl==-1:
      score[0:hr]=[hr]*hr
      score[hr]=0
    elif hr==W:
      score[hl]=0
      score[hl+1:]=[W-hl-1]*(W-hl-1)
    else:
      score[hl]=0
      score[hl+1:hr]=[hr-hl-1]*(hr-hl-1)
      score[hr]=0
  
  score_matrix_h.append(score)

map_matrix_w=[]
map_matrix_tr=list(map(list, zip(*map_matrix)))


for w in range(W):
  line=[i for i, x in enumerate(map_matrix_tr[w]) if not x]
  
  map_matrix_w.append([-1]+line+[H])


score_matrix_w=[]
for i in range(W):
  w2list = map_matrix_w[i]  
  score = [H]*H
  for j in range(len(w2list)-1):
    wl=w2list[j]
    wr=w2list[j+1]    
    
    if wl==-1 and wr==H:
      score=[H]*H
    elif wl==-1:
      score[0:wr]=[wr]*wr
      score[wr]=0
    elif wr==H:
      score[wl]=0
      score[wl+1:]=[H-wl-1]*(H-wl-1)
    else:
      score[wl]=0
      score[wl+1:wr]=[wr-wl-1]*(wr-wl-1)
      score[wr]=0
  
  score_matrix_w.append(score)



max_right = -1
for i in range(H):
  for j in range(W):
    right = score_matrix_h[i][j]+score_matrix_w[j][i]-1
    if right > max_right:
      max_right = right
      
print(max_right)

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

P = [[0 if x == "
C = [[-3*P[x][y] for y in range(W)] for x in range(H)]

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

        if P[H-1-i][j] == 0:
            cntU = 0
        else:
            cntU += 1
        C[H-1-i][j] += cntU 

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

        if P[i][W-1-j] == 0:
            cntL = 0
        else:
            cntL += 1
        C[i][W-1-j] += cntL 




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

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

memo_yoko1 = [[-1 for i in range(w)] for j in range(h)]
memo_tate1 = [[-1 for i in range(w)] for j in range(h)]

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

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


s_t = [[''] for j in range(h)]
for i in range(h):
    s_t[i] = s[h - i - 1][0][::-1]

memo_yoko2 = [[-1 for i in range(w)] for j in range(h)]
memo_tate2 = [[-1 for i in range(w)] for j in range(h)]

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

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


memo = [[-1 for i in range(w)] for j in range(h)]
ans = -1
for i in range(h):
    for j in range(w):
        _memo = memo_tate1[i][j] + memo_tate2[h - i - 1][w - j - 1] + memo_yoko1[i][j] + memo_yoko2[h - i - 1][w - j - 1] - 3
        memo[i][j] = _memo

        ans = max(ans, _memo)

print(ans)

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

A = [[0 for i in range(w)] for j in range(h)]

a = -1
b = -1
for i in range(h):
    a = -1
    for j in range(w):
        if S[i][j] == "
            if a != -1:
                for k in range(a,j):
                    A[i][k] += j-a
                a = -1
        else:
            if a == -1:
                a = j
                
    if a != -1:
        for k in range(a,j+1):
            A[i][k] += j+1-a

for i in range(w):
    a = -1
    for j in range(h):
        if S[j][i] == "
            if a != -1:
                for k in range(a,j):
                    A[k][i] += j-a
                a = -1
        else:
            if a == -1:
                a = j
    if a != -1:
        for k in range(a,j+1):
            A[k][i] += j+1-a


ans = 0
for i in range(h):
    ans = max(ans, max(A[i]))

print(ans-1)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main():
    H, W = LI()
    S = []
    for _ in range(H):
        S.append(SI())

    

    
    yoko = [ [-1]*W for _ in range(H)]
    for i in range(H):
        beginning = True
        continuous = 0
        for j in range(W):
            if beginning:
                if S[i][j] == '
                    continue
                if S[i][j] == '.':
                    beginning = False
                    continuous += 1
            else:
                if S[i][j] == '
                    for k in range(j-continuous, j):
                        yoko[i][k] = continuous
                    beginning = True
                    continuous = 0
                if S[i][j] == '.':
                    continuous += 1
        if continuous:
            for k in range(W-continuous, W):
                yoko[i][k] = continuous

    
    tate = [ [-1]*W for _ in range(H)]
    for j in range(W):
        beginning = True
        continuous = 0
        for i in range(H):
            if beginning:
                if S[i][j] == '
                    continue
                if S[i][j] == '.':
                    beginning = False
                    continuous += 1
            else:
                if S[i][j] == '
                    for k in range(i-continuous, i):
                        tate[k][j] = continuous
                    beginning = True
                    continuous = 0
                if S[i][j] == '.':
                    continuous += 1
        if continuous:
            for k in range(H-continuous, H):
                tate[k][j] = continuous

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

    print(ans)

main()

Solution (Python):






H, W = map(int, input().split())
mp = [[] for h in range(H)]
mp_row = [[0 for w in range(W)] for h in range(H)]
mp_col = [[0 for w in range(W)] for h in range(H)]


for h in range(H):
    mp[h] = [True if c == "." else False for c in input()]







for h in range(H):
    st = 0
    cnt = 0
    for w in range(W):
        if mp[h][w] is False:
            for i in range(st, w):
                mp_row[h][i] = cnt
            cnt = 0
            st = w+1
        elif w == W-1:
            cnt += 1
            for i in range(st, W):
                mp_row[h][i] = cnt
        else:
            cnt += 1


for w in range(W):
    st = 0
    cnt = 0
    for h in range(H):
        if mp[h][w] is False:
            for i in range(st, h):
                mp_col[i][w] = cnt
            cnt = 0
            st = h+1
        elif h == H-1:
            cnt += 1
            for i in range(st, H):
                mp_col[i][w] = cnt
        else:
            cnt += 1





mx = 0
for h in range(H):
    for w in range(W):
        
        mx = max(mx, mp_row[h][w]+mp_col[h][w]-1)
print(mx)

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

g = [".", "
HL = [[0] * W for _ in range(H)]
HR = [[0] * W for _ in range(H)]

for i in range(H):
  l = 0
  r = 0
  for j in range(W):
    if S[i][j] == g[0]:
      l += 1
    else:
      l = 0
    HL[i][j] = l
    if S[i][W - 1 - j] == g[0]:
      r += 1
    else:
      r = 0
    HR[i][W - 1 - j] = r

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

for i in range(W):
  u = 0
  d = 0
  for j in range(H):
    if S[j][i] == g[0]:
      u += 1
    else:
      u = 0
    WU[j][i] = u
    if S[H - j - 1][i] == g[0]:
      d += 1
    else:
      d = 0
    WD[H - j - 1][i] = d

ans = 0

for i in range(H):
  for j in range(W):
    k = HL[i][j] + HR[i][j] + WU[i][j] + WD[i][j] - 3
    ans = max(ans, k)

print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
S=[list(input().strip()) for _ in range(h)]
A=[[0]*(w+2) for _ in range(h+2)]
for i,s in enumerate(S):
    for j,t in enumerate(s):
        if t=='.':
            A[i+1][j+1]=A[i+1][j]+1
    for k in reversed(range(w+1)):
        if A[i+1][k]==0:
            continue
        A[i+1][k]=max(A[i+1][k],A[i+1][k+1])
St=list(map(list,zip(*S)))
B=[[0]*(h+2) for _ in range(w+2)]
for i,s in enumerate(St):
    for j,t in enumerate(s):
        if t=='.':
            B[i+1][j+1]=B[i+1][j]+1
    for k in reversed(range(h+1)):
        if B[i+1][k]==0:
            continue
        B[i+1][k]=max(B[i+1][k],B[i+1][k+1])
B=list(map(list,zip(*B)))
ans=0
for i in range(h+2):
    for j in range(w+2):
        ans=max(ans,A[i][j]+B[i][j]-1)
print(ans)

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

Solution (Python):

import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())


H, W = mi()
S = []

S.append('
for _ in range(H):
  S.append(''.join(('
S.append('



hnum = [[0]*(W+2) for _ in range(H+2)] 

for i in range(1, H+2): 
  noww = 0 
  tmphnum = 0 
  tmphnumstartidx = -1 
  for cell in S[i]: 
    if cell=='
      
      if tmphnumstartidx != -1:
        
        for j in range(tmphnumstartidx, noww): 
          hnum[i][j] = tmphnum
        tmphnumstartidx = -1 
        tmphnum = 0 
    else: 
      
      if tmphnumstartidx == -1:
        tmphnum = 1
        tmphnumstartidx = noww
      else: 
        tmphnum += 1 
    
    noww += 1


ans = 0



for i in range(1, W+2): 
  tmpwnum = 0 
  tmpwnumstartidx = -1 
  
  for j in range(1, H+2): 
    cell = S[j][i] 
    if cell=='
      
      
      if tmpwnumstartidx != -1:
        
        
        for p in range(tmpwnumstartidx, j): 
          ans = max(tmpwnum + hnum[p][i] - 1, ans)
        tmpwnumstartidx = -1 
        tmpwnum = 0 
    else: 
      
      if tmpwnumstartidx == -1:
        tmpwnum = 1
        tmpwnumstartidx = j
      else: 
        tmpwnum += 1 

print(ans)

Solution (Python):

import sys
import numpy as np


def solve(H: int, W: int, S: "List[List[str]]"):
    arr_s = np.array(S)
    arr_s = np.where(arr_s == ".", 1, 0)
    arr_v = np.zeros((H, W), dtype=int)
    arr_h = np.zeros((H, W), dtype=int)
    arr_v[0, :] = arr_s[0, :]
    arr_h[:, 0] = arr_s[:, 0]

    for i in range(H-1):
        arr_v[i+1, :] = (arr_v[i, :] + 1) * arr_s[i+1, :]
    
    for i in range(H-2, -1, -1):
        arr_v[i, :] = np.where(arr_v[i, :] > 0, np.maximum(arr_v[i+1, :], arr_v[i, :]), 0)

    for i in range(W-1):
        arr_h[:, i+1] = (arr_h[:, i] + 1) * arr_s[:, i+1]
    
    for i in range(W-2, -1, -1):
        arr_h[:, i] = np.where(arr_h[:, i] > 0, np.maximum(arr_h[:, i+1], arr_h[:, i]), 0)
    
    print(np.max(arr_v + arr_h) - 1)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    S = [ [c for c in next(tokens)] for _ in range(H) ]  
    solve(H, W, S)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

input = sys.stdin.readline

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

row_blocks = []
for r in range(H):
    t = []
    x = 0
    for c in range(W):
        if s[r][c] == '.':
            x += 1
        else:
            x = 0
        t.append(x)

    x = 0
    for i in range(W - 1, -1, -1):
        if t[i] > 0:
            x = max(x, t[i])
        else:
            x = 0
        t[i] = x
    row_blocks.append(t)


col_blocks = []
for c in range(W):
    t = []
    x = 0
    for r in range(H):
        if s[r][c] == '.':
            x += 1
        else:
            x = 0
        t.append(x)

    x = 0
    for i in range(H - 1, -1, -1):
        if t[i] > 0:
            x = max(x, t[i])
        else:
            x = 0
        t[i] = x
    col_blocks.append(t)


ans = 0
for r in range(H):
    for c in range(W):
        t = row_blocks[r][c] + col_blocks[c][r] - 1
        ans = max(ans, t)
print(ans)