Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
r = [[0] * w for i in range(h)]
l = [[0] * w for i in range(h)]
u = [[0] * w for i in range(h)]
d = [[0] * w for i in range(h)]

for i in range(h):
    s[i] = input()

# cal l
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i][j] = 0
        elif j == 0:
            l[i][j] = 1
        else:
            l[i][j] = l[i][j-1] + 1
# cal r
for i in range(h):
    for j in range(w)[::-1]:
        if s[i][j] == '#':
            r[i][j] = 0
        elif j == w-1:
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1
# cal u
for i in range(w):
    for j in range(h):
        if s[j][i] == '#':
            u[j][i] = 0
        elif j == 0:
            u[j][i] = 1
        else:
            u[j][i] = u[j-1][i] + 1
# cal d
for i in range(w):
    for j in range(h)[::-1]:
        if s[j][i] == '#':
            d[j][i] = 0
        elif j == h-1:
            d[j][i] = 1
        else:
            d[j][i] = d[j+1][i] + 1
ans = 0
# print(l,r,u,d)
for i in range(h):
    for j in range(w):
        ans = max(ans, r[i][j] + l[i][j] + u[i][j] + d[i][j])
print(ans-3)


Fixed submission:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
r = [[0] * w for i in range(h)]
l = [[0] * w for i in range(h)]
u = [[0] * w for i in range(h)]
d = [[0] * w for i in range(h)]

for i in range(h):
    s[i] = input()

# cal l
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i][j] = 0
        elif j == 0:
            l[i][j] = 1
        else:
            l[i][j] = l[i][j-1] + 1
# cal r
for i in range(h):
    for j in range(w)[::-1]:
        if s[i][j] == '#':
            r[i][j] = 0
        elif j == w-1:
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1
# cal u
for i in range(w):
    for j in range(h):
        if s[j][i] == '#':
            u[j][i] = 0
        elif j == 0:
            u[j][i] = 1
        else:
            u[j][i] = u[j-1][i] + 1
# cal d
for i in range(w):
    for j in range(h)[::-1]:
        if s[j][i] == '#':
            d[j][i] = 0
        elif j == h-1:
            d[j][i] = 1
        else:
            d[j][i] = d[j+1][i] + 1
ans = 0
# print(l,r,u,d)
for i in range(h):
    for j in range(w):
        ans = max(ans, r[i][j] + l[i][j] + u[i][j] + d[i][j])
print(ans-3)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
ss = [[0] * w for i in range(h)]
st = [[0] * w for i in range(h)]
for i in range(h):
    s[i] = input()

for i in range(h):
    cnt = 0
    start = w
    end = w
    for j in range(w)[::-1]:
        if s[i][j] == '.':
            cnt += 1
            start = j
        else:
            for k in range(start,end):
                ss[i][k] = cnt
            cnt = 0
            end = j
        if cnt > 0:
            for k in range(start,end):
                ss[i][k] = cnt
for i in range(w):
    cnt = 0
    start = h
    end = h
    for j in range(h)[::-1]:
        if s[j][i] == '.':
            cnt += 1
            start = j
        else:
            for k in range(start,end):
                st[k][i] = cnt
            cnt = 0
            end = j
        if cnt > 0:
            for k in range(start,end):
                st[k][i] = cnt
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, ss[i][j] + st[i][j])
print(ans-1)


Fixed submission:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
r = [[0] * w for i in range(h)]
l = [[0] * w for i in range(h)]
u = [[0] * w for i in range(h)]
d = [[0] * w for i in range(h)]

for i in range(h):
    s[i] = input()

# cal l
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i][j] = 0
        elif j == 0:
            l[i][j] = 1
        else:
            l[i][j] = l[i][j-1] + 1
# cal r
for i in range(h):
    for j in range(w)[::-1]:
        if s[i][j] == '#':
            r[i][j] = 0
        elif j == w-1:
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1
# cal u
for i in range(w):
    for j in range(h):
        if s[j][i] == '#':
            u[j][i] = 0
        elif j == 0:
            u[j][i] = 1
        else:
            u[j][i] = u[j-1][i] + 1
# cal d
for i in range(w):
    for j in range(h)[::-1]:
        if s[j][i] == '#':
            d[j][i] = 0
        elif j == h-1:
            d[j][i] = 1
        else:
            d[j][i] = d[j+1][i] + 1
ans = 0
# print(l,r,u,d)
for i in range(h):
    for j in range(w):
        ans = max(ans, r[i][j] + l[i][j] + u[i][j] + d[i][j])
print(ans-3)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
ss = [[0] * w for i in range(h)]
st = [[0] * w for i in range(h)]
for i in range(h):
    s[i] = input()

for i in range(h):
    cnt = 0
    start = w
    end = w
    for j in range(w)[::-1]:
        if s[i][j] == '.':
            cnt += 1
            start = j
        else:
            for k in range(start,end):
                ss[i][k] = cnt
            cnt = 0
            end = j
        if cnt > 0:
            for k in range(start,end):
                ss[i][k] = cnt
for i in range(w):
    cnt = 0
    start = h
    end = h
    for j in range(h)[::-1]:
        if s[j][i] == '.':
            cnt += 1
            start = j
        else:
            for k in range(start,end):
                st[k][i] = cnt
            cnt = 0
            end = j
        if cnt > 0:
            for k in range(start,end):
                st[k][i] = cnt
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, ss[i][j] + st[i][j])
print(ans-1)


Fixed submission:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
r = [[0] * w for i in range(h)]
l = [[0] * w for i in range(h)]
u = [[0] * w for i in range(h)]
d = [[0] * w for i in range(h)]

for i in range(h):
    s[i] = input()

# cal l
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            l[i][j] = 0
        elif j == 0:
            l[i][j] = 1
        else:
            l[i][j] = l[i][j-1] + 1
# cal r
for i in range(h):
    for j in range(w)[::-1]:
        if s[i][j] == '#':
            r[i][j] = 0
        elif j == w-1:
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1
# cal u
for i in range(w):
    for j in range(h):
        if s[j][i] == '#':
            u[j][i] = 0
        elif j == 0:
            u[j][i] = 1
        else:
            u[j][i] = u[j-1][i] + 1
# cal d
for i in range(w):
    for j in range(h)[::-1]:
        if s[j][i] == '#':
            d[j][i] = 0
        elif j == h-1:
            d[j][i] = 1
        else:
            d[j][i] = d[j+1][i] + 1
ans = 0
# print(l,r,u,d)
for i in range(h):
    for j in range(w):
        ans = max(ans, r[i][j] + l[i][j] + u[i][j] + d[i][j])
print(ans-3)