#C5660. Count Unique Substrings

    ID: 49334 Type: Default 1000ms 256MiB

Count Unique Substrings

Count Unique Substrings

You are given a string S. Your task is to compute the number of unique substrings of S. A substring is defined as a contiguous sequence of characters within the string. Note that even though a string of length n has at most \(\frac{n(n+1)}{2}\) substrings when all are distinct, duplicates may occur. For example, if S = "aaa", the unique substrings are "a", "aa", and "aaa".

Examples:

  • If S = "a", the answer is 1.
  • If S = "ab", the answer is 3 ("a", "b", "ab").
  • If S = "abc", the answer is 6 ("a", "b", "c", "ab", "bc", "abc").

Write a program that reads the input string from standard input and outputs the number of unique substrings to standard output.

inputFormat

The input consists of a single line containing the string S.

outputFormat

Output a single integer representing the number of unique substrings of the input string.

## sample
a
1

</p>