Problem p03014 (python)

Fixed submission:
import sys
 
def solve():
    file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    H, W = map(int, file().split())
    S = [None] * H
    for i in range(H):
        S[i] = list(file())
    left, right, up, down = [[0 for i in range(W)] for j in range(H)], [[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)]
    for h in range(H):
        if S[h][0] == ".": left[h][0] += 1
        if S[h][W-1] == ".": right[h][W-1] += 1
    for w in range(W):
        if S[0][w] == ".": up[0][w] += 1
        if S[H-1][w] == ".": down[H-1][w] += 1

    for h in range(H):
        for w in range(1, W):
            if S[h][w] == ".":
                left[h][w] = left[h][w-1] + 1
            if S[h][W-w-1] == ".":
                right[h][W - w - 1] = right[h][W - w] + 1
    for h in range(1, H):
        for w in range(W):
            if S[h][w] == ".":
                up[h][w] = up[h-1][w] + 1
            if S[H-h-1][w] == ".":
                down[H-h-1][w] = down[H-h][w] + 1

    maxlight = 0
    for h in range(H):
        for w in range(W):
            maxlight = max(maxlight, left[h][w] + right[h][w] + up[h][w] + down[h][w] - 3)
    print(maxlight)   
 
    return 0
  
if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    H, W = map(int, file().split())
    S = [None] * H
    for i in range(H):
        S[i] = list(file())
    left, right, up, down = [[0 for i in range(W)] for j in range(H)], [[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)]
    for h in range(H):
        if S[h][0] == ".": left[h][0] += 1
        if S[h][W-1] == ".": right[h][W-1] += 1
    for w in range(W):
        if S[0][w] == ".": up[0][w] += 1
        if S[0][H-1] == ".": down[H-1][w] += 1

    for h in range(H):
        for w in range(1, W):
            if S[h][w] == ".":
                left[h][w] = left[h][w-1] + 1
                right[h][W - w - 1] = right[h][W - w] + 1
    for h in range(1, H):
        for w in range(W):
                up[h][w] = up[h-1][w] + 1
                down[H-h-1][w] = down[H-h][w] + 1

    maxlight = 0
    for h in range(H):
        for w in range(W):
            maxlight = max(maxlight, left[h][w] + right[h][w] + up[h][w] + down[h][w] - 3)
    print(maxlight)      

    return 0
  
if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys, math, collections, heapq, itertools
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    file = sys.stdin.readline #single: int(file()), line: map(int, file().split())
    INF = 10 ** 25
    mod = 7 + 10 ** 9
    H, W = map(int, file().split())
    S = [None] * H
    for i in range(H):
        S[i] = list(file())
    left, right, up, down = [[0 for i in range(W)] for j in range(H)], [[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)],[[0 for i in range(W)] for j in range(H)]
    for h in range(H):
        if S[h][0] == ".": left[h][0] += 1
        if S[h][W-1] == ".": right[h][W-1] += 1
    for w in range(W):
        if S[0][w] == ".": up[0][w] += 1
        if S[0][H-1] == ".": down[H-1][w] += 1

    for h in range(H):
        for w in range(1, W):
            if S[h][w] == ".":
                left[h][w] = left[h][w-1] + 1
                right[h][W - w - 1] = right[h][W - w] + 1
    for h in range(1, H):
        for w in range(W):
                up[h][w] = up[h-1][w] + 1
                down[H-h-1][w] = down[H-h][w] + 1

    maxlight = 0
    for h in range(H):
        for w in range(W):
            maxlight = max(maxlight, left[h][w] + right[h][w] + up[h][w] + down[h][w] - 3)
    print(maxlight)      

    return 0
  
if __name__ == "__main__":
    solve()