Under construction

Still being built. Things may change

Incomparable Pairs

Time limit3sMemory limit512 MB

Summary
Count unordered pairs of substrings of a string s where neither substring is contained in the other.
Level

Hard8 of 10

Topics
String, Tree, String matching
Solved
No attempts yet

Problem

You are given a string s=s1s2...sns = s_1 s_2 ... s_n. Consider an unordered pair of its substrings {a,b}\{a, b\}. Call such a pair incomparable if neither aa is a substring of bb nor bb is a substring of aa. Compute the number of incomparable pairs of substrings of ss.

Input

The first line contains a single string ss consisting of lowercase English letters (1≤∣s∣≤1051 \le |s| \le 10^5).

Output

Output a single integer, the answer to the problem.

Examples2

  1. Example 1

    Input
    abba
    
    Expected output
    8
    
  2. Example 2

    Input
    abacaba
    
    Expected output
    64