#K48967. Count Distinct Substrings

    ID: 28538 Type: Default 1000ms 256MiB

Count Distinct Substrings

Count Distinct Substrings

Given a string (s), your task is to compute the number of distinct non-empty substrings in (s). A substring is defined as a contiguous sequence of characters within the string. Formally, if (s) has length (n), consider the set (S = { s[i:j] \mid 0 \le i < j \le n }). The goal is to calculate (|S|), the cardinality of this set. For example, for (s = \texttt{ab}), the distinct substrings are: ({\texttt{a}, \texttt{b}, \texttt{ab}}), so the answer is 3.

inputFormat

Input is provided via standard input (stdin) and consists of a single line containing the string (s). The string may be empty and will consist of lowercase letters.

outputFormat

Output the number of distinct non-empty substrings in (s) to standard output (stdout) as a single integer.## sample

ab
3

</p>