#K34717. Unique Substrings

    ID: 25372 Type: Default 1000ms 256MiB

Unique Substrings

Unique Substrings

You are given a word (a string) and an integer k. Your task is to find all unique substrings of the word with length k and output them in lexicographical (dictionary) order.

The first line of input contains the string word. The second line contains the integer k. If k is greater than the length of the word, the output should be 0 followed by no substrings.

For example, when the input is:

abacaba
3

The unique substrings of length 3 are: "aba", "aca", "bac", and "cab" (listed in lexicographical order), and the count is 4.

inputFormat

The input consists of two lines.

  • The first line contains the string word.
  • The second line contains an integer k representing the length of substrings.

outputFormat

Output to stdout. The first line should be an integer representing the number of unique substrings of length k. Each of the following lines should contain one substring in lexicographical order.

## sample
abacaba
3
4

aba aca bac cab

</p>