CodeForces - 1307C C - Cow and Message

Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.

The text is a string ss of lowercase Latin letters. She considers a string tt as hidden in string ss if tt exists as a subsequence of ss whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices 11, 33, and 55, which form an arithmetic progression with a common difference of 22. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of SS are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!

For example, in the string aaabb, a is hidden 33 times, b is hidden 22 times, ab is hidden 66 times, aa is hidden 33 times, bb is hidden 11 time, aab is hidden 22 times, aaa is hidden 11 time, abb is hidden 11 time, aaab is hidden 11 time, aabb is hidden 11 time, and aaabb is hidden 11 time. The number of occurrences of the secret message is 66.

Input

The first line contains a string ss of lowercase Latin letters (1≤|s|≤1051≤|s|≤105) — the text that Bessie intercepted.

Output

Output a single integer  — the number of occurrences of the secret message.

Examples

Input

aaabb

Output

6

Input

usaco

Output

1

Input

lol

Output

2

Note

In the first example, these are all the hidden strings and their indice sets:

  • a occurs at (1)(1), (2)(2), (3)(3)
  • b occurs at (4)(4), (5)(5)
  • ab occurs at (1,4)(1,4), (1,5)(1,5), (2,4)(2,4), (2,5)(2,5), (3,4)(3,4), (3,5)(3,5)
  • aa occurs at (1,2)(1,2), (1,3)(1,3), (2,3)(2,3)
  • bb occurs at (4,5)(4,5)
  • aab occurs at (1,3,5)(1,3,5), (2,3,4)(2,3,4)
  • aaa occurs at (1,2,3)(1,2,3)
  • abb occurs at (3,4,5)(3,4,5)
  • aaab occurs at (1,2,3,4)(1,2,3,4)
  • aabb occurs at (2,3,4,5)(2,3,4,5)
  • aaabb occurs at (1,2,3,4,5)(1,2,3,4,5)

Note that all the sets of indices are arithmetic progressions.

In the second example, no hidden string occurs more than once.

In the third example, the hidden string is the letter l.

求最大子串出现个数

注意开long long

#include<bits/stdc++.h>
int t;
long long cnt[30];
using namespace std;
string a;
map<string, long long> mp;
string cha;
void solve(){
    cin >> a;
    long long ans = 0;
    long long one = 0;
    for(int i = 0; i < a.size(); i++){
        for(int j = 0; j <= 26; j++){
            if(cnt[j]){
                cha.clear();
                cha += a[i];
                cha += 'a' + j;
                mp[cha] += cnt[j];
                ans = max(ans, mp[cha]);
            }
        }
        cnt[a[i] - 'a']++;
        one = max(one, cnt[a[i] - 'a']);
    }
    cout << max(ans, one) << endl;
}

int main(){
    ios::sync_with_stdio(0);
    t = 1;
    while(t--){
        solve();
    }

    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值