given a string, calculate the longest math of its proper prefix and proper suffix