cswork / OAOpen practice workspace

ZipRecruiterOA #4

Count Distinct Swappable Digit Pairs

Estimated MediumJudge-ready

Topics (AI-labelled)HashingStrings

For each i<j, the pair is valid if the decimal representation of numbers[j] can become numbers[i] with at most one swap (swapping one pair of positions); no swap is also allowed. Only numbers with the same number of digits are counted. Find the number of pairs. A swap must not create a leading zero.

Input

The first line contains n (1..100000), and the second line contains n integers (0..10^9) in ordinary decimal representation.

Output

Output the number of valid pairs; the result may exceed 32 bits.

Example 1

Input:

4
12 21 12 123

Output:

3

Example 2

Input:

2
7 7

Output:

1

Example 3

Input:

4
1 10 100 1000

Output:

0

Editorial

Loading solution…