#K54472. Counting Distinct Substrings

    ID: 29761 Type: Default 1000ms 256MiB

Counting Distinct Substrings

Counting Distinct Substrings

You are given a string \(S\) of length \(N\) and an integer \(L\). Your task is to count the number of distinct substrings of length \(L\) that can be extracted from \(S\) by considering all consecutive substrings.

Formally, for each index \(i\) with \(0 \le i \le N-L\), let \(S[i:i+L]\) be a substring of \(S\). Count how many unique substrings occur among these.

The problem can be summarized by the formula:

[ \text{Answer} = \left|{ S[i:i+L] : 0 \le i \le N - L }\right| ]

Be sure to read the input from standard input and output your answer to standard output.

inputFormat

The input consists of two lines:

  • The first line contains two space-separated integers \(N\) and \(L\), where \(N\) is the length of the string and \(L\) is the length of the substring.
  • The second line contains the string \(S\) of length \(N\).

outputFormat

Output a single integer: the number of distinct substrings of length \(L\) found in \(S\).

## sample
5 3
ABCDE
3

</p>