Problem p03014 (python)

Fixed submission:
H, W = map(int, input().split())
s, ans = [], 0
dpr = [[0] * W for _ in range(H)]
dpl = [[0] * W for _ in range(H)]
dpd = [[0] * W for _ in range(H)]
dpu = [[0] * W for _ in range(H)]

for i in range(H):
    s.append(input())

# to right
for i in range(H):
    for j in reversed(range(W)):
        if j == W-1 and s[i][j] == '.':
            dpr[i][j] = 1
        elif s[i][j] == '#':
            dpr[i][j] = 0
        else:
            dpr[i][j] = dpr[i][j+1] + 1

# to left
for i in range(H):
    for j in range(0, W):
        if j == 0 and s[i][j] == '.':
            dpl[i][j] = 1
        elif s[i][j] == '#':
            dpl[i][j] = 0
        else:
            dpl[i][j] = dpl[i][j-1] + 1

# to down
for i in reversed(range(H)):
    for j in range(W):
        if i == H-1 and s[i][j] == '.':
            dpd[i][j] = 1
        elif s[i][j] == '#':
            dpd[i][j] = 0
        else:
            dpd[i][j] = dpd[i+1][j] + 1

# to up
for i in range(0, H):
    for j in range(W):
        if i == 0 and s[i][j] == '.':
            dpu[i][j] = 1
        elif s[i][j] == '#':
            dpu[i][j] = 0
        else:
            dpu[i][j] = dpu[i-1][j] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        cnt = dpr[i][j] + dpl[i][j] + dpd[i][j] + dpu[i][j] - 3
        ans = max(ans, cnt)

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, ans = [], 0
dpr = [[None] * W for _ in range(H)]
dpl = [[None] * W for _ in range(H)]
dpd = [[None] * W for _ in range(H)]
dpu = [[None] * W for _ in range(H)]

for i in range(H):
    s.append(input())

# to right
for i in range(H):
    for j in reversed(range(W-1)):
        if s[i][j] == '#':
            dpr[i][j] = 0
        else:
            dpr[i][j] = dpr[i][j+1] + 1

# to left
for i in range(H):
    for j in range(1, W):
        if s[i][j] == '#':
            dpl[i][j] = 0
        else:
            dpl[i][j] = dpr[i][j-1] + 1

# to down
for i in reversed(range(H-1)):
    for j in range(W):
        if s[i][j] == '#':
            dpd[i][j] = 0
        else:
            dpd[i][j] = dpd[i+1][j] + 1

# to up
for i in range(1, H):
    for j in range(W):
        if s[i][j] == '#':
            dpu[i][j] = 0
        else:
            dpu[i][j] = dpu[i-1][j] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        cnt = dpr[i][j] + dpl[i][j] + dpd[i][j] + dpu[i][j] - 3
        ans = max(ans, cnt)

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, ans = [], 0
dpr = [[None] * W for _ in range(H)]
dpl = [[None] * W for _ in range(H)]
dpd = [[None] * W for _ in range(H)]
dpu = [[None] * W for _ in range(H)]

for i in range(H):
    s.append(input())

# to right
for i in range(H):
    for j in reversed(range(W-1)):
        if s[i][j] == '#':
            dpr[i][j] = 0
        else:
            dpr[i][j] = dpr[i][j+1] + 1

# to left
for i in range(H):
    for j in range(1, W):
        if s[i][j] == '#':
            dpl[i][j] = 0
        else:
            dpl[i][j] = dpr[i][j-1] + 1

# to down
for i in reversed(range(H-1)):
    for j in range(W):
        if s[i][j] == '#':
            dpd[i][j] = 0
        else:
            dpd[i][j] = dpd[i+1][j] + 1

