Avito Cool Challenge 2018
H
Palindromic Magic
Codeforces
3500
原题
← G→
翻译中…

After learning some fancy algorithms about palindromes, Chouti found palindromes very interesting, so he wants to challenge you with this problem.

翻译中…

Chouti has got two strings $A$ and $B$. Since he likes palindromes, he would like to pick $a$ as some non-empty palindromic substring of $A$ and $b$ as some non-empty palindromic substring of $B$. Concatenating them, he will get string $ab$.

翻译中…

Chouti thinks strings he could get this way are interesting, so he wants to know how many different strings he can get.

翻译中…

Input

翻译中…

The first line contains a single string $A$ ($1 \le |A| \le 2 \cdot 10^5$).

翻译中…

The second line contains a single string $B$ ($1 \le |B| \le 2 \cdot 10^5$).

翻译中…

Strings $A$ and $B$ contain only lowercase English letters.

翻译中…

Output

翻译中…

The first and only line should contain a single integer — the number of possible strings.

翻译中…

Note

翻译中…

In the first example, attainable strings are

翻译中…
  • "a" + "a" = "aa",
  • "aa" + "a" = "aaa",
  • "aa" + "aba" = "aaaba",
  • "aa" + "b" = "aab",
  • "a" + "aba" = "aaba",
  • "a" + "b" = "ab".
翻译中…

In the second example, attainable strings are "aa", "aaa", "aaaa", "aaaba", "aab", "aaba", "ab", "abaa", "abaaa", "abaaba", "abab", "ba", "baa", "baba", "bb".

翻译中…

Notice that though "a"+"aa"="aa"+"a"="aaa", "aaa" will only be counted once.

翻译中…

样例

Input #1
aa
aba
Output #1
6
InputCopy OutputCopy
Input #2
aaba
abaa
Output #2
15
InputCopy OutputCopy
题目信息
题号
1081H
时间限制
2.5 s
内存限制
1024 MB
标签
数据结构
哈希
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。