#C6141. Counting Distinct Substrings

    ID: 49869 Type: Default 1000ms 256MiB

Counting Distinct Substrings

Counting Distinct Substrings

Given a string consisting of lowercase English letters, your task is to compute the number of distinct substrings that can be formed from the string. A substring is defined as a contiguous sequence of characters within the string. For example, for the string "abc", the distinct substrings are: "a", "b", "c", "ab", "bc", and "abc".

Note: The well-known formula for the total number of substrings (including duplicates) of a string of length (n) is (\frac{n(n+1)}{2}), but in this problem you need to count only distinct substrings.

Input is read from standard input (stdin) and output is written to standard output (stdout).

inputFormat

The first line of input contains an integer \(n\) indicating the length of the string. The second line contains the string \(s\) of length \(n\) consisting of lowercase English letters.

outputFormat

Output a single integer representing the number of distinct substrings present in the string.

## sample
3
abc
6

</p>