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



sys.setrecursionlimit(10**9)
input = sys.stdin.readline

H, W = map(int, input().split())
grid = [[v for v in input()[:-1]] for _ in range(H)]

col_seq = [[1]*W for _ in range(H)]
row_seq = [[1]*W for _ in range(H)]

for row in range(H):
    for col in range(W):
        if grid[row][col] == "
            col_seq[row][col] = 0
            row_seq[row][col] = 0


for row in range(H):
    for col1, col2 in zip(range(W), range(1, W)):
        if grid[row][col1] == "." and grid[row][col2] == "." and col_seq[row][col1] == 1:
            seq = 2
            next_col = col2+1
            while next_col < W:
                if grid[row][next_col] == ".":
                    seq += 1
                else:
                    break
                next_col += 1
            for i in range(col1, col1+seq):
                col_seq[row][i] = seq


for col in range(W):
    for row1, row2 in zip(range(H), range(1, H)):
        if grid[row1][col] == "." and grid[row2][col] == "." and row_seq[row1][col] == 1:
            seq = 2
            next_row = row2+1
            while next_row < H:
                if grid[next_row][col] == ".":
                    seq += 1
                else:
                    break
                next_row += 1
            for i in range(row1, row1+seq):
                row_seq[i][col] = seq

ans = 0
for row in range(H):
    for col in range(W):
        if grid[row][col] == ".":
            tmp = col_seq[row][col]+row_seq[row][col]-1
            ans = max(ans, tmp)
print(ans)

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

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

for j in range(W):
    tmp = set()
    cnt = 0
    for i in range(H):
        if S[i][j] == "
            for pi,pj in tmp:
                row[pi][pj] = cnt
            tmp = set()
            cnt = 0
        else:
            tmp.add((i,j))
            cnt += 1
    for pi,pj in tmp:
        row[pi][pj] = cnt

for i in range(H):
    tmp = set()
    cnt = 0
    for j in range(W):
        if S[i][j] == "
            for pi,pj in tmp:
                column[pi][pj] = cnt
            tmp = set()
            cnt = 0
        else:
            tmp.add((i,j))
            cnt += 1
    for pi,pj in tmp:
        column[pi][pj] = cnt

ans = 0
for i in range(H):
    for j in range(W):
        res = row[i][j] + column[i][j] - 1
        ans = max(ans,res)

print(ans)

Solution (Python):
import numpy as np

h, w = map(int, input().split())
table = np.array([list(input()) for _ in range(h)]) == "."
D = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
L = np.zeros((h, w), dtype=int)

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

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

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

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

for i in range(H):
  for j in range(W):
    if S[i][j] == "
      A[i][j] = B[i][j] = 0
      continue
    
    if j== 0 or A[i][j-1] == 0:
      numA = 0 
      k = j
      while True:
        numA += 1
        if k == W-1 or S[i][k+1] == "
          A[i][j] = numA
          break
        k += 1
    else:
      A[i][j] = A[i][j-1]
    
    if i == 0 or B[i-1][j] == 0:
      numB =0
      k = i
      while True: 
        numB += 1
        if k == H-1 or S[k+1][j] == "
          B[i][j] = numB
          break
        k += 1
    else:
      B[i][j] = B[i-1][j]


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

Solution (Python):
inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    score[h]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)

Solution (Python):
h, w = map(int, input().split())
s = [input() for _ in range(h)]
 
hdots = [[0]*(w+1) for _ in range(h)]
for j in range(h):
    ndots = 0
    for i in range(1, w+1):
        if s[j][i-1] == '.':
            ndots += 1
        else:
            hdots[j][i-1] = ndots
            ndots = 0
    hdots[j][-1] = ndots if s[j][-1] == '.' else 0
    for i in range(w, 0, -1):
        if s[j][i-1] == '.':
            hdots[j][i] = ndots
        else:
            ndots = hdots[j][i-1]
