Buggy python submission (verdict: Time Limit Exceeded):
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [input().rstrip() for _ in range(H)]
# for m in M:
# 	print(m)

O = []
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': O.append([i, j])

# print(O)

DU = [-1,1]
LR = [-1,1]
D = [[0]*W for _ in range(H)]
memo = [[-1]*W for _ in range(H)]
ans = 0
for i in range(H):
	for j in range(W):
		if M[i][j] == '#':
			D[i][j] = 9
			continue
		tmp = [0,0]
		
		skip = -1
		if memo[i-1][j] != -1:
			tmp[0] = memo[i-1][j][0]
			skip = 1
			D[i][j] = 1
		if memo[i][j-1] != -1:
			tmp[1] = memo[i][j-1][1]
			skip = 5 if skip == 1 else 2
			D[i][j] = 5 if D[i][j]==1 else 2
		
		if skip == 1 or skip == -1:
			lr = 0
			for idx,move in enumerate(LR):
				nw = j
				dw = move
				while True:
					nw += dw
					# print(i, j, nh, nw)
					if nw>W-1 or nw<0 or M[i][nw] == '#': break
					lr += 1
				tmp[1] = lr

		if skip == 2 or skip == -1:
			du = 0
			for idx,move in enumerate(DU):
				nh = i
				dh = move
				while True:
					nh += dh
					# print(i, j, nh, nw)
					if nh>H-1 or nh<0 or M[nh][j] == '#': break
					du += 1
				tmp[0] = du
		
		memo[i][j] = tmp
		ans = max(ans, sum(tmp)+1)
	
# for mem in memo:
# 	print(mem)
# for m in M:
# 	print(m)
# for d in D:
# 	print(d)
print(ans)

Fixed submission:
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	M = [input().rstrip() for _ in range(H)]

	DU = tuple([-1,1])
	LR = tuple([-1,1])
	memo = [[-1]*W for _ in range(H)]
	ans = 0
	for i in range(H):
		for j in range(W):
			if M[i][j] == '#': continue
			tmp = [0,0]
			
			skip = -1
			if memo[i-1][j] != -1:
				tmp[0] = memo[i-1][j][0]
				skip = 1
			if memo[i][j-1] != -1:
				tmp[1] = memo[i][j-1][1]
				skip = 5 if skip == 1 else 2
			
			if skip == 1 or skip == -1:
				lr = 0
				for move in LR:
					nw = j
					dw = move
					while True:
						nw += dw
						# print(i, j, nh, nw)
						if nw>W-1 or nw<0 or M[i][nw] == '#': break
						lr += 1
					tmp[1] = lr

			if skip == 2 or skip == -1:
				du = 0
				for move in DU:
					nh = i
					dh = move
					while True:
						nh += dh
						# print(i, j, nh, nw)
						if nh>H-1 or nh<0 or M[nh][j] == '#': break
						du += 1
					tmp[0] = du
			
			memo[i][j] = tuple(tmp)
			ans = max(ans, sum(tmp)+1)
		
	# for mem in memo:
	# 	print(mem)
	# for m in M:
	# 	print(m)
	print(ans)

if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [input().rstrip() for _ in range(H)]
# for m in M:
# 	print(m)

O = []
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': O.append([i, j])

# print(O)

MOVE = [[-1,0],[1,0],[0,-1],[0,1]]

memo = [[-1]*W for _ in range(H)]
ans = 0
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': continue
		tmp = [0,0,0,0]
		skip = []
		if memo[i-1][j] != -1:
			tmp[0] = memo[i-1][j][0]
			tmp[1] = memo[i-1][j][1]
			skip.extend([0, 1])
		if memo[i][j-1] != -1:
			tmp[2] = memo[i][j-1][2]
			tmp[3] = memo[i][j-1][3]
			skip.extend([2, 3])
		for idx,move in enumerate(MOVE):
			if idx in skip:
				# print('skipping')
				continue
			cnt = 0
			nh, nw = i, j
			dh, dw = move
			while True:
				nh += dh
				nw += dw
				# print(i, j, nh, nw)
				if nh>H-1 or nh<0 or nw>W-1 or nw<0: break
				if M[nh][nw] == '#': break
				cnt += 1
			tmp[idx] = cnt
		memo[i][j] = tmp
		ans = max(ans, sum(tmp)+1)
	
