#C5220. Counting Distinct Substrings

    ID: 48846 Type: Default 1000ms 256MiB

Counting Distinct Substrings

Counting Distinct Substrings

You are given a string s. Your task is to compute the total number of distinct, non-empty substrings of s. A substring is defined as a contiguous sequence of characters in the string.

For example, consider the string s = "ab". Its non-empty substrings are "a", "b", and "ab", all of which are distinct. Hence, the answer is 3.

Note: The theoretical maximum number of substrings of a string of length n is given by the formula $\frac{n(n+1)}{2}$, but duplicate substrings are only counted once.

inputFormat

The input consists of a single line containing the string s. The string can be empty and will have a reasonable length.

Input Format:

s

outputFormat

Output a single integer denoting the number of distinct non-empty substrings of the input string s.

Output Format:

result
## sample
a
1

</p>