• + 0 comments

    In Python, key is to import inf first so cases with only negative numbers pass:

    #!/bin/python3
    
    import math
    import os
    import random
    import re
    import sys
    from math import inf
    #
    # Complete the 'hourglassSum' function below.
    #
    # The function is expected to return an INTEGER.
    # The function accepts 2D_INTEGER_ARRAY arr as parameter.
    #
    
    def hourglassSum(arr):
        curm = -inf
        for i in range(0,4):
            for j in range(0,4):
                l = (arr[i][j] +
                    arr[i][j+1] + arr[i][j+2] + arr[i+1][j+1] +
                    arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2])
                curm = max(curm,l)
        return curm
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        arr = []
    
        for _ in range(6):
            arr.append(list(map(int, input().rstrip().split())))
    
        result = hourglassSum(arr)
    
        fptr.write(str(result) + '\n')
    
        fptr.close()