Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int,input().split())
s = [list(map(lambda x: x == '.', list(input()))) for i in range(H)]
v = [[0]*W for i in range(H)]
h = [[0]*W for i in range(H)]

for i in range(H):
  for j in range(W):
    if not s[i][j]:
      continue
    h[i][j] = v[i][j] = s[i][j]
    if j:
      v[i][j] += v[i][j-1]
    if i:
      h[i][j] += h[i-1][j]
hx, hy = W, 0
vx, vy = 0, H
cv, ch = 0, 0
fh, fv = 0, 0
for _ in range(H*W):
  hy -= 1
  if hy < 0:
    hx -= 1
    hy += H
    fh = 1
  vx -= 1
  if vx < 0:
    vy -= 1
    vx += W
    fv = 1
  if fh or not ch or not h[hy][hx]:
    ch = h[hy][hx]
    fh = 0
  else:
    h[hy][hx] = ch
  if fv or not cv or not v[vy][vx]:
    cv = v[vy][vx]
    fv = 0
  else:
    v[vy][vx] = cv
print(max(h[i][j] + v[i][j] for i in range(H) for j in range(W)) - 1)

Fixed submission:
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
u = [[0]*w for _ in range(h)]
d = [[0]*w for _ in range(h)]
l = [[0]*w for _ in range(h)]
r = [[0]*w for _ in range(h)]
for i in range(h):
  l[i][0] = int(s[i][0] != "#")
  for j in range(1,w):
    if s[i][j] == "#":
      l[i][j] = 0
    else:
      l[i][j] = l[i][j-1] + 1
  r[i][w-1] = int(s[i][w-1] != "#")
  for j in range(w-2,-1,-1):
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      r[i][j] = r[i][j+1] + 1 
for i in range(w):
  d[0][i] = int(s[0][i] != "#")
  for j in range(1,h):
    if s[j][i] == "#":
      d[j][i] = 0
    else:
      d[j][i] = d[j-1][i] + 1
  u[h-1][i] = int(s[h-1][i] != "#")
  for j in range(h-2,-1,-1):
    if s[j][i] == "#":
      u[j][i] = 0
    else:
      u[j][i] = u[j+1][i] + 1
ans = 0
for i in range(h):
  for j in range(w):
    cur = l[i][j] + r[i][j] + u[i][j] + d[i][j]
    if cur>ans:
      ans = cur
print(ans - 3)

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
u = [[0]*w for _ in range(h)]
d = [[0]*w for _ in range(h)]
l = [[0]*w for _ in range(h)]
r = [[0]*w for _ in range(h)]
for i in range(h):
  l[i][0] = int(s[i][0] != "#")
  for j in range(1,w):
    if s[i][j] == "#":
      l[i][j] = 0
    else:
      l[i][j] = l[i][j-1] + 1
  r[i][w-1] = int(s[i][w-1] != "#")
  for j in range(w-2,-1,-1):
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      r[i][j] = r[i][j+1] + 1 
for i in range(w):
  d[0][i] = int(s[0][i] != "#")
  for j in range(1,h):
    if s[j][i] == "#":
      d[j][i] = 0
    else:
      d[j][i] = d[j-1][i] + 1
  u[h-1][i] = int(s[h-1][i] != "#")
  for j in range(h-2,-1,-1):
    if s[j][i] == "#":
      u[j][i] = 0
    else:
      u[j][i] = u[j+1][i] + 1
ans = 0
for i in range(h):
  for j in range(w):
    cur = l[i][j] + r[i][j] + u[i][j] + d[i][j]
    if cur>ans:
      ans = cur
print(ans - 3)


Fixed submission:
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
u = [[0]*w for _ in range(h)]
d = [[0]*w for _ in range(h)]
l = [[0]*w for _ in range(h)]
r = [[0]*w for _ in range(h)]
for i in range(h):
  l[i][0] = int(s[i][0] != "#")
  for j in range(1,w):
    if s[i][j] == "#":
      l[i][j] = 0
    else:
      l[i][j] = l[i][j-1] + 1
  r[i][w-1] = int(s[i][w-1] != "#")
  for j in range(w-2,-1,-1):
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      r[i][j] = r[i][j+1] + 1 
for i in range(w):
  d[0][i] = int(s[0][i] != "#")
  for j in range(1,h):
    if s[j][i] == "#":
      d[j][i] = 0
    else:
      d[j][i] = d[j-1][i] + 1
  u[h-1][i] = int(s[h-1][i] != "#")
  for j in range(h-2,-1,-1):
    if s[j][i] == "#":
      u[j][i] = 0
    else:
      u[j][i] = u[j+1][i] + 1
ans = 0
for i in range(h):
  for j in range(w):
    cur = l[i][j] + r[i][j] + u[i][j] + d[i][j]
    if cur>ans:
      ans = cur
print(ans - 3)