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.
n = int(raw_input())
dict = {'2':0, '3':0, '5':0, '7':0, '2,3':0, '2,5':0, '2,7':0, '3,5':0, '3,7':0, '5,7':0, '2,3,5':0, '2,3,7':0, '2,5,7':0, '3,5,7':0, '2,3,5,7':0}
for i in range(n):
	num = raw_input()
	if '2' in num:
		dict['2'] = dict['2'] + 1
		if '3' in num:
			dict['2,3'] = dict['2,3'] + 1
			if '5' in num:
				dict['2,3,5'] = dict['2,3,5'] + 1
				if '7' in num:
					dict['2,3,5,7'] = dict['2,3,5,7'] + 1
			if '7' in num:
						dict['2,3,7'] = dict['2,3,7'] + 1
		if '5' in num:
			dict['2,5'] = dict['2,5'] + 1
			if '7' in num:
				dict['2,5,7'] = dict['2,5,7'] + 1
		if '7' in num:
			dict['2,7'] = dict['2,7'] + 1
	if '3' in num:
		dict['3'] = dict['3'] + 1
		if '5' in num:
			dict['3,5'] = dict['3,5'] + 1
			if '7' in num:
				dict['3,5,7'] = dict['3,5,7'] + 1
		if '7' in num:
			dict['3,7'] = dict['3,7'] + 1
	if '5' in num:
		dict['5'] = dict['5'] + 1
		if '7' in num:
			dict['5,7'] = dict['5,7'] + 1
	if '7' in num:
		dict['7'] = dict['7'] + 1	

ans = 0
for i in [2, 3, 5, 7]:
	temp = dict[str(i)]
	ans = ans + (temp*(temp-1)*(temp-2))/6
for i in [2, 3, 5, 7]:
	for j in [2, 3, 5, 7]:
		if i >= j:
			continue
		temp = dict[str(i)+','+str(j)]
		ans = ans - (temp*(temp-1)*(temp-2))/6
for i in [2, 3, 5, 7]:
	for j in [2, 3, 5, 7]:
		if i >= j:
			continue
		for k in [2, 3, 5, 7]:
			if j >= k:
				continue
			temp = dict[str(i)+','+str(j)+','+str(k)]
			ans = ans + (temp*(temp-1)*(temp-2))/6
temp = dict['2,3,5,7']
ans = ans - (temp*(temp-1)*(temp-2))/6
print ans