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
) (1 ≤ i < j ≤ n).
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.
Input example #1
4 1 2 12 21
Output example #1
5
Input example #2
4 0 10 22 22
Output example #2
2