eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач

PIN

Martin has just been hired as a computer administrator in a big company. The company did not change its authorization system since \textbf{1980}s. Every person has a four-digit personal identification number (\textbf{PIN}). Nobody uses usernames or passwords, you can login just by typing your \textbf{PIN}. As the company grew, they added the possibility to use letters as well, but the length of the \textbf{PIN} remained the same. Martin is not happy with the situation. Suppose there are people whose \textbf{PIN}s differ only at a single place, for example \textbf{61ab} and \textbf{62ab}. If the first person accidentally presses \textbf{2} instead of \textbf{1}, the system would still let him in. Martin would like to make the statistics about the \textbf{PIN}s currently in use, in particular, compute the number of pairs of \textbf{PIN}s that differ at \textbf{1}, \textbf{2}, \textbf{3} or \textbf{4} positions. He hopes that these numbers will be alarming enough to convince his boss to invest in a better system. Given the list of \textbf{PIN}s and an integer \textbf{D}, find the number of pairs of \textbf{PIN}s that differ at exactly \textbf{D} positions. \InputFile The first line of the input contains two space-separated positive integers \textbf{N} and \textbf{D}, where \textbf{N} is the number of \textbf{PIN}s and \textbf{D} is the chosen number of differences. Each of the following \textbf{N} lines contains a single \textbf{PIN}. \textbf{Constraints} You may assume that in all test cases \textbf{2} ≤ \textbf{N} ≤ \textbf{50000} and \textbf{1} ≤ \textbf{D} ≤ \textbf{4}. Each \textbf{PIN} is of length \textbf{4} and each character is either a digit or a lowercase letter between '\textbf{a}' and '\textbf{z}', inclusive. You may assume that all \textbf{PIN}s in the input are different. In test cases worth \textbf{15} points, \textbf{N} ≤ \textbf{2000}. In test cases worth \textbf{60} points, \textbf{D} ≤ \textbf{2}. Out of those, in test cases worth \textbf{30} points, \textbf{D = 1}. In test cases worth \textbf{75} points, every \textbf{PIN} will only consist of digits or lowercase letters between '\textbf{a}' and '\textbf{f}', inclusive. Thus it can be viewed as a hexadecimal number. \OutputFile Output a single line with a single number: the number of pairs of \textbf{PIN}s that differ at \textit{\textbf{exactly}} \textbf{D} positions.
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
4 1
0000
a010
0202
a0e2
Выходные данные #1
0
Автор Lukáš Poláček