CF1307C Cow and Message
题目描述
贝茜刚刚截取了来自约翰发送出去的讯息!但是,贝茜很肯定里面一定有隐藏的讯息。
讯息是一个字符串 $s$ ,全部都是由小写拉丁字母字符构成。她认为一个字符串 $t$ 是隐藏的当且仅当 $t$ 是 $s$ 的子序列且 $t$ 在 $s$ 中出现的下标构成了一个等差数列(公差必须为一个**正整数**)。
例如,字符串`aab`是隐藏在字符串`aaabb`因为`aab`出现在$s$的下标$1,3,5$,这刚好构成了一个等差数列,而公差是 $2$。贝茜觉得秘密讯息讯息一定是隐藏最多次的那一个字符串。两个 $s$ 中的子序列是不同的当且仅当两个字符串在 $s$ 中出现的下标是不同的。 请帮贝茜找出秘密讯息在 $s$ 中出现的次数吧。
例如,在字符串`aaabb`中,
`a`隐藏了 $3$ 次,
`b`隐藏了 $2$ 次,
`ab`隐藏了 $6$ 次,
`aa`隐藏了 $3$ 次,
`bb`隐藏了 $1$ 次,
`aab`隐藏了 $2$ 次,
`aaa`隐藏了 $1$ 次,
`abb`隐藏了 $1$ 次,
`aaab`隐藏了 $1$ 次,
`aabb`隐藏了 $1$ 次,
`aaabb`隐藏了 $1$ 次,
秘密讯息出现的次数是 $6$ 次。
输入格式
一行一个字符串 $s$,表示截取得到的讯息。这里用 $\lvert s \rvert$ 表示字符串 $s$ 的长度,则有$1 \leq \lvert s \rvert \leq 10^5$。
输出格式
一行一个整数,表示秘密讯息出现的次数。
说明/提示
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.