#P6521. String Pairs with Exact Differences
String Pairs with Exact Differences
String Pairs with Exact Differences
You are given n strings, each of length 4, and an integer D. Your task is to count the number of pairs of strings that differ in exactly D positions.
For example, if two strings are "abcd" and "abcf", they differ in only the 4th character. If D was 1, this pair would be counted; otherwise, it would not. Note that the positions are compared one-by-one.
Input Format: The first line contains two integers n and D. The next n lines each contain a string of exactly 4 characters.
Output Format: Output a single integer, the number of valid pairs.
inputFormat
The first line contains two integers n and D separated by space.
Then follow n lines, each containing a 4-character string.
outputFormat
Output a single integer which is the number of pairs with exactly D differing positions.
sample
3 2
abcd
abcf
abdf
1