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 collections
def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input())

    rows = []
    rows_val = dict()
    id = 0
    for i in range(H):
        count = 0
        temp = []
        id += 1
        for j in range(W):
            if grid[i][j] == "
                if count > 0:
                    rows_val[id] = count
                count = 0
                id += 1
                temp.append(None)
            else:
                temp.append(id)
                count += 1
        if count > 0:
            rows_val[id] = count
        rows.append(temp)
    

    cols = []
    cols_val = dict()
    id = 0
    for j in range(W):
        count = 0
        temp = []
        id += 1
        for i in range(H):
            if grid[i][j] == "
                if count > 0:
                    cols_val[id] = count
                count = 0
                id += 1
                temp.append(None)
            else:
                count += 1
                temp.append(id)
        if count > 0:
            cols_val[id] = count
        cols.append(temp)

    max_v = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == ".":
                v = rows_val[rows[i][j]]
                v += cols_val[cols[j][i]] - 1 
                max_v = max(max_v, v)
    return max_v


if __name__ == '__main__':
    print(main())

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

def calc(x,y):
    if grid[y][x] == '
        return
    if tate[y][x] == -1:
        count = 1
        up = y
        down = y
        while True:
            if up == 0 or grid[up-1][x] == '
                break
            else:
                up -= 1
                count += 1
        while True:
            if down == H-1 or grid[down+1][x] == '
                break
            else:
                down += 1
                count += 1
        for i in range(up, down+1):
            tate[i][x] = count
    if yoko[y][x] == -1:
        count = 1
        left = x
        right = x
        while True:
            if left == 0 or grid[y][left-1] == '
                break
            else:
                left -= 1
                count += 1
        while True:
            if right == W-1 or grid[y][right+1] == '
                break
            else:
                right += 1
                count += 1
        for i in range(left, right+1):
            yoko[y][i] = count
    return

for x in range(W):
    for y in range(H):
        calc(x, y)

ans = 0
for x in range(W):
    for y in range(H):
       ans = max(ans, tate[y][x]+yoko[y][x]-1)
print(ans)

