SAC '22 Code Challenge 4 P2 - Obligatory String Problem

View as PDF

Submit solution


Points: 5
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

After grading too many tests, Mr. DeMello decided to start grading strings instead.

Mr. DeMello has the correct 4-letter, lowercase string, C, which he will use to grade the other strings.

Now, Mr. DeMello considers all possible 4-letter, lowercase strings and grades them by finding the minimum distance between each letter in the string (e.g., a and z have a distance of 1), summing it up for their total score.

Since Mr. DeMello knows all his students will get a score of at most K, can you tell him all the possible strings that his students can get?

Input Specification

The first line will contain K (0 \le K \le 52), the maximum score his students can achieve.

The second line will contain C, the intended 4-letter string.

Output Specification

Output all possible strings in sorted alphabetical order (e.g., abc should appear before bac).

Sample Input

1
abcd

Sample Output

aacd
abbd
abcc
abcd
abce
abdd
accd
bbcd
zbcd

Comments

There are no comments at the moment.