• + 0 comments

    So here is my code.For an help for you guys just look at the object from front back right left top bottom and you will notice that each of those pairs are equal.Also see the list A and try to get the pattern.Then the coding is simple

    #!/bin/python3
    
    import math
    import os
    import os
    
    def surfaceArea(A):
        D = []
        for a in A:
            S = []
            for i in range(1, W):
                S.append(abs(a[i] - a[i - 1])) 
            D.append(sum(S) + a[-1] + a[0])
    
        E = []
        for d in range(H - 1): 
            for c in range(W):  
                E.append(abs(A[d][c] - A[d + 1][c]))
    
        E.append(sum(A[0]) + sum(A[-1]))  
        return sum(D) + sum(E) + 2 * H * W 
    
    if __name__ == '__main__':
        fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
        first_multiple_input = input().rstrip().split()
    
        H = int(first_multiple_input[0])
        W = int(first_multiple_input[1])
    
        A = []
        for _ in range(H):
            A.append(list(map(int, input().rstrip().split())))
    
        result = surfaceArea(A)
    
        fptr.write(str(result) + '\n')
        fptr.close()
    
        print(A)