#K78817. Count Prefix-Suffix Substrings

    ID: 35171 Type: Default 1000ms 256MiB

Count Prefix-Suffix Substrings

Count Prefix-Suffix Substrings

Given a string (S) of length (n), your task is to count the number of distinct non-empty substrings that appear both as a prefix and as a suffix of (S). In other words, for every (i) (where (1 \leq i \leq n)), check if the prefix (S[1..i]) is equal to the suffix (S[n-i+1..n]). Print the count of all such substrings.

For example, if (S = \texttt{ababa}), the valid substrings are (a), (aba), and (ababa) resulting in an answer of 3.

inputFormat

Input is given from standard input. It consists of a single line containing the string (S). The string (S) may include alphanumeric characters.

outputFormat

Output to standard output a single integer: the count of distinct, non-empty substrings of (S) that are both a prefix and a suffix.## sample

ababa
3