#P7617. [COCI 2011/2012 #2] KOMPIĆI

[COCI 2011/2012 #2] KOMPIĆI

Description

Given NN positive integers A1,A2,...,ANA_1, A_2, ..., A_N, find how many integer pairs (i,j)(i, j) satisfy the following conditions:

  • 1i<jN1 \le i < j \le N.
  • AiA_i and AjA_j share at least one common digit (the digit does not need to be in the same position).

Input Format

The first line contains a positive integer NN.

The next NN lines each contain a positive integer AiA_i.

Output Format

Output one integer in a single line, representing the number of pairs that satisfy the condition.

3
4
20
44
1
4
32
51
123
282
4

Hint

Sample Explanation

In Sample 1, the pair that meets the requirement is (1,3)(1, 3).

In Sample 2, the pairs that meet the requirement are (1,3)(1, 3), (1,4)(1, 4), (2,3)(2, 3), (3,4)(3, 4).

Constraints

For 100%100\% of the testdata, 1N1061 \le N \le 10^6, 1Ai10181 \le A_i \le 10^{18}.

Notes

The scoring of this problem follows the original COCI settings, with a full score of 120120.

This problem is translated from COCI2011-2012 CONTEST #2 T4 KOMPIĆI.

Translated by ChatGPT 5