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

def nthSuperUglyNumber(self, n, primes):

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