vdots = [[0]*w for _ in range(h+1)]
for i in range(w):
    ndots = 0
    for j in range(1, h+1):
        if s[j-1][i] == '.':
            ndots += 1
        else:
            vdots[j-1][i] = ndots
            ndots = 0
    vdots[-1][i] = ndots if s[-1][i] == '.' else 0
    for j in range(h, 0, -1):
        if s[j-1][i] == '.':
            vdots[j][i] = ndots
        else:
            ndots = vdots[j-1][i]
 
ans = 0
for j in range(h):
    for i in range(w):
        nh, nv = hdots[j][i+1], vdots[j+1][i]
        if nh == 0 or nv == 0:
            continue
        ans = max(ans, nh+nv-1)
print(ans)

Solution (Python):

import numpy as np

h, w = map(int, input().split())
s = np.array([list(input()) for _ in range(h)]) == '.'

ups = np.zeros((h, w), dtype = int)
downs = np.zeros((h, w), dtype = int)
lefts = np.zeros((h, w), dtype = int)
rights = np.zeros((h, w), dtype = int)

for i in range(1, h):
    ups[i] = (ups[i-1]+1)*s[i-1]
for i in range(h-2, -1, -1):
    downs[i] = (downs[i+1]+1)*s[i+1]
for j in range(1, w):
    lefts[:, j] = (lefts[:, j-1]+1)*s[:, j-1]
for j in range(w-2, -1, -1):
    rights[:, j] = (rights[:, j+1]+1)*s[:, j+1]
counts = ups+downs+lefts+rights
ans = np.max(counts*s)+1
print(ans)

Solution (Python):
H,W = (int(x) for x in input().split())

S_arr_arr = [[1]*(W+2)]
for i in range(H):
    S_arr_arr.append([0 if s=="." else 1 for s in "
S_arr_arr.append([1]*(W+2))

W_arr_arr = [[0]*(W+2) for _ in range(H+2)]
for j in range(H+2):
    i_begin = 0
    for i in range(W+2):
        if S_arr_arr[j][i] == 1:
            for ix in range(i_begin+1, i):
                W_arr_arr[j][ix] += i-i_begin-1
            i_begin = i
for i in range(W+2):
    j_begin = 0
    for j in range(H+2):
        if S_arr_arr[j][i] == 1:
            for jx in range(j_begin+1, j):
                W_arr_arr[jx][i] += j-j_begin-1
            j_begin = j

max_ans = max([max(W_arr) for W_arr in W_arr_arr]) - 1

print(max_ans)

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

L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W+1)] for j in range(H)]

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

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

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

Solution (Python):


H,W = list(map(int,input().split()))
S = [0] * (H+2)
wall = ''
for _ in range(W+2):
    wall += '
S[0] = wall
S[H+1] = wall
for h in range(H):
    S[h+1] = '





dp = [[0] * (W+2) for _ in range(H+2)]
start = 0
maxdp = 0
for h in range(1,H+1):
    flag = False
    for w in range(W+2):
        if S[h][w] == '
            if flag == False :
                start = w
            else:
                for i in range(start+1,w):
                    dp[h][i] += w - i - 1
                    dp[h][i] += i - start - 1
                    if dp[h][i] > maxdp:
                        maxdp = dp[h][i]
                flag = False
                start = w
        else:
            flag = True
for w in range(1,W+1):
    for h in range(H+2):
        if S[h][w] == '
            if flag == False:
                start = h
            else:
                for i in range(start+1,h):
                    dp[i][w] += h - i - 1
                    dp[i][w] += i - start -1
                    if dp[i][w] > maxdp:
                        maxdp = dp[i][w]
                flag = False
                start = h
        else:
            flag = True
print(maxdp+1)

Solution (Python):


H,W = list(map(int,input().split()))
S = [0] * (H+2)
wall = ''
for _ in range(W+2):
    wall += '
S[0] = wall
S[H+1] = wall
for h in range(H):
    S[h+1] = '





dp = [[0] * (W+2) for _ in range(H+2)]
start = 0
maxdp = 0
for h in range(1,H+1):
    flag = False
    for w in range(W+2):
        if S[h][w] == '
            if flag == False :
                start = w
            else:
                for i in range(start+1,w):
                    dp[h][i] += w - i - 1
                    dp[h][i] += i - start - 1
                    if dp[h][i] > maxdp:
                        maxdp = dp[h][i]
                    flag = False
                start = w
        else:
            flag = True
