Counting Functions

Count functions f on {1..N} such that each i returns to itself after exactly A_i iterations, for N up to 16.

Hard8CombinatoricsGraphBit manipulationNo attempts yetTime limit1sMemory limit32 MB

Problem

Minhyuk built a function f:SSf : S \to S from the set S={1,2,,N}S = \{1, 2, \dots, N\} to itself. Write fkf^k for applying ff exactly kk times in a row. The function Minhyuk built satisfies the following.

  • fA1(1)=1f^{A_1}(1) = 1
  • fA2(2)=2f^{A_2}(2) = 2
  • \dots
  • fAN(N)=Nf^{A_N}(N) = N

Minhyuk wants to know how many different functions satisfy this. Given A1,A2,,ANA_1, A_2, \dots, A_N, write a program that counts them. Two functions gg and hh are different when there is at least one xx with g(x)h(x)g(x) \neq h(x).

Input

The first line contains the size of the domain, NN. (3N163 \le N \le 16)

The second line contains the positive integers A1,A2,,ANA_1, A_2, \dots, A_N, separated by spaces. (1Ai1,000,0001 \le A_i \le 1{,}000{,}000)

Output

Print the number of functions that satisfy the condition on the first line.