#C3297. Count Distinct Substrings
Count Distinct Substrings
Count Distinct Substrings
Given a string \(S\), your task is to count the number of distinct non-empty substrings in \(S\). A substring of \(S\) is defined as a contiguous sequence of characters within \(S\). For example, if \(S = \texttt{ababc}\), then its distinct substrings include "a", "b", "ab", "ba", "abc", etc.
The problem can be formally stated as follows: For a string \(S\) of length \(n\), consider all substrings \(S[i:j]\) where \(1 \leq i \leq j \leq n\). Determine the number of unique substrings among all these \(\frac{n(n+1)}{2}\) possible substrings.
Note: The input string may be empty, in which case the output should be \(0\).
inputFormat
The input consists of a single line containing the string \(S\). The string may include any characters. An empty line represents an empty string.
Input Format:
S
outputFormat
Output a single integer representing the number of distinct non-empty substrings of \(S\).
Output Format:
result## sample
a
1
</p>