for w in range(1,W+1):
    for h in range(H+2):
        if S[h][w] == '
            if flag == False:
                start = h
            else:
                for i in range(start+1,h):
                    dp[i][w] += h - i - 1
                    dp[i][w] += i - start -1
                    if dp[i][w] > maxdp:
                        maxdp = dp[i][w]
                    flag = False
                start = h
        else:
            flag = True
print(maxdp+1)

Solution (Python):
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
L=[[0 for i in range(w)]for i in range(h)]
R=[[0 for i in range(w)]for i in range(h)]
D=[[0 for i in range(w)]for i in range(h)]
U=[[0 for i in range(w)]for i in range(h)]
ans=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='.':
            if j==0:
                R[i][j]=1
            else:
                R[i][j]=R[i][j-1]+1

        if s[h-i-1][w-j-1]=='.':
            if j==0:
                L[h-i-1][w-j-1]=1
            else:
                L[h-i-1][w-j-1]=L[h-i-1][w-j]+1


        if s[h-i-1][w-j-1]=='.':
            if i==0:
                U[h-i-1][w-j-1]=1
            else:
                U[h-i-1][w-j-1]=U[h-i][w-j-1]+1

        if s[i][j]=='.':
            if i==0:
                D[i][j]=1
            else:
                D[i][j]=D[i-1][j]+1


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

print(ans)

Solution (Python):
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
A = [[0] * W for _ in range(H)]
B = [[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] = 1 if grid[i][0] == '.' else 0
    for j in range(1, W):
        L[i][j] = L[i][j - 1] + 1 if grid[i][j] == '.' else 0
for i in range(H):
    R[i][-1] = 1 if grid[i][-1] == '.' else 0
    for j in range(W - 2, 0, -1):
        R[i][j] = R[i][j + 1] + 1 if grid[i][j] == '.' else 0
for j in range(W):
    A[0][j] = 1 if grid[0][j] == '.' else 0
    for i in range(1, H):
        A[i][j] = A[i - 1][j] + 1 if grid[i][j] == '.' else 0
for j in range(W):
    B[-1][j] = 1 if grid[-1][j] == '.' else 0
    for i in range(H - 2, -1, -1):
        B[i][j] = B[i + 1][j] + 1 if grid[i][j] == '.' else 0



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

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

for h in range(H):
    num = 0
    s = 0
    t = 0
    while t < W:
        if S[h][t] == '
            for k in range(s, t):
                horizontal_lights[h][k] = num
            num = 0
            t += 1
            s = t
        else:
            t += 1
            num += 1
    for k in range(s, t):
        horizontal_lights[h][k] = num


for w in range(W):
    s = 0
    t = 0
    num = 0
    while t < H:
        if S[t][w] == '
            for k in range(s, t):
                vertical_lights[k][w] = num
            num = 0
            t += 1
            s = t
        else:
            t += 1
            num += 1
    for k in range(s, t):
        vertical_lights[k][w] = num

ans = 0
for h, line in enumerate(S):
    for w, c in enumerate(line):
        if c == '.':
            tmp = horizontal_lights[h][w] + vertical_lights[h][w]
            ans = max(ans, tmp-1)
print(ans)

Solution (Python):
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    ht = [[0] * w for _ in range(h)]
    vt = [[0] * h for _ in range(w)]
    for i in range(h):
        st = 0
        c = 0
        for j in range(w):
            if s[i][j] == "
                ht[i][st:j] = [c] * (j - st)
                st = j + 1
                c = 0
                continue
            c += 1
        ht[i][st:w] = [c] * (w - st)
    for i in range(w):
        st = 0
        c = 0
        for j in range(h):
            if s[j][i] == "
                vt[i][st:j] = [c] * (j - st)
                st = j + 1
                c = 0
                continue
            c += 1
        vt[i][st:h] = [c] * (h - st)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, ht[i][j] + vt[j][i])
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
from itertools import accumulate