Solution (Python):
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '
  s.append('
  ft = [[i] * i for i in range(10)]
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          if t < 10:
            yokoi[start:j] = ft[t]
          else:
            yokoi[start:j] = [t] * t
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '
  s.append('
  ft = [[i] * i for i in range(1000)]
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          if t < 1000:
            yokoi[start:j] = ft[t]
          else:
            yokoi[start:j] = [t] * t
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '
  s.append('
  ft = [[i] * i for i in range(100)]
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          if t < 100:
            yokoi[start:j] = ft[t]
          else:
            yokoi[start:j] = [t] * t
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
from sys import stdin
def main():
  from itertools import repeat
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '
  s.append('
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          yokoi[start:j] = repeat(t, t)
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
from sys import stdin
def main():
  from itertools import repeat
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '
  s.append('
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          yokoi[start:j] = repeat(t, t)
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '
  s.append('
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          yokoi[start:j] = [t] * t
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
from sys import stdin
def main():
  from itertools import repeat
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '
  s.append('
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          yokoi[start:j] = repeat(t, t)
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
def main():
    h,w = map(int,input().split())
    ls = [list(input()) for _ in range(h)]
    r = [[0 for _ in range(w)]  for _ in range(h)]
    l = [[0 for _ in range(w)]  for _ in range(h)]
    o = [[0 for _ in range(w)]  for _ in range(h)]
    u = [[0 for _ in range(w)]  for _ in range(h)]

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

    for i in range(h):
        for j in range(w):
            if j == 0:
                if ls[i][j]=='
                    pass
                else:
                    l[i][j]=1
            else:
                if ls[i][j]=='
                    pass
                else:
                    l[i][j] = l[i][j-1]+1
    for j in range(w):
        for i in range(h):
            if i == 0:
                if ls[i][j]=='
                    pass
                else:
                    o[i][j]=1
            else:
                if ls[i][j]=="
                    pass
                else:
                    o[i][j] = o[i-1][j] + 1
    for j in range(w):
        for i in reversed(range(h)):
            if i == h-1:
                if ls[i][j]=='
                    pass
                else:
                    u[i][j]=1
            else:
                if ls[i][j]=='
                    pass
                else:
                    u[i][j] = u[i+1][j] + 1

    ans = 0
    for i in range(h):
        for j in range(w):
            can = r[i][j] + l[i][j] + o[i][j] + u[i][j]
            ans = max(ans,can)
    print(ans-3)
if __name__ == "__main__":
    main()

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):
H, W = map(int, input().split())
field = [input() for i in range(H)]
verti_lamp = [[0]*W for i in range(H)]
horiz_lamp = [[0]*W for i in range(H)]


def verti_search(y, x):
    count = 0
    down = 1
    while y+down <= H-1 and field[y+down][x] =='.':
        count += 1
        down += 1
    y += down
    return count, y


def horiz_search(y, x):
    count = 0
    right = 1
    while x+right <= W-1 and field[y][x+right] =='.':
        count += 1
        right += 1
    x += right
    return count, x


for y in range(H):
    x = 0
    while x <= W-1:
        if field[y][x] == '
            x += 1
            continue
        else:
            horiz, nx = horiz_search(y, x)
            for t in range(x, nx):
                horiz_lamp[y][t] = horiz
            x = nx

for x in range(W):
    y = 0
    while y <= H-1:
        if field[y][x] == '
            y += 1
            continue
        else:
            verti, ny = verti_search(y, x)
            for t in range(y, ny):
                verti_lamp[t][x] = verti
            y = ny

ans = 0
for y in range(H):
    for x in range(W):
        candidate = verti_lamp[y][x] + horiz_lamp[y][x] + 1
        ans = max(ans, candidate)

print(ans)

Solution (Python):
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '
  s.append('
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          for k in range(start, j):
            yokoi[k] = t
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
import sys
input = sys.stdin.readline

from collections import deque

def main(): 
    H,W = map(int,input().split())
    S = [input().split() for _ in range(H)]
    for i in range(H):
        S[i]=list(S[i][0])
    grid = [[0]*W for _ in range(H)]
    
    for i in range(H):
        l=0
        for j in range(W):
            if S[i][j] == "
                for k in range(1,l+1):
                    grid[i][j-k]+=l
                l=0
            else:
                l+=1
        for k in range(1,l+1):
                    grid[i][W-k]+=l
    max=0
    for j in range(W):
        l=0
        for i in range(H):
            if S[i][j] == "
                for k in range(1,l+1):
                    grid[i-k][j]+=l
                    if grid[i-k][j] > max:
                        max = grid[i-k][j]
                l=0
            else:
                l+=1
        for k in range(1,l+1):
            grid[H-k][j]+=l
            if grid[H-k][j] > max:
                        max = grid[H-k][j]
    print(max-1)
if __name__ == "__main__":
    main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    matrix = [list(input()) for _ in range(H)]
    count_matrix = [[0 for _ in range(W)] for _ in range(H)]

    
    for i in range(H):
        start = 0
        count = 0
        for j in range(W):
            s = matrix[i][j]
            if s == '.':
                count += 1
                if j == W-1:
                    for k in range(start, j+1):
                        count_matrix[i][k] += count
            else:
                for k in range(start, j):
                    count_matrix[i][k] += count
                start = j+1
                count = 0

    
    for i in range(W):
        start = 0
        count = 0
        for j in range(H):
            s = matrix[j][i]
            if s == '.':
                count += 1
                if j == H-1:
                    for k in range(start, j+1):
                        count_matrix[k][i] += count
            else:
                for k in range(start, j):
                    count_matrix[k][i] += count
                start = j+1
                count = 0
    
    max_val = 0
    for i in range(H):
        for j in range(W):
            max_val = max(max_val, count_matrix[i][j])
    print(max_val-1)
    return

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    H, W = map(int, input().split())
    matrix = [list(input()) for _ in range(H)]
    L = [[0 for _ in range(W)] for _ in range(H)]
    R = [[0 for _ in range(W)] for _ in range(H)]
    D = [[0 for _ in range(W)] for _ in range(H)]
    U = [[0 for _ in range(W)] for _ in range(H)]

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

    
    for i in range(H):
        if matrix[i][-1] == '.':
            R[i][-1] = 1
        for j in range(W-2, -1, -1):
            s = matrix[i][j]
            if s == '.':
                R[i][j] = R[i][j+1] + 1
    
    
    for i in range(W):
        if matrix[0][i] == '.':
            U[0][i] = 1
        for j in range(1, H):
            s = matrix[j][i]
            if s == '.':
                U[j][i] = U[j-1][i] + 1
    
    
    for i in range(W):
        if matrix[-1][i] == '.':
            D[-1][i] = 1
        for j in range(H-2, -1, -1):
            s = matrix[j][i]
            if s == '.':
                D[j][i] = D[j+1][i] + 1    
    
    max_val = -3
    for i in range(H):
        for j in range(W):
            max_val = max(max_val, R[i][j]+L[i][j]+U[i][j]+D[i][j])
    print(max_val-3)
    return

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
def main():
  _readline, _range = stdin.readline, range
  h, w = map(int, _readline().split())
  s = [_readline().rstrip() + '
  s.append('
  yoko = [[0] * w for _ in _range(h)]
  for i in _range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in _range(w + 1):
      if si[j] == '
        if start != -1:
          t = j - start
          for k in _range(start, j):
            yokoi[k] = t
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in _range(w):
    start = -1
    for j in _range(h + 1):
      if s[j][i] == '
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Solution (Python):
def main():
    import sys
    
    H,W = map(int, input().split())
    S = [(input()) for i in range(H)]
    wall = "
    for i in range(H):
        S[i] += "
    S.append(wall)
    A = [([0]*W) for _ in range(H)]
    B = [([0]*W) for _ in range(H)]
    
    for i in range(H+1):
        for j in range(W):
            if i == 0:
                if S[i][j]  == ".":
                    A[i][j] = 1
            else:
                if S[i][j]  == ".":
                    A[i][j] = A[i-1][j] + 1
                else:
                    k = i-1
                    while k>=0 and A[k][j]>0:
                        A[k][j] = A[i-1][j]
                        k -= 1
    for j in range(W+1):
        for i in range(H):
            if j == 0:
                if S[i][j]  == ".":
                    B[i][j] = 1
            else:
                if S[i][j]  == ".":
                    B[i][j] = B[i][j-1] + 1
                else:
                    k = j-1
                    while k >=0 and B[i][k]>0:
                        B[i][k] = B[i][j-1]
                        k -= 1
    answer = 0
    for i in range(H):
        for j in range(W):
            tmp = A[i][j] + B[i][j] - 1
            if tmp >= answer:
                answer = tmp
    print(answer)
    
    
    
main()

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

l, r, d, u = [[[0 for _ in range(W)] for _ in range(H)] for _ in range(4)]

for y in range(H):
    for x in range(W):
        if S[y][x] == "
            l[y][x] = -1
        elif x == 0:
            l[y][x] = 0
        else:
            l[y][x] = l[y][x-1] + 1
for y in range(H):
    for x in range(W-1, -1, -1):
        if S[y][x] == "
            r[y][x] = -1
        elif x == W-1:
            r[y][x] = 0
        else:
            r[y][x] = r[y][x+1] + 1
for x in range(W):
    for y in range(H):
        if S[y][x] == "
            u[y][x] = -1
        elif y == 0:
            u[y][x] = 0
        else:
            u[y][x] = u[y-1][x] + 1
for x in range(W):
    for y in range(H-1, -1, -1):
        if S[y][x] == "
            d[y][x] = -1
        elif y == H-1:
            d[y][x] = 0
        else:
            d[y][x] = d[y+1][x] + 1

max_num = 0
for y in range(H):
    for x in range(W):
        m = l[y][x] + r[y][x] + u[y][x] + d[y][x] + 1
        
        
        max_num = max(max_num, m)

print(max_num)

Solution (Python):
H, W = map(int,input().split())
S = [list(input()) for _ in range(H)]
table = [[0 for _ in range(W)] for _ in range(H)]
def dfsW(n):
  global table
  l = -1
  r = -1
  i = 0
  while i < W:
    if S[n][i] == ".":
      if l == -1:
        l = i
      r = i
    else:
      if l != -1:
        for j in range(l, r + 1):
          table[n][j] += r - l + 1
      l = -1
      r = -1
    i += 1
  if l != -1:
    for j in range(l, r + 1):
      table[n][j] += r - l + 1


def dfsH(n):
  global table
  l = -1
  r = -1
  i = 0
  while i < H:
    if S[i][n] == ".":
      if l == -1:
        l = i
      r = i
    else:
      if l != -1:
        for j in range(l, r + 1):
          table[j][n] += r - l + 1
      l = -1
      r = -1
    i += 1
    
  if l != -1:
    for j in range(l, r + 1):
      table[j][n] += r - l + 1


for i in range(H):
  dfsW(i)
for i in range(W):
  dfsH(i)
print(max(map(max, table)) - 1)

Solution (Python):
from itertools import groupby
 
[H, W] = map(int, input().split())
Ss = [list(map( lambda x: int(x == "."), list(input()) )) for _ in range(H)]
 
res = 0
count = [[-Ss[i][j] for j in range(W)] for i in range(H)]
for i in range(H):
    j = 0
    for x in groupby(Ss[i]):
        k = len(list(x[1]))
        for _ in range(k):
            count[i][j] += k * x[0]
            j += 1

for j in range(W):
    i = 0
    for x in groupby([Ss[i][j] for i in range(H)]):
        k = len(list(x[1]))
        for _ in range(k):
            new_res = count[i][j] + k * x[0]
            if res < new_res:
                res = new_res
            i += 1

print(res)

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

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]

for i in range(h):
    cnt_L = 1
    for j in range(w):
        if (lst[i][j] == '
            cnt_L =1
        else:
            L[i][j] = cnt_L
            cnt_L += 1
            
    cnt_R = 1
    for k in range(w)[::-1]:
        if (lst[i][k] == '
            cnt_R = 1
        else:
            R[i][k] = cnt_R
            cnt_R += 1

for i in range(w):
    cnt_U = 1
    for j in range(h):
        if (lst[j][i] == '
            cnt_U = 1
        else:
            U[j][i] = cnt_U
            cnt_U += 1
    
    cnt_D = 1
    for k in range(h)[::-1]:
        if (lst[k][i] == '
            cnt_D = 1
        else:
            D[k][i] = cnt_D
            cnt_D += 1

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

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

res = 0
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]

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

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

for i in reversed(range(h)):
    for j in reversed(range(w)):
        if lst[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1

for i in reversed(range(w)):
    for j in reversed(range(h)):
        if lst[j][i] == '.':
            if i == w-1:
                R[j][i] = 1
            else:
                R[j][i] = R[j][i+1] + 1

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

Solution (Python):



def solve(H, W, S):
    grid = [[0] * W for _ in range(H)]
    for y in range(H):
        count = 0
        start = 0
        for x in range(W):
            if S[y][x] == '
                for i in range(start, x):
                    grid[y][i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[y][i] = count

    ans = 1
    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '
                for i in range(start, y):
                    if ans < grid[i][x] + count:
                        ans = grid[i][x] + count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            if ans < grid[i][x] + count:
                ans = grid[i][x] + count

    return ans - 1


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

    ans = solve(H, W, S)

    print(ans)

Solution (Python):



def solve(H, W, S):
    grid = [[0] * W for _ in range(H)]
    for y in range(H):
        count = 0
        start = 0
        for x in range(W):
            if S[y][x] == '
                for i in range(start, x):
                    grid[y][i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[y][i] = count

    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '
                for i in range(start, y):
                    grid[i][x] += count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            grid[i][x] += count

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


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

    ans = solve(H, W, S)

    print(ans)

Solution (Python):
import numpy as np
H, W = map(int, input().split())
A = []
for _ in range(H):
    vec = list(map(lambda x: 0 if x=='
    A.append(vec)

A = np.array(A)
top = np.zeros((H+1, W), dtype=np.int)
bottom = np.zeros((H+1, W), dtype=np.int)
left = np.zeros((H, W+1), dtype=np.int)
right = np.zeros((H, W+1), dtype=np.int)

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

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

for i in range(1, W+1):
    left[:, i] = (left[:, i-1] + 1) * A[:, i-1]
    
for i in range(W-1, -1, -1):
    right[:, i] = (right[:, i+1] + 1) * A[:, i]
    
C = top[1:H+1, :] + bottom[0:H, :] - A
R = left[:, 1:W+1] + right[:, 0:W] - A
CR = C + R - A
print(CR.max())

Solution (Python):
h, w = map(int, input().split())
s = [input() + '
s.append('
t = [[-1] * w for _ in range(h + 1)]
tstart = [-1] * (w + 1)
for i in range(h + 1):
  ystart = -1
  for j in range(w + 1):
    if s[i][j] == '
      if ystart != -1:
        for k in range(ystart, j):
          t[i][k] += j - ystart
        ystart = -1
      if tstart[j] != -1:
        for k in range(tstart[j], i):
          t[k][j] += i - tstart[j]
        tstart[j] = -1
    else:
      if ystart == -1:
        ystart = j
      if tstart[j] == -1:
        tstart[j] = i
print(max(map(max, t)))

Solution (Python):
def main():
  _max = max
  _range = range
  _input = input
  h, w = map(int, _input().split())
  s = [_input() + '
  s.append('

  rt = [[-1] * w for _ in _range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in _range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in _range(w + 1):
      tj = tstart[j]
      if si[j] == '
        if ystart != -1:
          jy = j - ystart
          for k in _range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in _range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(_max(map(_max, rt)))

main()