Problem:
A binary heap which satisfies max-heap property is called max-heap. In a max- heap, for every node $i$ other than the root, $A    Write a program which reads an array and constructs a max-heap from the array based on the following pseudo code.  $maxHeapify(A, i)$ move the value of $A[i]$ down to leaves to make a sub-tree of node $i$ a max-heap. Here, $H$ is the size of the heap.                 1  maxHeapify(A, i) 2      l = left(i) 3      r = right(i) 4      // select the node which has the maximum value 5      if l ≤ H and A[l] > A[i] 6          largest = l 7      else  8          largest = i 9      if r ≤ H and A[r] > A[largest] 10         largest = r 11 12     if largest ≠ i　// value of children is larger than that of i 13         swap A[i] and A[largest] 14         maxHeapify(A, largest) // call recursively   The following procedure buildMaxHeap(A) makes $A$ a max-heap by performing maxHeapify in a bottom-up manner.                 1 buildMaxHeap(A) 2    for i = H/2 downto 1 3        maxHeapify(A, i)

Incorrect submission (verdict: Wrong Answer):
import pprint as pp

class Main():
    def exchange(self, n1, n2):
        tmp = self.A[n1]
        self.A[n1] = self.A[n2]
        self.A[n2] = tmp

    def left(self, i):
        return i * 2

    def right(self, i):
        return i * 2 + 1

    def maxHeapify(self, i):
        l = self.left(i)
        r = self.right(i)
        if l <= self.H and self.A[l] > self.A[i]:
            largest = l
        else :
            largest = i
        if r <= self.H and self.A[r] > self.A[largest]:
            largest = r
        if largest != i:
            self.exchange(i, largest)
            self.maxHeapify(largest) 

    def buildMaxHeap(self):
        for i in reversed( range(1, self.H//2) ):
            self.maxHeapify(i)

    def main(self):
        self.H = int( input() )
        self.A = [0]
        inputData = [int(x) for x in input().split()]
        self.A.extend(inputData)
        self.buildMaxHeap()
        for i in range(1, self.H+1):
            print(" " + str(self.A[i]), end = "" )

if __name__ == '__main__':
    M = Main()
    M.main()



Fixed, accepted submission:
import pprint as pp

class Main():
    def exchange(self, n1, n2):
        tmp = self.A[n1]
        self.A[n1] = self.A[n2]
        self.A[n2] = tmp

    def left(self, i):
        return i * 2

    def right(self, i):
        return i * 2 + 1

    def maxHeapify(self, i):
        l = self.left(i)
        r = self.right(i)
        if l <= self.H and self.A[l] > self.A[i]:
            largest = l
        else :
            largest = i
        if r <= self.H and self.A[r] > self.A[largest]:
            largest = r
        if largest != i:
            self.exchange(i, largest)
            self.maxHeapify(largest) 

    def buildMaxHeap(self):
        for i in reversed( range(1, self.H//2 + 1) ):
            self.maxHeapify(i)

    def main(self):
        self.H = int( input() )
        self.A = [0]
        inputData = [int(x) for x in input().split()]
        self.A.extend(inputData)
        self.buildMaxHeap()
        for i in range(1, self.H+1):
            print(" " + str(self.A[i]), end = "" )
        print()

if __name__ == '__main__':
    M = Main()
    M.main()