Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
cnt1 = [[0]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      continue
    cnt1[i][j] = 1

for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      continue
    if j-1 >= 0:
      cnt1[i][j] += cnt1[i][j-1]
for i in range(H):
  for j in range(W-1, -1, -1):
    if S[i][j] == '#':
      continue
    if j+1 <= W-1:
      cnt1[i][j] = max(cnt1[i][j], cnt1[i][j+1])

S2 = [[0]*H for _ in range(W)]
for i in range(H):
  for j in range(W):
    S2[j][i] = S[i][j]

cnt2 = [[0]*H for _ in range(W)]
for i in range(W):
  for j in range(H):
    if S2[i][j] == '#':
      continue
    cnt2[i][j] = 1

for i in range(W):
  for j in range(H):
    if S2[i][j] == '#':
      continue
    if j-1 >= 0:
      cnt2[i][j] += cnt2[i][j-1]
for i in range(W):
  for j in range(H-1, -1, -1):
    if S2[i][j] == '#':
      continue
    if j+1 <= H-1:
      cnt2[i][j] = max(cnt2[i][j], cnt2[i][j+1])


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


Fixed submission:
h, w = map(int, input().split())
s = [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):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)])
cnt1 = [[0]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      continue
    cnt1[i][j] = 1

for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      continue
    if j-1 >= 0:
      cnt1[i][j] += cnt1[i][j-1]
for i in range(H):
  for j in range(W-1, -1, -1):
    if S[i][j] == '#':
      continue
    if j+1 <= W-1:
      cnt1[i][j] = max(cnt1[i][j], cnt1[i][j+1])

cnt1 = np.array(cnt1)
S = S.T
cnt2 = [[0]*H for _ in range(W)]
for i in range(W):
  for j in range(H):
    if S[i][j] == '#':
      continue
    cnt2[i][j] = 1

for i in range(W):
  for j in range(H):
    if S[i][j] == '#':
      continue
    if j-1 >= 0:
      cnt2[i][j] += cnt2[i][j-1]
for i in range(W):
  for j in range(H-1, -1, -1):
    if S[i][j] == '#':
      continue
    if j+1 <= H-1:
      cnt2[i][j] = max(cnt2[i][j], cnt2[i][j+1])
cnt2 = np.array(cnt2).T

cnt = cnt1 + cnt2
print(np.max(cnt)-1)


Fixed submission:
h, w = map(int, input().split())
s = [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):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
s = [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):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)



Fixed submission:
h, w = map(int, input().split())
s = [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):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
moves = [[0,1], [0,-1],[1,0], [-1,0]]

def bfs(b, a):
  light = [[0 for _ in range(w)] for _ in range(h)]
  q = deque([(b, a, (0, 1, 2, 3))])
  ans = 0
  while q:
    y, x, direction= q.popleft()
    light[y][x] = 1
    ans += 1
    
    for i in direction:
      next_y = y + moves[i][0]
      next_x = x + moves[i][1]
      if 0 <= next_y < h and 0 <= next_x < w and s[next_y][next_x] == '.' and light[next_y][next_x] == 0:
        q.append([next_y, next_x, [i]])
  return ans
final_ans = 0
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      final_ans = max(final_ans, bfs(i, j))

print(final_ans)



Fixed submission:
h, w = map(int, input().split())
s = [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):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
moves = [[0,1], [0,-1],[1,0], [-1,0]]

def bfs(b, a):
  light = [[0 for _ in range(w)] for _ in range(h)]
  q = deque([(b, a, (0, 1, 2, 3))])
  ans = 0
  while q:
    y, x, direction= q.popleft()
    light[y][x] = 1
    ans += 1
    
    for i in direction:
      next_y = y + moves[i][0]
      next_x = x + moves[i][1]
      if 0 <= next_y < h and 0 <= next_x < w and s[next_y][next_x] == '.' and light[next_y][next_x] == 0:
        q.append([next_y, next_x, [i]])
  return ans
final_ans = 0
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      final_ans = max(final_ans, bfs(i, j))

print(final_ans)



Fixed submission:
h, w = map(int, input().split())
s = [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):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)

Buggy python submission (verdict: Runtime Error):
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
moves = [[0,1], [0,-1],[1,0], [-1,0]]

def bfs(b, a):
  light = [[0 for _ in range(w)] for _ in range(h)]
  q = deque([(b, a, (0, 1, 2, 3))])
  ans = 0
  while q:
    y, x, direction= q.popleft()
    light[y][x] = 1
    ans += 1
    
    for i in direction:
      next_y = y + moves[i][0]
      next_x = x + moves[i][1]
      if 0 <= next_y < h and 0 <= next_x < w and s[next_y][next_x] == '.' and light[next_y][next_x] == 0:
        q.append([next_y, next_x, [i]])
  return ans
bfs(2, 5)
final_ans = 0
for i in range(h):
  for j in range(w):
    final_ans = max(final_ans, bfs(i, j))

print(final_ans)



Fixed submission:
h, w = map(int, input().split())
s = [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):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)

print(ans)