print(ans)
# print(memo)

Fixed submission:
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	M = [input().rstrip() for _ in range(H)]

	DU = tuple([-1,1])
	LR = tuple([-1,1])
	memo = [[-1]*W for _ in range(H)]
	ans = 0
	for i in range(H):
		for j in range(W):
			if M[i][j] == '#': continue
			tmp = [0,0]
			
			skip = -1
			if memo[i-1][j] != -1:
				tmp[0] = memo[i-1][j][0]
				skip = 1
			if memo[i][j-1] != -1:
				tmp[1] = memo[i][j-1][1]
				skip = 5 if skip == 1 else 2
			
			if skip == 1 or skip == -1:
				lr = 0
				for move in LR:
					nw = j
					dw = move
					while True:
						nw += dw
						# print(i, j, nh, nw)
						if nw>W-1 or nw<0 or M[i][nw] == '#': break
						lr += 1
					tmp[1] = lr

			if skip == 2 or skip == -1:
				du = 0
				for move in DU:
					nh = i
					dh = move
					while True:
						nh += dh
						# print(i, j, nh, nw)
						if nh>H-1 or nh<0 or M[nh][j] == '#': break
						du += 1
					tmp[0] = du
			
			memo[i][j] = tuple(tmp)
			ans = max(ans, sum(tmp)+1)
		
	# for mem in memo:
	# 	print(mem)
	# for m in M:
	# 	print(m)
	print(ans)

if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [input().rstrip() for _ in range(H)]
# for m in M:
# 	print(m)

O = []
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': O.append([i, j])

# print(O)

MOVE = [[-1,0],[1,0],[0,-1],[0,1]]

ans = 0
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': continue
		cnt = 1 # 自分
		for move in MOVE:
			nh, nw = i, j
			dh, dw = move
			while True:
				nh += dh
				nw += dw
				# print(i, j, nh, nw)
				if nh>H-1 or nh<0 or nw>W-1 or nw<0: break
				if M[nh][nw] == '#': break
				cnt += 1
		ans = max(ans, cnt)
	
print(ans)

Fixed submission:
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	M = [input().rstrip() for _ in range(H)]

	DU = tuple([-1,1])
	LR = tuple([-1,1])
	memo = [[-1]*W for _ in range(H)]
	ans = 0
	for i in range(H):
		for j in range(W):
			if M[i][j] == '#': continue
			tmp = [0,0]
			
			skip = -1
			if memo[i-1][j] != -1:
				tmp[0] = memo[i-1][j][0]
				skip = 1
			if memo[i][j-1] != -1:
				tmp[1] = memo[i][j-1][1]
				skip = 5 if skip == 1 else 2
			
			if skip == 1 or skip == -1:
				lr = 0
				for move in LR:
					nw = j
					dw = move
					while True:
						nw += dw
						# print(i, j, nh, nw)
						if nw>W-1 or nw<0 or M[i][nw] == '#': break
						lr += 1
					tmp[1] = lr

			if skip == 2 or skip == -1:
				du = 0
				for move in DU:
					nh = i
					dh = move
					while True:
						nh += dh
						# print(i, j, nh, nw)
						if nh>H-1 or nh<0 or M[nh][j] == '#': break
						du += 1
					tmp[0] = du
			
			memo[i][j] = tuple(tmp)
			ans = max(ans, sum(tmp)+1)
		
	# for mem in memo:
	# 	print(mem)
	# for m in M:
	# 	print(m)
	print(ans)

if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [input().rstrip() for _ in range(H)]
# for m in M:
# 	print(m)

O = []
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': O.append([i, j])

# print(O)

MOVE = [[-1,0],[1,0],[0,-1],[0,1]]

ans = 0
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': continue
		cnt = 1 # 自分
		for move in MOVE:
			nh, nw = i, j
			dh, dw = move
			while True:
				nh += dh
				nw += dw
				# print(i, j, nh, nw)
				if nh>H-1 or nh<0 or nw>W-1 or nw<0: break
				if M[nh][nw] == '#': break
				cnt += 1
		ans = max(ans, cnt)
	
