Under construction

Still being built. Things may change

Trio

Interview

Time limit2sMemory limit1024 MB

Summary
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 AA be any set of nn natural numbers whose decimal representations have exactly four digits, none of which is 00.

A trio is a set of three numbers {a,b,c}\{a, b, c\} chosen from AA that satisfies all of the following conditions at once.

  • The ones digits of aa, bb, cc are either all equal or all distinct.
  • The tens digits of aa, bb, cc are either all equal or all distinct.
  • The hundreds digits of aa, bb, cc are either all equal or all distinct.
  • The thousands digits of aa, bb, cc are either all equal or all distinct.

For example, {1425,1113,1354}\{1425, 1113, 1354\} is a trio if all three numbers are in AA. 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 {1425,1113,5436}\{1425, 1113, 5436\} is not a trio, even if AA contains all three numbers.

Input

The first line contains a single integer nn (1≤n≤2,0001 \le n \le 2,000), the number of members in AA. Each of the following nn lines contains one positive integer with exactly four digits, none of which is 00. The nn numbers are all distinct and are the members of AA.

Output

Print the number of different trios for AA on one line.

Examples2

  1. Example 1

    Input
    6
    1234
    1235
    1244
    1233
    7133
    8133
    
    Expected output
    1
    
  2. Example 2

    Input
    9
    1234
    5678
    9123
    4567
    8912
    3456
    7891
    2345
    6789
    
    Expected output
    84