#P4503. Counting Similar Accounts
Counting Similar Accounts
Counting Similar Accounts
PenguinQQ website administrator, Xiao Q, is investigating which accounts might have been registered by the same person. Through his research, he found that if a person registers multiple accounts, the account names tend to be very similar. In this problem, two account names are defined as similar if and only if they have the same length and differ in exactly one position. For example, Penguin1 and Penguin2 are similar because they differ only in the last character, but Penguin1 and 2Penguin are not similar.
You are given n account names, each of the same length L, consisting of 64 possible characters (uppercase, lowercase letters, digits, underscore, and '@'). No two account names are the same. Your task is to count the number of pairs of account names that are similar.
The formula used to count similar pairs for a particular pattern is given by:
\[ \text{pairs} = \frac{\left( \left(\sum_{i=1}^{k} c_i\right)^2 - \sum_{i=1}^{k} c_i^2 \right)}{2} \]
where each ci is the frequency of a removed character in a fixed position pattern. Each similar pair is counted exactly once.
inputFormat
The first line contains a single integer n (the number of account names). Each of the following n lines contains an account name consisting of exactly L characters.
outputFormat
Output a single integer, the number of pairs of account names that are similar.
sample
3
Penguin1
Penguin2
Penguin3
3
</p>