#P7617. Counting Pairs with Common Digit
Counting Pairs with Common Digit
Counting Pairs with Common Digit
Given N positive integers A1, A2, ..., AN, count the number of pairs (i, j) (with 1 \le i < j &le N) such that Ai and Aj share at least one common digit (the digit can occur in different positions in the two numbers).
The condition can be formally stated in \(\LaTeX\) as follows:
[ 1 \le i < j \le N \quad \text{and} \quad \exists d ; \text{such that} ; d \in \text{digits}(A_i) ; \text{and} ; d \in \text{digits}(A_j). ]
inputFormat
The first line contains an integer N (1 \le N). The second line contains N positive integers A1, A2, ..., AN separated by spaces.
outputFormat
Output a single integer, which is the count of pairs (i, j) that satisfy the condition.
sample
3
11 12 23
2
</p>