# to up
for i in range(1, H):
    for j in range(W):
        if s[i][j] == '#':
            dpu[i][j] = 0
        else:
            dpu[i][j] = dpu[i-1][j] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        cnt = dpr[i][j] + dpl[i][j] + dpd[i][j] + dpu[i][j] - 3
        ans = max(ans, cnt)

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    if w > 0 and s[h][w-1] == '.' and s[h][w] == '.' and dpr[h][w-1] is not None:
        dpr[h][w] = dpr[h][w-1] - 1
    else:
        for i in range(w+1, W):
            if s[h][i] == '.':
                if dpr[h][i] is not None:
                    rcnt += dpr[h][i] + 1
                    break
                else:
                    rcnt += 1
            else:
                break
        dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
        dpl[h][w] = lcnt

    # to down
    if h > 0 and s[h-1][w] == '.' and s[h][w] == '.' and dpd[h-1][w] is not None:
        dpd[h][w] = dpd[h-1][w] - 1
    else:
        for i in range(h+1, H):
            if s[i][w] == '.':
                if dpr[i][w] is not None:
                    dcnt += dpd[i][w] + 1
                    break
                else:
                    dcnt += 1
            else:
                break
        dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
        dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    if w > 0 and s[h][w-1] == '.' and s[h][w] == '.' and dpr[h][w-1] is not None:
        dpr[h][w] = dpr[h][w-1] - 1
    else:
        for i in range(w+1, W):
            if s[h][i] == '.':
                if dpr[h][i] is not None:
                    rcnt += dpr[h][i] + 1
                    break
                else:
                    rcnt += 1
            else:
                break
        dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
        dpl[h][w] = lcnt

    # to down
    if h > 0 and s[h-1][w] == '.' and s[h][w] == '.' and dpr[h-1][w] is not None:
        dpr[h][w] = dpr[h-1][w] - 1
    else:
        for i in range(h+1, H):
            if s[i][w] == '.':
                if dpr[i][w] is not None:
                    dcnt += dpd[i][w] + 1
                    break
                else:
                    dcnt += 1
            else:
                break
        dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
        dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    if w > 0 and s[h][w-1] == '.' and s[h][w] == '.' and dpr[h][w-1] is not None:
        dpr[h][w] = dpr[h][w-1] - 1
    else:
        for i in range(w+1, W):
            if s[h][i] == '.':
                if dpr[h][i] is not None:
                    rcnt += dpr[h][i] + 1
                    break
                else:
                    rcnt += 1
            else:
                break
    dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
    dpl[h][w] = lcnt

    # to down
    if h > 0 and s[h-1][w] == '.' and s[h][w] == '.' and dpr[h-1][w] is not None:
        dpr[h][w] = dpr[h-1][w] - 1
    else:
        for i in range(h+1, H):
            if s[i][w] == '.':
                if dpr[i][w] is not None:
                    dcnt += dpd[i][w] + 1
                    break
                else:
                    dcnt += 1
            else:
                break
    dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
    dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    # if w > 0 and s[h][w-1] == '.' and s[h][w] == '.' and dpr[h][w-1] is not None:
    #     dpr[h][w] = dpr[h][w-1] - 1
    # else:
    for i in range(w+1, W):
        if s[h][i] == '.':
            if dpr[h][i] is not None:
                rcnt += dpr[h][i] + 1
                break
            else:
                rcnt += 1
        else:
            break
    dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
    dpl[h][w] = lcnt

    # to down
    for i in range(h+1, H):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                dcnt += dpd[i][w] + 1
                break
            else:
                dcnt += 1
        else:
            break
    dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
    dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    for i in range(w+1, W):
        key = str(h) + str(i)
        if s[h][i] == '.':
            if dpr[h][i] is not None:
                rcnt += dpr[h][i] + 1
                break
            else:
                rcnt += 1
        else:
            break
    dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        key = str(h) + str(i)
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
    dpl[h][w] = lcnt

    # to down
    for i in range(h+1, H):
        key = str(i) + str(w)
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                dcnt += dpd[i][w] + 1
                break
            else:
                dcnt += 1
        else:
            break
    dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        key = str(i) + str(w)
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
    dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in range(H):
    for j in range(W):
        ans = max(ans, getCount(i, j))

