In PrimeLand, there existed a very handsome young prince named Prima. He greatly desired the Princess of Mathematics – Facie. However, before accepting his hand in marriage, Facie asked Prima to solve the following problem:


The figure below shows a simple multiplication problem. However, not all the decimal digits are available. Prima has to find an assignment of digits to the marked places so that the multiplication is valid.


      * * *
   x    * *
    -------
      * * *         <-- partial product 1
    * * *           <-- partial product 2
    -------
    * * * *


Digits can appear only in places marked by `*'. Of course, leading zeroes are not allowed.
Write a program to help Prima that will find all solutions to this problem for any subset of digits from the set {1,2,3,4,5,6,7,8,9}.



Input
The first line contains N, the number of digits that will be used 
The second line contains N space separated digits 


Output
A single line with the total number of unique solutions. Here is the single solution for the sample input:

      2 2 2
    x   2 2
     ------
      4 4 4
    4 4 4
  ---------
    4 8 8 4


Example

Input:
5
2 3 4 6 8


Output:
1
#input 
N = int(raw_input())
digits = [0 for i in range(N)]
string = raw_input()
string = string.split()
for i in range(N):
    digits[i] = int(string[i])

output=0

#main logic

mult1 = [0 for i in range(N*N*N)]
mult2 = [0 for i in range(N*N)]
num1=0
num2=0

#generate all mult1
for i in range(N):
    for j in range(N):
        for k in range(N):
            if digits[i] != 0:
                mult1[num1] = digits[i]*100+digits[j]*10+digits[k]
                num1+=1
                    

#generate all mult2
for i in range(N):
    for j in range(N):
        if digits[i] != 0:
            mult2[num2] = digits[i]*10+digits[j]
            num2+=1

#multiply and check
for i in range(num1):
    for j in range(num2):
        yes = 1
        result_par1 = mult1[i] * (mult2[j]%10)
        result_par1_copy = result_par1
        if result_par1 <1000:
            while(result_par1!=0):
                dig = result_par1%10
                if dig not in digits:
                    yes = 0
                    break;
                result_par1 = result_par1/10
            if yes ==1:
                result_par2 = mult1[i] * (mult2[j]/10)
                result_par2_copy = result_par2
                if result_par2 <1000:
                    while(result_par2!=0):
                        dig = result_par2%10
                        if dig not in digits:
                            yes = 0
                            break;
                        result_par2 = result_par2/10
                    if yes == 1:
                        result =   result_par1_copy + result_par2_copy*10
                        result_copy = result
                        if result <10000:
                            while(result!=0):
                                dig = result%10
                                if dig not in digits:
                                    yes = 0
                                    break;
                                result = result/10                        
                            if yes ==1:
                                output+=1
                
#output
print output