Suffix automaton
Count the different pieces you can cut from a word by taking consecutive letters. In банан, the piece ан appears twice but counts only once.
Add one character at a time. Substrings ending at the same positions can share a state. Sometimes we split a state by cloning it. Its length minus its suffix link’s length counts the new substrings.