print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    for i in range(w+1, W):
        key = str(h) + str(i)
        if s[h][i] == '.':
            if dpr[h][i] is not None:
                rcnt += dpr[h][i] + 1
                break
            else:
                rcnt += 1
        else:
            break
    dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        key = str(h) + str(i)
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
    dpl[h][w] = lcnt

    # to down
    for i in range(h+1, H):
        key = str(i) + str(w)
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                dcnt += dpd[i][w] + 1
                break
            else:
                dcnt += 1
        else:
            break
    dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        key = str(i) + str(w)
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            if key in dpu:
                ucnt += dpu[key] + 1
                break
            else:
                ucnt += 1
        else:
            break
    dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in range(H):
    for j in range(W):
        ans = max(ans, getCount(i, j))

print(ans)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(1000000000000)
H, W = map(int, input().split())
s, dp, ans = [], {}, 0
for i in range(H):
    s.append(input())
def getRightCount(h, w):
    key = str(h) + str(w) + 'r'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == W - 1:
        dp[key] = 0
    elif s[h][w+1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getRightCount(h, w+1)
    return dp[key]
def getLeftCount(h, w):
    key = str(h) + str(w) + 'l'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == 0:
        dp[key] = 0
    elif s[h][w-1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getLeftCount(h, w-1)
    return dp[key]
def getDownCount(h, w):
    key = str(h) + str(w) + 'd'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == H - 1:
        dp[key] = 0
    elif s[h+1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getDownCount(h+1, w)
    return dp[key]
def getUpCount(h, w):
    key = str(h) + str(w) + 'u'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == 0:
        dp[key] = 0
    elif s[h-1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getUpCount(h-1, w)
    return dp[key]
def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rCnt, lCnt, uCnt, dCnt = 0,0,0,0
    key = str(h) + str(w)
    # to right
    rkey = key + 'r'
    rCnt = getRightCount(h, w)
    # to left
    lkey = key + 'l'
    lCnt = getLeftCount(h, w)
    # to down
    dkey = key + 'd'
    dCnt = getDownCount(h, w)
    # to up
    ukey = key + 'u'
    uCnt = getUpCount(h, w)
    return rCnt + lCnt + uCnt + dCnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(1000000000000)
H, W = map(int, input().split())
s, dp, ans = [], {}, 0
for i in range(H):
    s.append(input())
def getRightCount(h, w):
    key = str(h) + str(w) + 'r'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == W - 1:
        dp[key] = 0
    elif s[h][w+1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getRightCount(h, w+1)
    return dp[key]
def getLeftCount(h, w):
    key = str(h) + str(w) + 'l'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == 0:
        dp[key] = 0
    elif s[h][w-1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getLeftCount(h, w-1)
    return dp[key]
def getDownCount(h, w):
    key = str(h) + str(w) + 'd'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == H - 1:
        dp[key] = 0
    elif s[h+1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getDownCount(h+1, w)
    return dp[key]
def getUpCount(h, w):
    key = str(h) + str(w) + 'u'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == 0:
        dp[key] = 0
    elif s[h-1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getUpCount(h-1, w)
    return dp[key]
def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rCnt, lCnt, uCnt, dCnt = 0,0,0,0
    key = str(h) + str(w)
    # to right
    rkey = key + 'r'
    rCnt = getRightCount(h, w)
    # to left
    lkey = key + 'l'
    lCnt = getLeftCount(h, w)
    # to down
    dkey = key + 'd'
    dCnt = getDownCount(h, w)
    # to up
    ukey = key + 'u'
    uCnt = getUpCount(h, w)
    return rCnt + lCnt + uCnt + dCnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, dp, ans = [], {}, 0
for i in range(H):
    s.append(input())
def getRightCount(h, w):
    key = str(h) + str(w) + 'r'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == W - 1:
        dp[key] = 0
    elif s[h][w+1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getRightCount(h, w+1)
    return dp[key]
def getLeftCount(h, w):
    key = str(h) + str(w) + 'l'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == 0:
        dp[key] = 0
    elif s[h][w-1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getLeftCount(h, w-1)
    return dp[key]
def getDownCount(h, w):
    key = str(h) + str(w) + 'd'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == H - 1:
        dp[key] = 0
    elif s[h+1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getDownCount(h+1, w)
    return dp[key]
def getUpCount(h, w):
    key = str(h) + str(w) + 'u'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == 0:
        dp[key] = 0
    elif s[h-1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getUpCount(h-1, w)
    return dp[key]
def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rCnt, lCnt, uCnt, dCnt = 0,0,0,0
    key = str(h) + str(w)
    # to right
    rkey = key + 'r'
    rCnt = getRightCount(h, w)
    # to left
    lkey = key + 'l'
    lCnt = getLeftCount(h, w)
    # to down
    dkey = key + 'd'
    dCnt = getDownCount(h, w)
    # to up
    ukey = key + 'u'
    uCnt = getUpCount(h, w)
    return rCnt + lCnt + uCnt + dCnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s, dp, ans = [], {}, 0
for i in range(H):
    s.append(input())
def getRightCount(h, w):
    key = str(h) + str(w) + 'r'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == W - 1:
        dp[key] = 0
    elif s[h][w+1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getRightCount(h, w+1)
    return dp[key]
def getLeftCount(h, w):
    key = str(h) + str(w) + 'l'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == 0:
        dp[key] = 0
    elif s[h][w-1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getLeftCount(h, w-1)
    return dp[key]
def getDownCount(h, w):
    key = str(h) + str(w) + 'd'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == H - 1:
        dp[key] = 0
    elif s[h+1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getDownCount(h+1, w)
    return dp[key]
def getUpCount(h, w):
    key = str(h) + str(w) + 'u'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == 0:
        dp[key] = 0
    elif s[h-1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getUpCount(h-1, w)
    return dp[key]
def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rCnt, lCnt, uCnt, dCnt = 0,0,0,0
    key = str(h) + str(w)
    # to right
    rkey = key + 'r'
    rCnt = getRightCount(h, w)
    # to left
    lkey = key + 'l'
    lCnt = getLeftCount(h, w)
    # to down
    dkey = key + 'd'
    dCnt = getDownCount(h, w)
    # to up
    ukey = key + 'u'
    uCnt = getUpCount(h, w)
    return rCnt + lCnt + uCnt + dCnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))
print(ans)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
s = []
ans = 0
dp = {}
for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
	return 0
    rCnt = 0
    lCnt = 0
    uCnt = 0
    dCnt = 0
    key = str(h) + str(w)

    # to right
    rkey = key + 'r'
    if rkey in dp:
	rCnt = dp[rkey]
    else:
        for i in range(w+1, W):
            if s[h][i] == '.':
		rCnt += 1
            else:
                break
	dp[rkey] = rCnt

    # to left
    lkey = key + 'l'
    if lkey in dp:
	lCnt = dp[lkey]
    else:
        for i in reversed(range(w)):
            if s[h][i] == '.':
		lCnt += 1
            else:
                break
	dp[lkey] = lCnt

    # to down
    dkey = key + 'd'
    if dkey in dp:
	dCnt = dp[dkey]
    else:
        for i in range(h+1, H):
            if s[i][w] == '.':
		dCnt += 1
            else:
                break
	dp[dkey] = dCnt

    # to up
    ukey = key + 'u'
    if ukey in dp:
	uCnt = dp[ukey]
    else:
        for i in reversed(range(h)):
            if s[i][w] == '.':
		uCnt += 1
            else:
                break
	dp[ukey] = uCnt

    return rCnt + lCnt + uCnt + dCnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
	ans = max(ans, getCount(i, j))

print(ans)