Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

grid = []

for i in range(H):
    s = input()
    r = []
    for j, x in enumerate(s):
        r.append(x)

    grid.append(r)


H_cnt = [[0] * W for _ in range(H)]
W_cnt = [[0] * W for _ in range(H)]

for r in range(H):
    idx = 0

    while idx < W:
        if grid[r][idx] == '.' and (idx == 0 or grid[r][idx - 1] == '#'):
            cnt = 1
            st = idx
            if idx == W - 1 or grid[r][idx + 1] == '#':
                W_cnt[r][idx] = 1
        elif grid[r][idx] == '.' and (idx == W - 1 or grid[r][idx + 1] == '#'):
            cnt += 1
            for i in range(st, idx + 1):
                W_cnt[r][i] = cnt
        elif grid[r][idx] == '.':
            cnt += 1
        elif grid[r][idx] == '#':
            pass

        idx += 1

for c in range(W):
    idx = 0

    while idx < H:
        if grid[idx][c] == '.' and (idx == 0 or grid[idx - 1][c] == '#'):
            cnt = 1
            st = idx
            if idx == H - 1 or grid[idx + 1][c] == '#':
                H_cnt[idx][c] = 1
        elif grid[idx][c] == '.' and (idx == H - 1 or grid[idx + 1][c] == '#'):
            cnt += 1
            for i in range(st, idx + 1):
                H_cnt[i][c] = cnt
        elif grid[idx][c] == '.':
            cnt += 1
        elif grid[idx][c] == '#':
            pass

        idx += 1

max_ = 0
for r in range(H):
    for c in range(W):
        max_ = max(max_, W_cnt[r][c] + H_cnt[r][c] - 1)

print(max_)


Fixed submission:
H, W = map(int, input().split())

grid = []

for i in range(H):
    s = input()
    r = []
    for j, x in enumerate(s):
        r.append(x)

    grid.append(r)


H_cnt = [[0] * W for _ in range(H)]
W_cnt = [[0] * W for _ in range(H)]

for r in range(H):
    idx = 0

    while idx < W:
        if grid[r][idx] == '.' and (idx == 0 or grid[r][idx - 1] == '#'):
            cnt = 1
            st = idx
            if idx == W - 1 or grid[r][idx + 1] == '#':
                W_cnt[r][idx] = 1
        elif grid[r][idx] == '.' and (idx == W - 1 or grid[r][idx + 1] == '#'):
            cnt += 1
            for i in range(st, idx + 1):
                W_cnt[r][i] = cnt
        elif grid[r][idx] == '.':
            cnt += 1
        elif grid[r][idx] == '#':
            pass

        idx += 1

for c in range(W):
    idx = 0

    while idx < H:
        if grid[idx][c] == '.' and (idx == 0 or grid[idx - 1][c] == '#'):
            cnt = 1
            st = idx
            if idx == H - 1 or grid[idx + 1][c] == '#':
                H_cnt[idx][c] = 1
        elif grid[idx][c] == '.' and (idx == H - 1 or grid[idx + 1][c] == '#'):
            cnt += 1
            for i in range(st, idx + 1):
                H_cnt[i][c] = cnt
        elif grid[idx][c] == '.':
            cnt += 1
        elif grid[idx][c] == '#':
            pass

        idx += 1

max_ = 0
for r in range(H):
    for c in range(W):
        max_ = max(max_, W_cnt[r][c] + H_cnt[r][c] - 1)

print(max_)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)]

M = [[[0, 0] for i in range(W)] for j in range(H)]
V = [[[False, False] for i in range(W)] for j in range(H)]

def search(grid, w, h, direction):
    cnt = 0

    if direction == 'W':
        for _ in range(W):
            if w + cnt + 1 == W:
                break
            elif grid[h][w + cnt + 1] == '#':
                break

            cnt += 1

    if direction == 'H':
        for _ in range(H):
            if h + cnt + 1 == H:
                break
            elif grid[h + cnt + 1][w] == '#':
                break

            cnt += 1

    return cnt


for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            continue
        else:
            if not V[h][w][1]:
                cnt = search(grid, w, h, 'W')

                for i in range(cnt + 1):
                    V[h][w + i][1] = True
                    M[h][w + i][1] = cnt

for w in range(W):
    for h in range(H):
        if grid[h][w] == '#':
            continue
        else:
            if not V[h][w][0]:
                cnt = search(grid, w, h, 'H')

                for i in range(cnt + 1):
                    V[h + i][w][0] = True
                    M[h + i][w][0] = cnt

m = -1
for h in range(H):
    for w in range(W):
        if M[h][w][0] + M[h][w][1] > m:
            m = M[h][w][0] + M[h][w][1] + 1

