Given a string S of length n consisting of lowercase English characters. We denote Suffix(i) as the suffix of S starting from the i-th character. We define w(i,j) as the length of the LCP of Suffix(i) and Suffix(j). LCP is the longest common prefix of two strings. For example, the LCP of abca and abd is ab.
You should divide the integers from 1 to n into two non-empty complementary sets T1,T2. We define the value of this partition as follows.
∑ ∑ w(i,j)
i∈T1 j∈T2
Please find a partition to minimize the value.
Input
The input contains a string SS of length nn (2≤n≤1052≤n≤105) in a single line, consisting of only lowercase English letters.
Output
Output a single integer indicating the minimum value.
Examples
Inputcopy | Outputcopy |
---|---|
aa | 1 |
Inputcopy | Outputcopy |
---|---|
ab | 0 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int flag=1;
for(int i=0;i<s.size()-1;i++)
{
if(s[i]!=s[i+1])
flag=0;
}
if(flag) cout<<s.size()-1<<endl;
else cout<<0;
return 0;
}