def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    t = [[1 if __s == "
    hi = [list(accumulate(_t)) for _t in t]
    vi = [list(accumulate(_t)) for _t in zip(*t)]
    hg = [list(map(len, _s.split("
    vg = [list(map(len, "".join(_s).split("
    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]])
    return str(ans - 1)
  
  
if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]])
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)
    ans = 0
    for i in range(h):
        ans = max(ans, max([hg[i][hi[i][j]] + vg[j][vi[j][i]] for j in range(w)]))
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)

    ans = max([max([hg[i][hi[i][j]] + vg[j][vi[j][i]] for j in range(w)]) for i in range(h)])
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, hg[i][hi[i][j]] + vg[j][vi[j][i]])
    return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)

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

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

for i in range(H):
    Si = list(input())
    for j in range(W):
        if Si[j] == '
            S[i][j] = 1


S_row = [[0]*W for _ in range(H)]
for i in range(H):
    c = 0
    for j in range(W):
        if S[i][j] == 1:
            c = 0
        else:
            c += 1
        S_row[i][j] = c
    
    for j in range(W-2, -1, -1):
        if S_row[i][j+1] > 0 and S_row[i][j] > 0:
            S_row[i][j] = S_row[i][j+1]


S_col = [[0]*W for _ in range(H)]
for j in range(W):
    c = 0
    for i in range(H):
        if S[i][j] == 1:
            c = 0
        else:
            c += 1
        S_col[i][j] = c
    
    for i in range(H-2, -1, -1):
        if S_col[i+1][j] > 0 and S_col[i][j] > 0:
            S_col[i][j] = S_col[i+1][j]


res = max([max([S_row[i][j] + S_col[i][j] - 1 for j in range(W)]) for i in range(H)])
print(res)

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

def calc(s):
    res = []
    for v in s:
        v = v + '-'
        tmp = []
        nc = v[0]
        nn = 0
        for c in v:
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        tmp = []
        nc = s[0][j]
        nn = 0
        for i in range(h):
            c = s[i][j]
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        if nc == '
            tmp.extend([0 for _ in range(nn)])
        else:
            tmp.extend( [nn for _ in range(nn)])
        res.append(tmp)
    return res

tate = calc2(S)
yoko = calc(S)

print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)

Solution (Python):
L = []

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

ans1 = [[0 for i in range(W)] for j in range(H)]
ans2 = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
	val = 0
	l = []
	for j in range(W):
		if L[i][j] == "
			for k in l:
				ans1[i][k] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans1[i][k] = val

for i in range(W):
	val = 0
	l = []
	for j in range(H):
		if L[j][i] == "
			for k in l:
				ans2[k][i] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans2[k][i] = val


ans = -1
for i in range(H):
	for j in range(W):
		x = ans1[i][j] + ans2[i][j] - 1
		if x > ans:
			ans = x

print(ans)

Solution (Python):

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

H += 2
W += 2
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)]

