Problem p03014 (python)

Fixed submission:
from sys import stdin
h,w = map(int,stdin.readline().rstrip().split())
li = [stdin.readline().rstrip() for _ in range(h)]
#各四方向のDPをつくる
L = [[0 for i in range(w)]for j in range(h)]
R = [[0 for i in range(w)]for j in range(h)]
D = [[0 for i in range(w)]for j in range(h)]
U = [[0 for i in range(w)]for j in range(h)]
ma = 0
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":L[i][j] = 0
        elif j == 0:L[i][j] = 1
        else:L[i][j] = L[i][j-1]+1
for i in range(h):
    for j in range(w):
        if li[i][w-j-1] == "#":R[i][w-j-1] = 0
        elif w-j-1 == w-1:R[i][w-j-1] = 1
        else:R[i][w-j-1] = R[i][w-j]+1
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":U[i][j] = 0
        elif i == 0:U[i][j] = 1
        else:U[i][j] = U[i-1][j]+1
for i in range(h):
    for j in range(w):
        if li[h-i-1][j] == "#":D[h-i-1][j] = 0
        elif h-i-1 == h-1:D[h-i-1][j] = 1
        else:D[h-i-1][j] = D[h-i][j]+1
for i in range(h):
    for j in range(w):
        point = L[i][j]+R[i][j]+D[i][j]+U[i][j]-3
        ma = max(ma,point)
print(ma)

Buggy submission (verdict: Runtime Error):
from sys import stdin
inf = 10**10
h,w = [int(x) for x in stdin.readline().rstrip().split()]
li = ["" for j in range(h)]
ma = 0
for i in range(h):
    s = stdin.readline().rstrip()
    li[i] = s
for i in range(h):
    for j in range(w):
        if li[i][j] == "#":
            continue
        now_u = 0;now_b = 0;now_r = 0;now_l = 0
        while i+now_b <= h-1:
            if li[i+now_b][j] == ".":
                now_b += 1
            else:
                break
        while i-now_u >= 0:
            if li[i-now_u][j] == ".":
                now_u += 1
            else:
                break
        while j+now_r <= w-1:
            if li[i][j+now_r] == ".":
                now_r += 1
            else:
                break
        while i-now_l >= 0:
            if li[i][j-now_l] == ".":
                now_l += 1
            else:
                break
        point = now_u+now_b+now_r+now_l-3
        ma = max(point,ma)
print(ma)

Buggy submission (verdict: Runtime Error):
from sys import stdin
inf = 10**10
h,w = [int(x) for x in stdin.readline().rstrip().split()]
li = ["" for j in range(h)]
ma = 0
for i in range(h):
    s = stdin.readline().rstrip()
    li[i] = s
for i in range(h):
    for j in range(w):
        now_u = 0;now_b = 0;now_r = 0;now_l = 0
        while i+now_b < h:
            if li[i+now_b][j] == ".":
                now_b += 1
            else:
                now_b -= 1
                break
        while i-now_u >= 0:
            if li[i-now_u][j] == ".":
                now_u += 1
            else:
                now_u -= 1
                break
        while j+now_r < w:
            if li[i][j+now_r] == ".":
                now_r += 1
            else:
                now_r -= 1
                break
        while i-now_l >= 0:
            if li[i][j-now_l] == ".":
                now_l += 1
            else:
                now_l -= 1
                break
        point = now_u+now_b+now_r+now_l-2
        ma = max(ma,point)
print(ma)

Buggy submission (verdict: Runtime Error):
from sys import stdin
inf = 10**10
h,w = [int(x) for x in stdin.readline().rstrip().split()]
li = ["" for j in range(h)]
ma = 0
for i in range(h):
    s = stdin.readline().rstrip()
    li[i] = s
for i in range(h):
    for j in range(w):
        now_u = 0;now_b = 0;now_r = 0;now_l = 0
        while i+now_b < h:
            if li[i+now_b][j] == ".":
                now_b += 1
            else:
                now_b -= 1
                break
        while i-now_u >= 0:
            if li[i-now_u][j] == ".":
                now_u += 1
            else:
                now_u -= 1
                break
        while j+now_r < w:
            if li[i][j+now_r] == ".":
                now_r += 1
            else:
                now_r -= 1
                break
        while i-now_l >= 0:
            if li[i][j-now_l] == ".":
                now_l += 1
            else:
                now_l -= 1
                break
        point = now_u+now_b+now_r+now_l-2
        ma = max(ma,point)
print(ma)