High Security
Time limit3sMemory limit256 MB
Given up to 50000 length-5 passwords over 62 characters, count pairs of passwords for each Hamming distance from 0 to 5.
- Level
Medium7 of 10
- Topics
- String, Combinatorics, Bit manipulation, Hash map
- Solved
- No attempts yet
Problem
Vasya is a system administrator of a new social network called Five Contacts (or simply V Contacts). Security matters a great deal on a social network. One of the biggest threats is spammers, who steal users' passwords and then send spam or cause other harm.
Under the V Contacts security policy, every password is exactly five characters long, and each character is a lowercase English letter, an uppercase English letter, or a digit. Vasya wants to measure how secure the password database is. His metric is based on how similar the passwords are to one another: how many pairs of passwords are identical, how many differ in exactly one position, how many differ in exactly two positions, and so on.
Two passwords are compared position by position. The number of positions in which they differ (their Hamming distance) ranges from (identical) to (different in every position). For every distance from to , count the number of unordered pairs of passwords whose distance is exactly .
Input
The first line contains one integer — the number of users of V Contacts ().
Each of the next lines contains one password: exactly five characters, each a lowercase English letter, an uppercase English letter, or a digit. Passwords are case-sensitive, and the same password may appear more than once.
Output
Print six integers on a single line, separated by single spaces. Here is the number of unordered pairs of passwords that differ in exactly positions. In particular, counts pairs of identical passwords.