Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Fixed submission:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1
for x in range(w):
    for y in range(h):
        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Fixed submission:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
for y in range(h - 1, -1, -1):
    for x in range(w - 1, -1, -1):
        if ls[y][x] == '#':
            counts[1][y][x] = 0
        else:
            if x == w - 1:
                counts[1][y][x] = 1
            else:
                counts[1][y][x] = counts[1][y][x + 1] + 1
for x in range(w):
    for y in range(h):
        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
for x in range(w - 1, -1, -1):
    for y in range(h - 1, -1, -1):
        if ls[y][x] == '#':
            counts[3][y][x] = 0
        else:
            if y == h - 1:
                counts[3][y][x] = 1
            else:
                counts[3][y][x] = counts[3][y + 1][x] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Fixed submission:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
lrs = []
tbs = []

for y in range(h):
    left = 0
    while left < w:
        if ls[y][left] == '#':
            left += 1
            continue
        right = left
        while right < w:
            right += 1
            if right == w or ls[y][right] == '#':
                lrs.append([y, left, right, right - left])
                break
        left = right

for x in range(w):
    top = 0
    while top < h:
        if ls[top][x] == '#':
            top += 1
            continue
        bottom = top
        while bottom < h:
            bottom += 1
            if bottom == h or ls[bottom][x] == '#':
                tbs.append([x, top, bottom, bottom - top])
                break
        top = bottom
lrs.sort(key=lambda x: x[3], reverse=True)
tbs.sort(key=lambda x: x[3], reverse=True)

res = 0
for y, left, right, lh in lrs:
    for x, top, bottom, lv in tbs:
        if lh + lv - 1 <= res:
            break
        if top <= y <= bottom and left <= x <= right:
            res = max(res, lh + lv - 1)
            break
print(res)

Fixed submission:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
lrs = []
tbs = []

for y in range(h):
    left = 0
    while left < w:
        if ls[y][left] == '#':
            left += 1
            continue
        right = left
        while right < w:
            right += 1
            if right == w or ls[y][right] == '#':
                lrs.append([y, left, right, right - left])
                break
        left = right

for x in range(w):
    top = 0
    while top < h:
        if ls[top][x] == '#':
            top += 1
            continue
        bottom = top
        while bottom < h:
            bottom += 1
            if bottom == h or ls[bottom][x] == '#':
                tbs.append([x, top, bottom, bottom - top])
                break
        top = bottom
lrs.sort(key=lambda x: x[3], reverse=True)
tbs.sort(key=lambda x: x[3], reverse=True)

res = 0
for y, left, right, lh in lrs:
    for x, top, bottom, lv in tbs:
        if lh + lv - 1 <= res:
            break
        if top <= y <= bottom and left <= x <= right:
            res = max(res, lh + lv - 1)
            break
print(res)

Fixed submission:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
lrs = []
tbs = []

for y in range(h):
    left = 0
    while left < w:
        if ls[y][left] == '#':
            left += 1
            continue
        right = left
        while right < w:
            right += 1
            if right == w or ls[y][right] == '#':
                lrs.append([y, left, right, right - left])
                break
        left = right

for x in range(w):
    top = 0
    while top < h:
        if ls[top][x] == '#':
            top += 1
            continue
        bottom = top
        while bottom < h:
            bottom += 1
            if bottom == h or ls[bottom][x] == '#':
                tbs.append([x, top, bottom, bottom - top])
                break
        top = bottom
lrs.sort(key=lambda x: x[3], reverse=True)
tbs.sort(key=lambda x: x[3], reverse=True)

res = 0
for y, left, right, lh in lrs:
    for x, top, bottom, lv in tbs:
        if top <= y <= bottom and left <= x <= right:
            res = max(res, lh + lv - 1)
            break
print(res)

Fixed submission:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

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

h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
lrs = [[] for _ in range(h)]
tbs = [[] for _ in range(w)]

for y in range(h):
    left = 0
    while left < w:
        if ls[y][left] == '#':
            left += 1
            continue
        right = left
        while right < w:
            right += 1
            if right == w or ls[y][right] == '#':
                lrs[y].append(left)
                lrs[y].append(right)
                break
        left = right

for x in range(w):
    top = 0
    while top < h:
        if ls[top][x] == '#':
            top += 1
            continue
        bottom = top
        while bottom < h:
            bottom += 1
            if bottom == h or ls[bottom][x] == '#':
                tbs[x].append(top)
                tbs[x].append(bottom)
                break
        top = bottom
res = 0
for y in range(h):
    for x in range(w):
        j = bisect.bisect(lrs[y], x)
        if j % 2 == 0:
            continue
        i = bisect.bisect(tbs[x], y)
        val = lrs[y][j] - lrs[y][j - 1] + tbs[x][i] - tbs[x][i - 1] - 1
        res = max(res, val)
print(res)

Fixed submission:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
xs = [[-1] * w for _ in range(h)]
ys = [[-1] * w for _ in range(h)]
for y in range(h):
    for x in range(w):
        if xs[y][x] >= 0 and ys[y][x] >= 0:
            continue
        if ls[y][x] == '#':
            xs[y][x] = 0
            ys[y][x] = 0
        if xs[y][x] == -1:
            count = 0
            while x + count < w:
                c2 = ls[y][x + count]
                if c2 == '.':
                    count += 1
                else:
                    break
            for i in range(count):
                xs[y][x + i] = count
        if ys[y][x] == -1:
            count = 0
            while y + count < h:
                c2 = ls[y + count][x]
                if c2 == '.':
                    count += 1
                else:
                    break
            for i in range(count):
                ys[y + i][x] = count
res = 0
for y in range(h):
    for x in range(w):
        res = max(res, xs[y][x] + ys[y][x] - 1)
print(res)

Fixed submission:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)