grid = []
grid.append(list(('
for i in range(H-2):
    grid.append(list(('
grid.append(list(('

for i in range(1, H-1):
    for j in range(1, W-1):
        if grid[i][j] == '.':
            L[i][j] = L[i][j-1] + 1
        if grid[i][W - j-1]  == '.':
            R[i][W - j-1] = R[i][W - j-1 + 1] + 1

for j in range(1, W-1):
    for i in range(1, H-1):
        if grid[i][j] == '.':
            U[i][j] = U[i-1][j] + 1
        if grid[H - i-1][j]  == '.':
            D[H - i-1][j] = D[H - i-1 + 1][j] + 1

total = [[0 for _ in range(W)] for _ in range(H)]
for i in range(1, H-1):
    for j in range(1,W-1):
        total[i][j] = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3

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

Solution (Python):
import numpy as np


H, W = map(int, input().split())
s = np.array([[c for c in input()] for i in range(H)]) == '.'
s_t = s.transpose()

dp_l = np.zeros((W, H), dtype=int)
dp_r = np.zeros((W, H), dtype=int)
dp_u = np.zeros((H, W), dtype=int)
dp_d = np.zeros((H, W), dtype=int)

dp_l[0] = s_t[0]
dp_r[W-1] = s_t[W-1]
dp_u[0] = s[0]
dp_d[H-1] = s[H-1]

for i in range(1, W):
    dp_l[i] = s_t[i] * (dp_l[i-1] + 1)

for i in reversed(range(W-1)):
    dp_r[i] = s_t[i] * (dp_r[i+1] + 1)

for i in range(1, H):
    dp_u[i] = s[i] * (dp_u[i-1] + 1)

for i in reversed(range(H-1)):
    dp_d[i] = s[i] * (dp_d[i+1] + 1)

cnts = dp_l + dp_r + dp_d.transpose() + dp_u.transpose()
print(max(np.amax(cnts, 0)) - 3)

Solution (Python):
h,w = map(int,input().split())
s = []
for i in range(h):
    s1 = list(input())
    s.append(s1)
p = []
q = []
r = []
t = []
l = 0
for i in range(h):
    count1 = 0
    count2 = 0
    p1 = []
    q1 = []
    for j in range(w):
        if s[i][j] == ".":
            count1 = count1 + 1
            p1.append(count1)
        elif s[i][j] == "
            count1 = 0
            p1.append(count1)
        if s[i][w-j-1] == ".":
            count2 = count2 + 1
            q1.append(count2)
        elif s[i][w-j-1] == "
            count2 = 0
            q1.append(count2)
    p.append(p1)
    q.append(q1)
for i in range(w):
    count1 = 0
    count2 = 0
    r1 = []
    t1 = []
    for j in range(h):
        if s[j][i] == ".":
            count1 = count1 + 1
            r1.append(count1)
        elif s[j][i] == "
            count1 = 0
            r1.append(count1)
        if s[h-j-1][i] == ".":
            count2 = count2 + 1
            t1.append(count2)
        elif s[h-j-1][i] == "
            count2 = 0
            t1.append(count2)
    r.append(r1)
    t.append(t1)
for i in range(h):
    for j in range(w):
        l1 = p[i][j]+q[i][w-j-1]+r[j][i]+t[j][h-i-1]
        if l < l1:
            l = l1
print(l-3)

Solution (Python):
from functools import reduce
import sys
import numpy as np
MOD = 1000000007

buffer = sys.stdin.buffer
H, W = list(map(int,buffer.readline().split()))
S = np.frombuffer(buffer.read(H*(W+1)), dtype="B") == ord(".")
S = S.reshape((H,W+1))[:,:-1]
L = np.empty((H,W), dtype="i4")
R = np.empty((H,W), dtype="i4")
U = np.empty((H,W), dtype="i4")
D = np.empty((H,W), dtype="i4")
 
L[:,0] = S[:,0]
for i in range(1,W):
    L[:,i] = (L[:,i-1] + 1) * S[:,i]
 
R[:,-1] = S[:,-1]
for i in range(1,W):
    R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]
 
U[0] = S[0]
for i in range(1,H):
    U[i] = (U[i-1] + 1) * S[i]
 
D[-1] = S[-1]
for i in range(1,H):
    D[-1-i] = (D[-i] + 1) * S[-1-i]
 
score = L + R + U + D - 3
print(int(score.max()))

Solution (Python):
def getlist():
	return map(int, input().split())

L = []

H, W = getlist()
for i in range(H):
	S = list(input())
	L.append(S)

ans1 = [[0 for i in range(W)] for j in range(H)]
ans2 = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
	val = 0
	l = []
	for j in range(W):
		if L[i][j] == "
			for k in l:
				ans1[i][k] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans1[i][k] = val

for i in range(W):
	val = 0
	l = []
	for j in range(H):
		if L[j][i] == "
			for k in l:
				ans2[k][i] = val
			val = 0
			l = []
		else:
			val += 1
			l.append(j)
	for k in l:
		ans2[k][i] = val


ans = -1
for i in range(H):
	for j in range(W):
		x = ans1[i][j] + ans2[i][j] - 1
		if x > ans:
			ans = x

print(ans)