I - Cutting Suffix

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

InputcopyOutputcopy
aa
1
InputcopyOutputcopy
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;
}

  • 7
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值