Prefix-Suffixes
Time limit1sMemory limit128 MB
Count proper borders summed over all substrings of a given lowercase word of length up to 10^5.
- Level
Hard9 of 10
- Topics
- String matching, String, Prefix sum
- Solved
- No attempts yet
Problem
A prefix-suffix (a border) of a word is a word that is both a prefix (an initial fragment) and a suffix (a final fragment) of . A proper prefix-suffix of is any prefix-suffix that is non-empty and strictly shorter than . Let denote the number of proper prefix-suffixes of . Let denote the substring of that starts at position and ends at position ; positions are numbered from .
Given a word , compute the total number of proper prefix-suffixes over all substrings of , that is
Input
The first and only line of input contains the word . Its length satisfies , and it consists only of lowercase English letters.
Output
Print a single integer: the total number of proper prefix-suffixes over all substrings of .