#include<iostream> #include<cstring> #define maxn 3000010 #define ll long long #define uint unsigned int usingnamespacestd;
int n, m; char s[maxn], t[maxn];
int nxt[maxn]; voidinit_nxt(char *s){ int k = 0, l = strlen(s + 1); nxt[1] = 0; for (int i = 2; i <= l; ++i) { while (k && s[k + 1] != s[i]) k = nxt[k]; if (s[k + 1] == s[i]) ++k; nxt[i] = k; } }
uint d[maxn], dd[maxn]; voidkmp(char *s, char *t){ int k = 0, l1 = strlen(s + 1), l2 = strlen(t + 1); for (int i = 1; i <= l1; ++i) { while (k && s[i] != t[k + 1]) k = nxt[k]; if (t[k + 1] == s[i]) ++k; if (k == l2) d[i] = 1; d[i] += d[i - 1]; } for (int i = 1; i <= l1; ++i) dd[i] += dd[i - 1] + d[i]; }
structManacher { int n, l, f[maxn * 2], Len; char s[maxn * 2];
voidinit(char *c){ l = strlen(c + 1); s[0] = '~'; for (int i = 1, j = 2; i <= l; ++i, j += 2) s[j] = c[i], s[j - 1] = '#'; n = 2 * l + 1; s[n] = '#'; s[n + 1] = '\0'; } voidmanacher(){ int p = 0, mr = 0; for (int i = 1; i <= n; ++i) f[i] = 0; for (int i = 1; i <= n; ++i) { if (i < mr) f[i] = min(f[2 * p - i], mr - i); while (s[i + f[i]] == s[i - f[i]]) ++f[i]; --f[i]; if (f[i] + i > mr) mr = i + f[i], p = i; Len = max(Len, f[i]); } } } M;
int a[maxn]; uint solve(){ for (int i = 1; i <= 2 * n + 1; ++i) { int L = i - M.f[i] + 1 >> 1, R = i + M.f[i] - 1 >> 1, len = R - L + 1; if (!M.f[i] || ~len & 1) continue; a[L + len / 2] = len / 2; } int l = m / 2; uint ans = 0; for (int i = 1; i <= n; ++i) { if (l > a[i]) continue; ans += dd[i + a[i]] - dd[i + l - 1]; ans -= dd[i + m - l - 2] - (i + m - a[i] - 3 >= 0 ? dd[i + m - a[i] - 3] : 0); //for (int j = l; j <= a[i]; ++j) ans += d[i + j] - d[i + m - 1 - j - 1]; } return ans; }
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> m >> s + 1 >> t + 1; init_nxt(t); kmp(s, t); M.init(s), M.manacher(); cout << solve() << "\n"; return0; }