print(ans)

Fixed submission:
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	M = [input().rstrip() for _ in range(H)]

	DU = tuple([-1,1])
	LR = tuple([-1,1])
	memo = [[-1]*W for _ in range(H)]
	ans = 0
	for i in range(H):
		for j in range(W):
			if M[i][j] == '#': continue
			tmp = [0,0]
			
			skip = -1
			if memo[i-1][j] != -1:
				tmp[0] = memo[i-1][j][0]
				skip = 1
			if memo[i][j-1] != -1:
				tmp[1] = memo[i][j-1][1]
				skip = 5 if skip == 1 else 2
			
			if skip == 1 or skip == -1:
				lr = 0
				for move in LR:
					nw = j
					dw = move
					while True:
						nw += dw
						# print(i, j, nh, nw)
						if nw>W-1 or nw<0 or M[i][nw] == '#': break
						lr += 1
					tmp[1] = lr

			if skip == 2 or skip == -1:
				du = 0
				for move in DU:
					nh = i
					dh = move
					while True:
						nh += dh
						# print(i, j, nh, nw)
						if nh>H-1 or nh<0 or M[nh][j] == '#': break
						du += 1
					tmp[0] = du
			
			memo[i][j] = tuple(tmp)
			ans = max(ans, sum(tmp)+1)
		
	# for mem in memo:
	# 	print(mem)
	# for m in M:
	# 	print(m)
	print(ans)

if __name__ == "__main__":
	main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

H, W = MAP()
M = [input().rstrip() for _ in range(H)]
# for m in M:
# 	print(m)

O = []
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': O.append([i, j])

# print(O)

ans = 0
for i in range(H):
	for j in range(W):
		if M[i][j] == '#': continue
		u = i
		d = H-i-1
		l = j
		r = W-j-1
		# print(u,d,l,r, " / i, j:", i,j)
		for o in O:
			oh, ow = o
			if oh==i:
				# 障害物が同じ行の右側にある場合
				if ow > j:
					r = min(r, ow-j-1)
				# 障害物が同じ行の左側にある場合
				else:
					l = min(l, j-ow-1)
			if ow==j:
				# 障害物が同じ列の上側にある場合
				if oh < i:
					u = min(u, i-oh-1)
				# 障害物が同じ列の下側にある場合
				else:
					d = min(d, oh-i-1)
		# print(u,d,l,r)
		ans = max(ans, sum([u, d, l, r])+1)
	
print(ans)

Fixed submission:
import sys

if sys.platform in ['ios','win32','darwin']:
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	H, W = MAP()
	M = [input().rstrip() for _ in range(H)]

	DU = tuple([-1,1])
	LR = tuple([-1,1])
	memo = [[-1]*W for _ in range(H)]
	ans = 0
	for i in range(H):
		for j in range(W):
			if M[i][j] == '#': continue
			tmp = [0,0]
			
			skip = -1
			if memo[i-1][j] != -1:
				tmp[0] = memo[i-1][j][0]
				skip = 1
			if memo[i][j-1] != -1:
				tmp[1] = memo[i][j-1][1]
				skip = 5 if skip == 1 else 2
			
			if skip == 1 or skip == -1:
				lr = 0
				for move in LR:
					nw = j
					dw = move
					while True:
						nw += dw
						# print(i, j, nh, nw)
						if nw>W-1 or nw<0 or M[i][nw] == '#': break
						lr += 1
					tmp[1] = lr

			if skip == 2 or skip == -1:
				du = 0
				for move in DU:
					nh = i
					dh = move
					while True:
						nh += dh
						# print(i, j, nh, nw)
						if nh>H-1 or nh<0 or M[nh][j] == '#': break
						du += 1
					tmp[0] = du
			
			memo[i][j] = tuple(tmp)
			ans = max(ans, sum(tmp)+1)
		
	# for mem in memo:
	# 	print(mem)
	# for m in M:
	# 	print(m)
	print(ans)

if __name__ == "__main__":
	main()