@@ -0,0 +1,1314 @@
+%0Aclass heap:%0A    def __init__(self, xs = %5B%5D):%0A        self.xs = xs%0A%0A    def __len__(self):%0A        return len(self.xs)%0A%0A    def push(self, x):%0A        self.xs.append(x)%0A        self.upheap(len(self))%0A%0A    def pop(self):%0A        x = self.xs%5B0%5D%0A        y = self.xs.pop()%0A        if len(self.xs) %3E 0:%0A            self.modify(y)%0A        return x%0A%0A    def front(self):%0A        return self.xs%5B0%5D%0A%0A    def modify(self, x):%0A        self.xs%5B0%5D = x%0A        self.downheap(1)%0A%0A    def upheap(self, i):%0A        p = i // 2%0A        while p %3E= 1:%0A            if self.xs%5Bi - 1%5D %3C self.xs%5Bp - 1%5D:%0A                t = self.xs%5Bi - 1%5D%0A                self.xs%5Bi - 1%5D = self.xs%5Bp - 1%5D%0A                self.xs%5Bp - 1%5D = t%0A                i = p%0A                p = i // 2%0A            else:%0A                break%0A%0A    def downheap(self, p):%0A        z = len(self.xs)%0A        c = 2*p%0A        while c %3C= z:%0A            if c %3C z and self.xs%5Bc%5D %3C self.xs%5Bc - 1%5D:%0A                c += 1%0A            if self.xs%5Bc - 1%5D %3C self.xs%5Bp - 1%5D:%0A                t = self.xs%5Bc - 1%5D%0A                self.xs%5Bc - 1%5D = self.xs%5Bp - 1%5D%0A                self.xs%5Bp - 1%5D = t%0A                p = c%0A                c = 2*p%0A            else:%0A                break%0A%0A    def heapify():%0A        z = len(self.xs) + 1%0A        for i in xrange(1, z):%0A            self.upheap(i)%0A%0A

Add a heap data structure.