#P6216. 回文匹配

回文匹配

Problem Description

For a pair of strings (s1,s2)(s_1, s_2), for every substring [l,r][l, r] of s1s_1 with odd length, if [l,r][l, r] is a palindrome, then the “score” of s1s_1 increases by the number of occurrences of s2s_2 inside [l,r][l, r].

Now you are given a pair (s1,s2)(s_1, s_2). Please compute the “score” of s1s_1.

Output the answer modulo 2322 ^ {32}.

Input Format

The first line contains two integers n,mn, m, representing the lengths of s1s_1 and s2s_2.

The second line contains two strings s1,s2s_1, s_2.

Output Format

Output one integer on a single line, representing the score of s1s_1.

10 2
ccbccbbcbb bc
4
20 2
cbcaacabcbacbbabacca ba

4

Hint

Sample Explanation

For sample 1:

s2s_2 appears once in the substring [1,5][1, 5], and once in the substring [2,4][2, 4].

s2s_2 appears once in the substring [7,9][7, 9], and once in the substring [6,10][6, 10].


Constraints

This problem uses bundled testdata.

  • For 100%100\% of the testdata: 1n,m3×1061 \le n, m \le 3 \times 10 ^ 6, and all characters in the strings are lowercase letters.

  • Detailed constraints:

    Subtask ID n,mn, m \le Points
    11 100100 1515
    22 10310 ^ 3
    33 5×1035 \times 10 ^ 3 2020
    44 4×1054 \times 10 ^ 5 3030
    55 3×1063 \times 10 ^ 6 2020

Translated by ChatGPT 5