#C12409. Count Distinct Substrings

    ID: 41833 Type: Default 1000ms 256MiB

Count Distinct Substrings

Count Distinct Substrings

This problem requires you to count the number of distinct substrings of a given length \( k \) in a given string \( s \). A substring is defined as a contiguous sequence of characters within the string. For example, for the input string "abcabc" and \( k = 3 \), the distinct substrings of length 3 are "abc", "bca", and "cab" resulting in an answer of 3.

Input Constraints: The string \( s \) consists of lowercase English letters. The integer \( k \) is non-negative. If \( k \) is larger than the length of \( s \), the answer should be 0.

Mathematical Formulation:
Let \( S \) be a string of length \( n \). For every integer \( i \) such that \( 0 \leq i \leq n-k \), let \( s_i = s[i:i+k] \) denote a substring of length \( k \). The task is to compute the number of distinct substrings among all \( s_i \) for \( i=0,1,\dots,n-k \).

inputFormat

Standard input consists of two lines. The first line contains the string \( s \) and the second line contains the integer \( k \).

outputFormat

Output a single integer representing the number of distinct substrings of length \( k \) in the string \( s \).

## sample
abcabc
3
3