a follows z, and repeat it forever in both directions: ...xyzabcd...xyzabc....
You are given a string text of lowercase Latin letters. Count how many **distinct** non-empty substrings of text appear in that endless sequence, meaning each letter is the one right after the previous letter in the alphabet (with z wrapping to a).
Equal substrings found at different places in text are counted once.text='xyzab' → 15
The whole string follows the alphabet ring: x→y→z→a→b. Every substring fits, and there are 5 + 4 + 3 + 2 + 1 = 15 of them, all different.
text='abab' → 3
"a", "b" and "ab" fit. "ba" does not, since b is followed by c. Repeats count once, so the answer is 3.
text='dog' → 3
text.length ≤ 10⁵text consists of lowercase Latin letters onlytext='xyzab'
15
Run checks the first 3 tests in your browser. Submit checks all 69 tests on the server, hidden ones included.