Z-algorithm sum

Write codeMedium25 min

Your task

Given a string s, return the SUM over all indices i of the length of the longest common prefix between s and the suffix of s starting at i (for i=0 this is len(s) itself). 1 <= len(s) <= 100000, lowercase letters. Example: 'ababa' -> z = [5,0,3,0,1], sum = 9.

Examples

sum_z_values(s: str) -> int
Example 1
Inputsum_z_values("ababa")
Output9