Count of distinct substrings
Every substring is the start of some suffix. Insert every suffix into a trie and each distinct substring ends at exactly one node, so counting the nodes counts the substrings, the root standing for the empty string.
In st, i starts the suffix and j is the letter being inserted.