KOMPICI - Kompići

After successfully solving his math homework from the previous task, Mirko has become bored, so he has made a list of N large integers. On the list there are some pairs of numbers that he likes, and some pairs he doesn’t like. Mirko has named the pairs that he likes pals. Two numbers are pals if they have at least one digit in common (not necessarily in the same position). 

Help Mirko count how many pairs of numbers in his list are pals

Input

The first line of input contains the positive integer N (1 ≤ N ≤ 500 000).Each of the next N lines contains a positive integer from the range [1, 10^18], a number from Mirko’s list. No two numbers in the list will be equal.

Output

The first and only line of output must contain the number of pairs that are pals.

Example

Input:
3
4
20
44

Output:
1

Added by:Tadek Dul
Date:2011-11-23
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:C C++ 4.3.2 CPP HASK JAVA PAS-FPC PYTHON
Resource:COCI 2011/2012 2nd round

hide comments
2016-06-18 12:22:17 Shrish Lal Bhatnagar
@ Erik Lonèarek
answer to 4 34 3 3 4 is "6" not "4"
pairs are (4, 34); (4, 4); (34, 3); (34, 3); (34, 4); (3, 3)
2014-02-28 11:18:54 Rishul Aggarwal
Nice question! Those getting TLE, try to optimise EACH step of your algorithm.
2013-09-06 17:19:54 Ouditchya Sinha
Very Nice Problem! :)
2013-08-22 15:33:06 P_Quantum
Nice Question... :)
2013-08-19 20:57:04 BLANKRK
finaly done!!
2013-08-19 05:55:21 (Tjandra Satria Gunawan)(曾毅昆)
Got AC in the past, but TLE now. and suprisingly I can't easily understand my old AC code (>1 year ago) :-(
2013-06-06 06:39:58 Saurabh Kathpalia
Got Accepted!!!!!
Nice one
2013-06-06 04:56:08 Saurabh Kathpalia
@Erik Lončarek I am also getting the same answers for ur test case but still getting WA on 8th test case.
What may be the problem???
2013-01-13 23:29:26 nondescript
what if the list is 4, 2, 45, 5, 41 then looks like it has two answers....first is if you pair 45 and 4 you ll have one pal and second is if you pair 45 and 5 and then 4 and 41...so isnt this question ambiguous??
2012-11-29 13:22:55 Erik Lonèarek
@me
3 4 4 4 -> 3
4 34 3 3 4 -> 4
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.