Pinely Round 3 (Div. 1 + Div. 2)
G
Pumping Lemma
Codeforces
3000
原题
← F2H →
翻译中…

You are given two strings $s$, $t$ of length $n$, $m$, respectively. Both strings consist of lowercase letters of the English alphabet.

翻译中…

Count the triples $(x, y, z)$ of strings such that the following conditions are true:

翻译中…
  • $s = x+y+z$ (the symbol $+$ represents the concatenation);
  • $t = x+\underbrace{ y+\dots+y }_{k \text{ times}} + z$ for some integer $k$.
翻译中…

Input

翻译中…

The first line contains two integers $n$ and $m$ ($1 \leq n \lt m \leq 10^7$) — the length of the strings $s$ and $t$, respectively.

翻译中…

The second line contains the string $s$ of length $n$, consisting of lowercase letters of the English alphabet.

翻译中…

The third line contains the string $t$ of length $m$, consisting of lowercase letters of the English alphabet.

翻译中…

Output

翻译中…

Output a single integer: the number of valid triples $(x, y, z)$.

翻译中…

Note

翻译中…

In the first test case, the only valid triple is $(x, y, z) = (\texttt{"a"}, \texttt{"bc"}, \texttt{"d"})$. In fact,

翻译中…
  • $\texttt{"abcd"} = \texttt{"a"} + \texttt{"bc"} + \texttt{"d"}$;
  • $\texttt{"abcbcbcd"} = \texttt{"a"} + \texttt{"bc"} + \texttt{"bc"} + \texttt{"bc"} + \texttt{"d"}$.
翻译中…

In the second test case, there are $5$ valid triples:

翻译中…
  • $(x, y, z) = (\texttt{""}, \texttt{"a"}, \texttt{"aa"})$;
  • $(x, y, z) = (\texttt{""}, \texttt{"aa"}, \texttt{"a"})$;
  • $(x, y, z) = (\texttt{"a"}, \texttt{"a"}, \texttt{"a"})$;
  • $(x, y, z) = (\texttt{"a"}, \texttt{"aa"}, \texttt{""})$;
  • $(x, y, z) = (\texttt{"aa"}, \texttt{"a"}, \texttt{""})$.
翻译中…

In the third test case, there are $8$ valid triples:

翻译中…
  • $(x, y, z) = (\texttt{"ab"}, \texttt{"ba"}, \texttt{"babacaab"})$;
  • $(x, y, z) = (\texttt{"abb"}, \texttt{"ab"}, \texttt{"abacaab"})$;
  • $(x, y, z) = (\texttt{"abba"}, \texttt{"ba"}, \texttt{"bacaab"})$;
  • $(x, y, z) = (\texttt{"ab"}, \texttt{"baba"}, \texttt{"bacaab"})$;
  • $(x, y, z) = (\texttt{"abbab"}, \texttt{"ab"}, \texttt{"acaab"})$;
  • $(x, y, z) = (\texttt{"abb"}, \texttt{"abab"}, \texttt{"acaab"})$;
  • $(x, y, z) = (\texttt{"abbaba"}, \texttt{"ba"}, \texttt{"caab"})$;
  • $(x, y, z) = (\texttt{"abba"}, \texttt{"baba"}, \texttt{"caab"})$.
翻译中…

样例

Input #1
4 8
abcd
abcbcbcd
Output #1
1
InputCopy OutputCopy
Input #2
3 5
aaa
aaaaa
Output #2
5
InputCopy OutputCopy
Input #3
12 16
abbababacaab
abbababababacaab
Output #3
8
InputCopy OutputCopy
题目信息
题号
1909G
时间限制
2 s
内存限制
1024 MB
标签
哈希
字符串

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