print(m)


Fixed submission:
H, W = map(int, input().split())

grid = []

for i in range(H):
    s = input()
    r = []
    for j, x in enumerate(s):
        r.append(x)

    grid.append(r)


H_cnt = [[0] * W for _ in range(H)]
W_cnt = [[0] * W for _ in range(H)]

for r in range(H):
    idx = 0

    while idx < W:
        if grid[r][idx] == '.' and (idx == 0 or grid[r][idx - 1] == '#'):
            cnt = 1
            st = idx
            if idx == W - 1 or grid[r][idx + 1] == '#':
                W_cnt[r][idx] = 1
        elif grid[r][idx] == '.' and (idx == W - 1 or grid[r][idx + 1] == '#'):
            cnt += 1
            for i in range(st, idx + 1):
                W_cnt[r][i] = cnt
        elif grid[r][idx] == '.':
            cnt += 1
        elif grid[r][idx] == '#':
            pass

        idx += 1

for c in range(W):
    idx = 0

    while idx < H:
        if grid[idx][c] == '.' and (idx == 0 or grid[idx - 1][c] == '#'):
            cnt = 1
            st = idx
            if idx == H - 1 or grid[idx + 1][c] == '#':
                H_cnt[idx][c] = 1
        elif grid[idx][c] == '.' and (idx == H - 1 or grid[idx + 1][c] == '#'):
            cnt += 1
            for i in range(st, idx + 1):
                H_cnt[i][c] = cnt
        elif grid[idx][c] == '.':
            cnt += 1
        elif grid[idx][c] == '#':
            pass

        idx += 1

max_ = 0
for r in range(H):
    for c in range(W):
        max_ = max(max_, W_cnt[r][c] + H_cnt[r][c] - 1)

print(max_)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)]

M = [[[0, 0] for i in range(W)] for j in range(H)]
V = [[[False, False] for i in range(W)] for j in range(H)]


def search(grid, h, w, H, W, V_lst):
    h_cnt = 0
    v_cnt = 0

    if w != W and not V_lst[1]:
        for _ in range(W):
            if grid[h][w + h_cnt] != '#':
                h_cnt += 1
                if w + h_cnt == W:
                    break

    if h != H and not V_lst[0]:
        for _ in range(H):
            if grid[h + v_cnt][w] != '#':
                v_cnt += 1
                if h + v_cnt == H:
                    break

    return h_cnt, v_cnt

for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            continue
        else:
            h_cnt, v_cnt = search(grid, h, w, H, W, V[h][w])

            for i in range(h_cnt):
                V[h][w + i][1] = True
                M[h][w + i][1] = h_cnt - 1

            for i in range(v_cnt):
                V[h + i][w][0] = True
                M[h + i][w][0] = v_cnt - 1

m = -1
for h in range(H):
    for w in range(W):
        if M[h][w][0] + M[h][w][1] > m:
            m = M[h][w][0] + M[h][w][1] + 1

print(m)

Fixed submission:
H, W = map(int, input().split())

grid = []

for i in range(H):
    s = input()
    r = []
    for j, x in enumerate(s):
        r.append(x)

    grid.append(r)


H_cnt = [[0] * W for _ in range(H)]
W_cnt = [[0] * W for _ in range(H)]

for r in range(H):
    idx = 0

    while idx < W:
        if grid[r][idx] == '.' and (idx == 0 or grid[r][idx - 1] == '#'):
            cnt = 1
            st = idx
            if idx == W - 1 or grid[r][idx + 1] == '#':
                W_cnt[r][idx] = 1
        elif grid[r][idx] == '.' and (idx == W - 1 or grid[r][idx + 1] == '#'):
            cnt += 1
            for i in range(st, idx + 1):
                W_cnt[r][i] = cnt
        elif grid[r][idx] == '.':
            cnt += 1
        elif grid[r][idx] == '#':
            pass

        idx += 1

for c in range(W):
    idx = 0

    while idx < H:
        if grid[idx][c] == '.' and (idx == 0 or grid[idx - 1][c] == '#'):
            cnt = 1
            st = idx
            if idx == H - 1 or grid[idx + 1][c] == '#':
                H_cnt[idx][c] = 1
        elif grid[idx][c] == '.' and (idx == H - 1 or grid[idx + 1][c] == '#'):
            cnt += 1
            for i in range(st, idx + 1):
                H_cnt[i][c] = cnt
        elif grid[idx][c] == '.':
            cnt += 1
        elif grid[idx][c] == '#':
            pass

        idx += 1

max_ = 0
for r in range(H):
    for c in range(W):
        max_ = max(max_, W_cnt[r][c] + H_cnt[r][c] - 1)

print(max_)