Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
count_matw = [[0 for w in range(W)]for h in range(H)]
count_math = [[0 for w in range(W)]for h in range(H)]

for h in range(H):
    row = S[h]
    for w in range(W):
        if w > 0 and row[w-1] != '#':
            count_matw[h][w] = count_matw[h][w-1]
            continue
        if '#' in row[w:]:
            obs_i = row[w:].index('#')
            count_matw[h][w] = obs_i
        else:
            count_matw[h][w] = W-w
for w in range(W):
    col = [row[w] for row in S]
    for h in range(H):
        if h > 0 and col[h-1] != '#':
            count_math[h][w] = count_math[h-1][w]
            continue
        if '#' in col[h:]:
            obs_i = col[h:].index('#')
            count_math[h][w] = obs_i
        else:
            count_math[h][w] = H-h
ans = 1
for h in range(H):
    for w in range(W):
        ans = max(ans, count_math[h][w] + count_matw[h][w])
print(ans-1)


Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
count_matw = [[0 for w in range(W)]for h in range(H)]
count_math = [[0 for w in range(W)]for h in range(H)]

for h in range(H):
    count = 0
    for w in range(W):
        if '#' == S[h][w]:
            count = 0
        else:
            count += 1
        count_matw[h][w] = count
    for w in range(W-1, 0, -1):
        if count_matw[h][w-1] == 0:
            continue
        count_matw[h][w-1] = max(count_matw[h][w], count_matw[h][w-1])

for w in range(W):
    count = 0
    for h in range(H):
        if '#' == S[h][w]:
            count = 0
        else:
            count += 1
        count_math[h][w] = count
    for h in range(H-1, 0, -1):
        if count_math[h-1][w] == 0:
            continue
        count_math[h-1][w] = max(count_math[h][w], count_math[h-1][w])
ans = 1
# for h in range(H):
#     for w in range(W):
#         ans = max(ans, count_math[h][w] + count_matw[h][w])
ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])
# print(count_math)
# print(count_matw)
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
ST = [[row[w] for row in S] for w in range(W)]
count_matw = [[0 for w in range(W)]for h in range(H)]
count_math = [[0 for w in range(W)]for h in range(H)]

for h in range(H):
    row = S[h]
    for w in range(W):
        if w > 0 and row[w] != '#' and count_matw[h][w-1] != 0:
            count_matw[h][w] = count_matw[h][w-1]
            continue
        if '#' in row[w:]:
            obs_i = row[w:].index('#')
            count_matw[h][w] = obs_i
        else:
            count_matw[h][w] = W-w
for w in range(W):
    col = ST[w]
    for h in range(H):
        if h > 0 and col[h] != '#' and count_math[h-1][w] != 0:
            count_math[h][w] = count_math[h-1][w]
            continue
        if '#' in col[h:]:
            obs_i = col[h:].index('#')
            count_math[h][w] = obs_i
        else:
            count_math[h][w] = H-h
ans = max([count_math[h][w] + count_matw[h][w]for h in range(H) for w in range(W)])
print(ans-1)


Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
count_matw = [[0 for w in range(W)]for h in range(H)]
count_math = [[0 for w in range(W)]for h in range(H)]

for h in range(H):
    count = 0
    for w in range(W):
        if '#' == S[h][w]:
            count = 0
        else:
            count += 1
        count_matw[h][w] = count
    for w in range(W-1, 0, -1):
        if count_matw[h][w-1] == 0:
            continue
        count_matw[h][w-1] = max(count_matw[h][w], count_matw[h][w-1])

for w in range(W):
    count = 0
    for h in range(H):
        if '#' == S[h][w]:
            count = 0
        else:
            count += 1
        count_math[h][w] = count
    for h in range(H-1, 0, -1):
        if count_math[h-1][w] == 0:
            continue
        count_math[h-1][w] = max(count_math[h][w], count_math[h-1][w])
ans = 1
# for h in range(H):
#     for w in range(W):
#         ans = max(ans, count_math[h][w] + count_matw[h][w])
ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])
# print(count_math)
# print(count_matw)
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
count_matw = [[0 for w in range(W)]for h in range(H)]
count_math = [[0 for w in range(W)]for h in range(H)]

for h in range(H):
    row = S[h]
    for w in range(W):
        if w > 0 and row[w] != '#' and count_matw[h][w-1] != 0:
            count_matw[h][w] = count_matw[h][w-1]
            continue
        if '#' in row[w:]:
            obs_i = row[w:].index('#')
            count_matw[h][w] = obs_i
        else:
            count_matw[h][w] = W-w
for w in range(W):
    col = [row[w] for row in S]
    for h in range(H):
        if h > 0 and col[h] != '#' and count_math[h-1][w] != 0:
            count_math[h][w] = count_math[h-1][w]
            continue
        if '#' in col[h:]:
            obs_i = col[h:].index('#')
            count_math[h][w] = obs_i
        else:
            count_math[h][w] = H-h
ans = 1
for h in range(H):
    for w in range(W):
        ans = max(ans, count_math[h][w] + count_matw[h][w])
# print(count_math)
# print(count_matw)
print(ans-1)


Fixed submission:
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
count_matw = [[0 for w in range(W)]for h in range(H)]
count_math = [[0 for w in range(W)]for h in range(H)]

for h in range(H):
    count = 0
    for w in range(W):
        if '#' == S[h][w]:
            count = 0
        else:
            count += 1
        count_matw[h][w] = count
    for w in range(W-1, 0, -1):
        if count_matw[h][w-1] == 0:
            continue
        count_matw[h][w-1] = max(count_matw[h][w], count_matw[h][w-1])

for w in range(W):
    count = 0
    for h in range(H):
        if '#' == S[h][w]:
            count = 0
        else:
            count += 1
        count_math[h][w] = count
    for h in range(H-1, 0, -1):
        if count_math[h-1][w] == 0:
            continue
        count_math[h-1][w] = max(count_math[h][w], count_math[h-1][w])
ans = 1
# for h in range(H):
#     for w in range(W):
#         ans = max(ans, count_math[h][w] + count_matw[h][w])
ans = max([count_math[h][w] + count_matw[h][w] for h in range(H) for w in range(W)])
# print(count_math)
# print(count_matw)
print(ans-1)