C. Cow and Message
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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 s of lowercase Latin letters. She considers a string t as hidden in string s if t exists as a subsequence of s whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices 1, 3, and 5, which form an arithmetic progression with a common difference of 2. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of S 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 3 times, b is hidden 2 times, ab is hidden 6 times, aa is hidden 3 times, bb is hidden 1 time, aab is hidden 2 times, aaa is hidden 1 time, abb is hidden 1 time, aaab is hidden 1 time, aabb is hidden 1 time, and aaabb is hidden 1 time. The number of occurrences of the secret message is 6.

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

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

Examples
inputCopy
aaabb
outputCopy
6
inputCopy
usaco
outputCopy
1
inputCopy
lol
outputCopy
2
Note
In the first example, these are all the hidden strings and their indice sets:

a occurs at (1), (2), (3)
b occurs at (4), (5)
ab occurs at (1,4), (1,5), (2,4), (2,5), (3,4), (3,5)
aa occurs at (1,2), (1,3), (2,3)
bb occurs at (4,5)
aab occurs at (1,3,5), (2,3,4)
aaa occurs at (1,2,3)
abb occurs at (3,4,5)
aaab occurs at (1,2,3,4)
aabb occurs at (2,3,4,5)
aaabb occurs at (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.

题意:就是说给了个字符串,你找的组成每个子串的字符需要下标为等差数列
问你出现最多次的子串次数为多少

思路:首先我们可以知道个数子串长度为1 或者长度为2的 一定满足等差数列
我们只要找字串长度为1或者长度为2的最大值即可
这里你可能会问 为什么不去找长度≥3的子串的个数呢
想一下 比如 有 abc abc这样两个 那么就有2个a 2个b 2个c 2个ab 2个ac 2个bc
其实就是说当长度大于等于3时候,满足要求的子串是越来越少的
可能你还会问 为什么子串长度为2的也要算呢? 因为可能是这样 aaaa
子串最大值个数应该是6 也就是2个a组成的 显然比单个a 只有4个子串多
那么数组标记 边计算边找最大值即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define me(a,x) memset(a,x,sizeof a)
#define debug(x) cout<<"look at sb 【"<<x<<"】"<<endl;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define all(x) (x).begin(), (x).end()
#define pb(a) push_back(a)
#define paii pair<int,int>
#define pali pair<ll,int>
#define pail pair<int,ll>
#define pall pair<ll,ll>
#define fi first
#define se second
ll a[130],b[130][130];//数组a标记单个字符出现的次数 数组b表示子串中字符i和字符j组成的个数
int main()
{
   string s;cin>>s;
   int len=s.size();
   ll ans=0;
   rep(i,0,len){

      repd(j,'a','z'){

       b[j][s[i]]+=a[j];///计算字符s[i]前面出现过的字符j个个数
       ans=max(ans,b[j][s[i]]);
      }
      a[s[i]]++;
      ans=max(ans,a[s[i]]);
   }
   cout<<ans<<endl;
   return 0;
}