#K64547. Distinct Substrings

    ID: 31999 Type: Default 1000ms 256MiB

Distinct Substrings

Distinct Substrings

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

For example, if S = 'abc', the distinct non-empty substrings are a, b, c, ab, bc, and abc, making a total of 6.

The count is based on all possible intervals [i, j] (with i < j) that satisfy the condition. In mathematical notation, if S has length n, then a substring can be represented as ( S[i:j] ) where ( 0 \le i < j \le n ).

inputFormat

The input consists of a single line containing the string S. The string S may be empty or non-empty and will consist of lowercase English letters.

outputFormat

Output a single integer which represents the number of distinct non-empty substrings of S.## sample

abc
6