Mehta is a forever alone and desperate guy. He has a crush on N girls of his society. He wants to impress them all and so he needs to do their task collectively.All the girls give him a number which he stores in an array named A of size N. To do their task, he has to report the number of triplets (i,j,k) in the array A, with  i < j < k such that the triplets have at least one prime digit in common.

Input & Output:
The first line of the input contains an integer N. The next N lines has a number on each, which denote the array A.

You need to print on one line, the number of triples with the condition mentioned in the problem statement.

Constraints:

1 ≤ N ≤  10 ^ 5
0 ≤ A[i] ≤ 10  ^ {18}  for all index i in the array A.

Sample Input:

5
21
22
23
24
25

Sample Output:
10

SAMPLE INPUT
5
21
22
23
24
25

SAMPLE OUTPUT
10

Explanation

In the given sample each i,j,k has one prime digit common that is 2. So, total triplets are 5C3 which is 10.
'''
Project name : Mehta_and_the_Tricky_Triplets
Created on : Tue Aug 26 23:19:11 2014
Author : Anant Pushkar

'''
import sys
debug_mode = len(sys.argv)>1 and sys.argv[1]=="DEBUG"
def debug(msg):
	if debug_mode:
		print msg
class Solver:
	def __init__(self , n):
		self.create_masks()
		for i in xrange(n):
			a = int(raw_input())
			mask = 0
			while a>0:
				mask = mask | (1<<(a%10))
				a /= 10
			for i in xrange(len(self.mask)):
				self.count[i] += 1 if ( mask & self.mask[i] )==self.mask[i] else 0
	
	def create_masks(self):
		self.mask=[]
		self.mask.append(1<<2)
		self.mask.append(1<<3)
		self.mask.append(1<<5)
		self.mask.append(1<<7)
		self.mask.append((1<<2) | (1<<3))
		self.mask.append((1<<2) | (1<<5))
		self.mask.append((1<<2) | (1<<7))
		self.mask.append((1<<3) | (1<<5))
		self.mask.append((1<<3) | (1<<7))
		self.mask.append((1<<5) | (1<<7))
		self.mask.append((1<<2) | (1<<3) | (1<<5))
		self.mask.append((1<<7) | (1<<3) | (1<<5))
		self.mask.append((1<<2) | (1<<7) | (1<<5))
		self.mask.append((1<<2) | (1<<3) | (1<<7))
		self.mask.append((1<<2) | (1<<3) | (1<<5) | (1<<7))
		self.count = [0 for i in xrange(len(self.mask))]
	
	def nC3(self,n):
		return n*(n-1)*(n-2)/6
	
	def solve(self):
		soln  = self.nC3(self.count[0]) + self.nC3(self.count[1]) + self.nC3(self.count[2]) + self.nC3(self.count[3])
		soln -= self.nC3(self.count[4]) + self.nC3(self.count[5]) + self.nC3(self.count[6]) + self.nC3(self.count[7]) + self.nC3(self.count[8]) + self.nC3(self.count[9])
		soln += self.nC3(self.count[10]) + self.nC3(self.count[11]) + self.nC3(self.count[12]) + self.nC3(self.count[13])
		soln -= self.nC3(self.count[14])
		return soln
		
n = int(raw_input())
s = Solver(n)
print s.solve()