#C724. Count Distinct Substrings

    ID: 51089 Type: Default 1000ms 256MiB

Count Distinct Substrings

Count Distinct Substrings

Given a string \(S\) and an integer \(K\), compute the number of distinct substrings of \(S\) that have exactly \(K\) characters. A substring is a contiguous sequence of characters in \(S\). If \(K\) is greater than the length of \(S\), the result is zero.

For example:

Input: S = "banana", K = 3
Output: 3

Here, the distinct substrings of length 3 are "ban", "ana", and "nan".

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains the string \(S\).
  2. The second line contains an integer \(K\), representing the desired substring length.

outputFormat

The output is a single integer printed to standard output (stdout) representing the number of distinct substrings of length \(K\) from string \(S\).

## sample
banana
3
3