P28794 [洛谷] [COCI2011-2012#5] RAZBIBRIGA
普及+
题目描述

Problem Description

Four words of equal length can form a square, as shown in the image where "HLAD", "NIVA", "HSIN", "DEDA" form a $4 \times 4$ square.

Given \( N \) words of equal length, determine how many distinct squares can be formed from subsets of these words. Output the number of such distinct squares.

Note that no duplicate words are allowed within the same square. Two words are considered different if they differ by at least one character.

Input Format

The first line contains an integer \( N \), the number of words.

Following are \( N \) lines, each containing a word composed of uppercase letters, as described.

Output Format

Output a single integer, the number of distinct squares that can be formed.

Since the number of squares can be very large, you should use long long or int64.

Sample Input and Output

Sample Input #1

4
NIVA
HLAD
HSIN
DEDA

Sample Output #1

2

Sample Input #2

6
BAKA
BARA
BALC
CALC
ARHC
BLIC

Sample Output #2

8

Notes/Hints

\( 4 \le N \le 10^5 \).

Each word contains at most 10 characters.

Words are composed of uppercase letters.

This problem is translated from COCI 2011/2012 #5 T4.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 NIVA HLAD HSIN DEDA
样例输出
2