In the event of technical difficulties with Szkopuł, please contact us via email at [email protected].
If you are familiar with IRC chat, the support team is also reachable on PIRC network (
#szkopul channel. If you are not, just use email.
Please do not ask us things like "how to solve task XYZ?".
Please remember that the support team has to sleep sometimes or go to work in real life.
Martin has just been hired as a computer administrator in a big company. The company did not change its authorization system since 1980s. Every person has a four-digit personal identification number (PIN). Nobody uses usernames or passwords, you can login just by typing your PIN. As the company grew, they added the possibility to use letters as well, but the length of the PIN remained the same.
Martin is not happy with the situation. Suppose there are people whose PINs differ only at a single place, for example 61ab and 62ab. If the first person accidentally presses 2 instead of 1, the system would still let him in. Martin would like to make the statistics about the PINs currently in use, in particular, compute the number of pairs of PINs that differ at 1, 2, 3 or 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 PINs and an integer , find the number of pairs of PINs that differ at exactly positions.
The first line of the input contains two space-separated positive integers and , where is the number of PINs and is the chosen number of differences. Each of the following lines contains a single PIN.
You may assume that in all test cases and .
Each PIN is of length 4 and each character is either a digit or a lowercase letter between 'a' and 'z', inclusive. You may assume that all PINs in the input are different.
In test cases worth 15 points, .
In test cases worth 60 points, . Out of those, in test cases worth 30 points, .
In test cases worth 75 points, every PIN will only consist of digits or lowercase letters between 'a' and 'f', inclusive. Thus it can be viewed as a hexadecimal number.
Output a single line with a single number: the number of pairs of PINs that differ at exactly positions.
For the input data:
4 1 0000 a010 0202 a0e2
the correct result is:
For these PINs each pair of PINs differs at more than one position.
For the input data:
4 2 0000 a010 0202 a0e2
There are three pairs that differ at exactly 2 positions: (0000, a010), (0000, 0202), and (a010, a0e2).
Task author: Lukas Polacek.