Strange Strings
Time limit1sMemory limit512 MB
Given a string s, count the number of distinct substrings t such that the set of substrings of t equals the set of subsequences of t.
- Level
Hard8 of 10
- Topics
- String, Hash map, Greedy, Combinatorics
- Solved
- No attempts yet
Statement
Consider a string consisting of lowercase Latin letters. One example of such a string is «abba».
A substring of is a string formed from one or more consecutive characters of . Let be the set of all substrings of . Each substring appears in this set at most once, even if it occurs several times in .
For example, .
A subsequence of is a string obtained from by deleting any number of characters. Let be the set of all subsequences of . As with , each subsequence of is included in exactly once, even if it can be obtained by several different ways of deleting characters from . Since every substring of is also a subsequence of , the set contains , but it may also contain other strings.
For example, . The symbol denotes the union of sets.
Call a string strange if . For instance, «abba» is not strange, but «abb» is, since .
Call the strangeness of a string the number of its distinct strange substrings. When computing the strangeness, a substring is counted once, even if it occurs several times as a substring of . For example, the strangeness of «abba» is 7: every substring of it except the whole string is strange.
Write a program that, given a string , determines its strangeness.
Input
The input file contains a string consisting of lowercase Latin letters. The length of the string is between 1 and 200,000.
Output
The output file must contain a single integer: the strangeness of the string given in the input file.