#include<stdio.h> #include<string> #include<map> #include<vector> #include<cmath> #include<stdlib.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; #define rep0(i,n) for(int i=0;i<n;i++) #define rep(i,j,k) for(int i=j;i<k;i++) const int N=2e5+10; const int MOD=1e9+7; int n,m,k,up; char s[N],ss[N]; int cnt[N],f[N],r[N],sa[N],sr[N],height[N]; /* sa[i] 排第i的下标 f[i] 下标为i的排名 */ void getSa(){ up=0; int len=strlen(s); rep0(i,len) ss[i]=s[i]-'*',up=max((int)ss[i],up); up++; rep0(i,up) cnt[i]=0; rep0(i,len) cnt[ f[i]=ss[i] ]++; rep(i,1,up) cnt[i]+=cnt[i-1]; for(int i=len-1;i>=0;i--) sa[ --cnt[f[i]] ]=i; int d=1,p=0; while(d<len){ for(int i=len-d;i<len;i++) sr[p++]=i; rep0(i,len) if(sa[i]>=d) sr[p++]=sa[i]-d; rep0(i,up) cnt[i]=0; rep0(i,len) cnt[f[sr[i]]]++; rep(i,1,up) cnt[i]+=cnt[i-1]; for(int i=len-1;i>=0;i--) sa[--cnt[f[sr[i]]] ]=sr[i]; swap(f,r); p=0; f[sa[0]]=p++; rep0(i,len-1){ if(sa[i]+d<len &&sa[i+1]+d<len && r[sa[i]]==r[sa[i+1]] && r[sa[i]+d]==r[sa[i+1]+d]) f[sa[i+1]]=p-1; else f[sa[i+1]]=p++; } d*=2;up=p;p=0; } rep0(i,len) f[sa[i]]=i; } void getH(){ int len=strlen(s); int p=0; for(int i=0;i<len;i++){ if(f[i]==0) continue; int k=sa[f[i]-1]; while(k+p<len && i+p<len && s[k+p]==s[i+p]) p++; height[i]=p; p=max(0,p-1); } } void solve(char *s1,char *s2){ int len=strlen(s1); strcpy(s,s1); strcpy(s+len,"*"); strcpy(s+len+1,s2); getSa(); getH(); int len2=strlen(s); int res=0; for(int i=0;i<len2;i++){ int k=f[i]; if(k==0) continue; int j=sa[k-1]; if( (i<len && j>len) || (i>len && j<len) ) res=max(res,height[i]); } printf("%d\n",res); } int main(){ #ifndef ONLINE_JUDGE freopen("aaa","r",stdin); #endif int T; char s1[N],s2[N]; while(~scanf("%s%s",s1,s2)){ solve(s1,s2); } return 0; }