使用 collections.Counter 模块可以计算出字符中每个字母出现的次数。

from collections import Counter

s = input().split()
k = int(s.pop())
x = s.pop()
words = s[1:]

target_words = []
cx = Counter(x)
for word in words:
    if word == x:
        continue
    if Counter(word) == cx:
        target_words.append(word)

target_words.sort()
length = len(target_words)
print(length)
if length >= k:
    print(target_words[k-1])