#include<iostream> #include<cstring> #define maxn 1000010 #define ll long long usingnamespacestd;
int n, k; char s[maxn], c[maxn], ans[maxn];
int nxt[maxn]; voidinit_nxt(char *s){ int k = 0, t = 0, n = strlen(s + 1); nxt[1] = 0; for (int i = 2; i <= n; ++i) { while (k && s[k + 1] != s[i]) k = nxt[k]; if (s[k + 1] == s[i]) ++k; nxt[i] = k; } }