':type n: int
:type primes: List[int]
:rtype: int'

def nthSuperUglyNumber(self, n, primes):

    (uglies, idx, heap) = ([1], ([0] * len(primes)), [])
    for (k, p) in enumerate(primes):
        heapq.heappush(heap, (p, k))
    for i in xrange(1, n):
        (min_val, k) = heap[0]
        uglies += [min_val]
        while (heap[0][0] == min_val):
            (min_val, k) = heapq.heappop(heap)
            idx[k] += 1
            heapq.heappush(heap, ((primes[k] * uglies[idx[k]]), k))
    return uglies[(-1)]
