Trio
InterviewTime limit2sMemory limit1024 MB
Count the sets of three numbers from a list of four-digit numbers (no zero digits) where each digit position is either all equal or all distinct across the three.
- Level
Medium6 of 10
- Topics
- Hash map, Combinatorics, Implementation
- Solved
- No attempts yet
Problem
Let be any set of natural numbers whose decimal representations have exactly four digits, none of which is .
A trio is a set of three numbers chosen from that satisfies all of the following conditions at once.
- The ones digits of , , are either all equal or all distinct.
- The tens digits of , , are either all equal or all distinct.
- The hundreds digits of , , are either all equal or all distinct.
- The thousands digits of , , are either all equal or all distinct.
For example, is a trio if all three numbers are in . Their ones digits are all distinct, their tens digits are all distinct, their hundreds digits are all distinct, and their thousands digits are all equal. The set is not a trio, even if contains all three numbers.
Input
The first line contains a single integer (), the number of members in . Each of the following lines contains one positive integer with exactly four digits, none of which is . The numbers are all distinct and are the members of .
Output
Print the number of different trios for on one line.