#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; struct SuffixArray{ int n, k; vector rk, tmp, sa; string s; SuffixArray(string s):n(s.size()), s(s), rk(s.size()+1), tmp(s.size()+1), sa(s.size()+1){ auto compare_sa=[&](int i, int j){ if(rk[i]!=rk[j]) return rk[i] lcp; LCP(SuffixArray sa):sa(sa), lcp(sa.n){ int h=0; lcp[0]=0; for(int i=0; i0) h--; for(; j+h manacher(const string &s) { vector< int > radius(s.size()); int i = 0, j = 0; while(i < s.size()) { while(i - j >= 0 && i + j < s.size() && s[i - j] == s[i + j]) { ++j; } radius[i] = j; int k = 1; while(i - k >= 0 && i + k < s.size() && k + radius[i - k] < j) { radius[i + k] = radius[i - k]; ++k; } i += k; j -= k; } return radius; } int main() { int n, m; string s, t; cin>>s>>t; n=s.size(), m=t.size(); string u=s+"a"+t; vector> rs(2, vector(n)), rt(2, vector(m)); rs[1]=manacher(s), rt[1]=manacher(t); { string s0, t0; s0+='#'; t0+='#'; for(int i=0; i rs0=manacher(s0), rt0=manacher(t0); for(int i=0; i> rd(2, vector(n+m)); for(int i=1; i<=n+m; i++){ if(sa[i]void{ if(l>r) return; int mid=(l+r)/2; vector mnl(mid-l+1), mnr(r-mid+1); mnl[mid-l]=lcp[mid]; for(int i=mid-1; i>=l; i--){ mnl[i-l]=min(mnl[i+1-l], lcp[i]); } mnr[0]=lcp[mid]; for(int i=mid+1; i<=r; i++){ mnr[i-mid]=min(mnr[i-1-mid], lcp[i]); } for(int p=0; p<2; p++){ vector vls, vlt; vector sls, slt; for(int i=mid; i>=l; i--){ int x=min(mnl[i-l], rd[p][i-1]); if(sa[i]