from implementations import heap


def least_k_sum_of_cubes(k):
    results = []
    min_heap = heap.Heap(comp=lambda (a1, b1, cube1), (a2, b2, cube2): cube1 < cube2)
    min_heap.insert((0, 0, 0))
    while len(results) < k:
        a, b, cube = min_heap.extract_min()
        min_heap.insert((a + 1, b, (a + 1) ** 3 + b ** 3))
        if a - 1 == b:
            min_heap.insert((a, b + 1, a ** 3 + (b + 1) ** 3))
        results.append((a, b, cube))
    return results


if __name__ == '__main__':
    print '\n'.join(str(x) for x in least_k_sum_of_cubes(40))
