#C3543. Distinct Substrings of a Given Length

    ID: 46982 Type: Default 1000ms 256MiB

Distinct Substrings of a Given Length

Distinct Substrings of a Given Length

You are given a string S and an integer n. Your task is to compute the number of distinct substrings of length n that can be extracted from S. A substring is defined as a contiguous sequence of characters from S. If n is greater than the length of S, output 0.

In mathematical notation, if we denote by \( S[i:i+n] \) the substring of S starting at index \( i \) of length n, then the desired answer is:

[ \text{Result} = \left| \left{ S[i:i+n] : 0 \le i \le |S|-n \right} \right| ]

Make sure your solution reads from stdin and writes the result to stdout.

inputFormat

The input consists of two lines:

  • The first line contains the string S.
  • The second line contains the integer n.

outputFormat

Output a single integer representing the number of distinct substrings of length n.

## sample
abacab
3
4