Problems > How Many Distinct Substrings

How Many Distinct Substrings

Difficulty: 2300 6000 ms 128 MB

strings suffix-array

Count the DISTINCT non-empty substrings of S.

Input: one line with the string S.

Output: the number of distinct substrings.

Constraints:

  • 1 ≤ |S| ≤ 105
  • lowercase letters

Sample Tests

Input 1
ababa
Output 1
9
Input 2
aaa
Output 2
3

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.