Super Ugly Number

medium
1. You are given an array(arr) of size k which contains prime numbers in ascending order, and an integer N.
2. You have to find Nth super ugly number.
3. Super ugly number is defined as the number whose prime factors are elements of the given array.

Assumption -> 1 is the first super ugly number.

Input Format

A number K arr1 arr2.. K prime numbers in ascending order A number N

Output Format

A number representing Nth super ugly number.

Constraints

1 <= K <= 100
1 <= arr[i] <= 1000
1 <= N <= 10^6

Example

Input
4
3 5 7 11
13
Output
45
Previous
Find Transition Point
Next
Frog Jump

Related Questions