This page is still under construction.

Parts of this page are still being built. What you see may change.

Strange Strings

Time limit1sMemory limit512 MB

Summary
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 ss consisting of lowercase Latin letters. One example of such a string is «abba».

A substring of ss is a string formed from one or more consecutive characters of ss. Let W(s)W(s) be the set of all substrings of ss. Each substring appears in this set at most once, even if it occurs several times in ss.

For example, W(«abba»)={«a»,«b»,«ab»,«ba»,«bb»,«abb»,«bba»,«abba»}W(\text{«abba»}) = \{\text{«a»}, \text{«b»}, \text{«ab»}, \text{«ba»}, \text{«bb»}, \text{«abb»}, \text{«bba»}, \text{«abba»}\}.

A subsequence of ss is a string obtained from ss by deleting any number of characters. Let Y(s)Y(s) be the set of all subsequences of ss. As with W(s)W(s), each subsequence of ss is included in Y(s)Y(s) exactly once, even if it can be obtained by several different ways of deleting characters from ss. Since every substring of ss is also a subsequence of ss, the set Y(s)Y(s) contains W(s)W(s), but it may also contain other strings.

For example, Y(«abba»)=W(«abba»)∪{«aa»,«aba»}Y(\text{«abba»}) = W(\text{«abba»}) \cup \{\text{«aa»}, \text{«aba»}\}. The symbol ∪\cup denotes the union of sets.

Call a string ss strange if W(s)=Y(s)W(s) = Y(s). For instance, «abba» is not strange, but «abb» is, since W(«abb»)=Y(«abb»)={«a»,«b»,«ab»,«bb»,«abb»}W(\text{«abb»}) = Y(\text{«abb»}) = \{\text{«a»}, \text{«b»}, \text{«ab»}, \text{«bb»}, \text{«abb»}\}.

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 ss. 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 ss, determines its strangeness.

Input

The input file contains a string ss 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.

Examples1

  1. Example 1

    Input
    abba
    
    Expected output
    7