#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); #define F(x) ((x) / 3 + ((x) % 3 == 1 ? 0 : tb))
#define G(x) ((x) < tb ? (x) * 3 + 1 : ((x) - tb) * 3 + 2) int r[ * N], sa[ * N];
int wa[ * N], wb[ * N], wv[ * N], ss[ * N];
int rnk[N], lcp[N]; int c0(int *r, int a, int b) {return r[a] == r[b] && r[a + ] == r[b + ] && r[a + ] == r[b + ]; } int c12(int k, int *r, int a, int b) {
if(k == ) return r[a] < r[b] || r[a] == r[b] && c12(, r, a + , b + );
return r[a] < r[b] || r[a] == r[b] && wv[a + ] < wv[b + ];
} void sort(int *r, int *a, int *b, int n, int m) {
for(int i = ; i < n; i++) wv[i] = r[a[i]];
for(int i = ; i < m; i++) ss[i] = ;
for(int i = ; i < n; i++) ss[wv[i]]++;
for(int i = ; i < m; i++) ss[i] += ss[i - ];
for(int i = n - ; i >= ; i--) b[--ss[wv[i]]] = a[i];
} void DC3(int *r, int *sa, int n, int m) {
int i, j, p;
int *san = sa + n, *rn = r + n;
int ta = , tb = (n + ) / , tbc = ; r[n] = r[n + ] = ;
for(i = ; i < n; i++) if(i % != ) wa[tbc++] = i; sort(r + , wa, wb, tbc, m);
sort(r + , wb, wa, tbc, m);
sort(r, wa, wb, tbc, m); for(p = , rn[F(wb[])] = , i = ; i < tbc; i++)
rn[F(wb[i])] = c0(r, wb[i - ], wb[i]) ? p - : p++; if(p < tbc) DC3(rn, san, tbc, p);
else for(i = ; i < tbc; i++) san[rn[i]] = i; for(i = ; i < tbc; i++) if(san[i] < tb) wb[ta++] = san[i] * ;
if(n % == ) wb[ta++] = n - ; sort(r, wb, wa, ta, m); for(i = ; i < tbc; i++) wv[wb[i] = G(san[i])] = i;
for(i = , j = , p = ; i < ta && j < tbc; p++)
sa[p] = c12(wb[j] % , r, wa[i], wb[j]) ? wa[i++] : wb[j++]; for( ; i < ta; p++) sa[p] = wa[i++];
for( ; j < tbc; p++) sa[p] = wb[j++];
} void calc_LCP(int *r, int *sa, int n) {
int k = ;
for(int i = ; i < n; i++) rnk[sa[i]] = i;
for(int i = ; i < n - ; lcp[rnk[i++]] = k) {
if(k) k--;
for(int j = sa[rnk[i] - ]; r[i + k] == r[j + k]; k++);
}
} int n, m, tot;
char S[N], T[N]; int main() {
scanf("%s%s", S, T);
n = strlen(S); m = strlen(T);
for(int i = ; i < n; i++) r[tot++] = S[i];
r[tot++] = '$';
for(int i = ; i < m; i++) r[tot++] = T[i];
DC3(r, sa, tot + , );
calc_LCP(r, sa, tot + );
return ;
} /*
*/
05-06 11:07