eolymp
bolt
Try our new interface for solving problems
Problems

Suitable pairs

Suitable pairs

We call a pair of non-negative integers suitable if there is at least one common digit in their decimal notation (not necessarily in the same digit). Let there be given n non-negative numbers a1, a2, ..., an. Consider all possible pairs (ai, aj) (1i < jn).

Write a program that will determine the number of all suitable pairs.

Input

The first line contains positive integer n, not greater than 106. Second line contains n nonnegative integers, not greater 999.

Output

Print the number of suitable pairs.

Time limit 1 second
Memory limit 128 MiB
Input example #1
4
1 2 12 21
Output example #1
5
Input example #2
4
0 10 22 22
Output example #2
2
Author Неспирный В.Н.
Source III этап УОИ Донецк, 2012 г. I тур 10-11 кл.