/*************** Author: sambit1993 ******************/
/* Category: UpdateLater */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <queue>
#include <ctime>
#include <fstream>
#include <sstream>
#include <cmath>
#include <limits>
#include <climits>
#include <bitset>
#include <iomanip>
#include <stack>
#ifndef ONLINE_JUDGE
#define gc getchar
#else
#define gc getchar_unlocked
#endif
#define s(x) scanf("%d",&x)
#define sil(x) scanf("%llu",&x)
#define sd(x) scanf("%ld",&x)
#define ri(x) x=read<int>()
#define rl(x) x=read<ll>()
#define ru(x) x=read<ull>()
#define FOR(i,a,b) for( int i=(a); i<(b); ++i) // exclusive for
#define FORR(i,a,b) for( int i=(a-1) ; i>=(b); --i)
#define REP(k,a,b) for(int k=(a); k <= (b); ++k) // inclusive for
#define REPR(i,a,b) for( int i=(a) ; i>=(b); --i)
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define SRT(v) std::sort(ALL(v))
#define CTN(x) std::cout<<x<<'\n' //cout with newline
#define CTS(x) std::cout<<x<<" " //cout with space
#define CLR(x) std::memset(x,0,sizeof(x))
#define FILL(x,n) std::fill_n(x,sizeof(x),n)
#define T(t) int t; ri(t); while(t--)
#define DBGA(x,n) {for(int i=0;i<n;i++) cerr<<x[i]<<" "; cerr<<"\n";}
#define REC(x) clock_t x=clock()
#define CPS CLOCKS_PER_SEC
#define TM(x,y) CTN(((double)(y-x)/CPS))
#define abs(x) ((x)>0?(x):(-(x)))
typedef std::vector<int> VI;
typedef std::vector<long long int> VL;
typedef std::vector<std::string> VS;
typedef std::pair<int,int> PII;
typedef unsigned long long ull;
typedef long long ll;
template <typename T>
inline T read()
{
register T x=0;
register char c;
while((c=gc())<48 || c>'9');
x=c-'0';
while((c=gc())>='0' && c<='9')
x=(x<<3)+(x<<1)+c-'0';
return x;
}
using namespace std;
/**************************GLOBAL DATA***************************************/
int P[20][500000];
struct node
{
int s_ind,next_s_ind;
int ind;
}elem[500000];
PII ud[250000];
int log_n;
VI two,one;
/**************************GLOBAL DATA***************************************/
int lower(VI &one,int p)
{
int low=0,up=SZ(one)-1,ans=-1;
while(low<=up)
{
int mid=((low+up)>>1);
if(one[mid]>p)
{
up=mid-1;
}
else
{
low=mid+1;
ans=mid;
}
}
return ans;
}
int upper(VI &one,int p)
{
int low=0,up=SZ(one)-1,ans=-1;
while(low<=up)
{
int mid=((low+up)>>1);
if(one[mid]<p)
{
low=mid+1;
}
else
{
up=mid-1;
ans=mid;
}
}
return ans;
}
int lcp(int i,int j,int n)
{
int ans=0;
for(int k=log_n;k>=0 && i<n && j<n ; k--)
{
if(P[k][i]==P[k][j])
{
ans+=(1<<k);
i+=(1<<k);
j+=(1<<k);
}
}
return ans;
}
bool cmp(node a,node b)
{
return a.s_ind==b.s_ind?a.next_s_ind<b.next_s_ind:a.s_ind<b.s_ind;
}
int main()
{
std::ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
string s1,s2;
cin>>s1>>s2;
string s=s1+s2;
FOR(i,0,SZ(s))
P[0][i]=s[i]-'a';
int stp=1,cnt=1;
int n=SZ(s);
for(;cnt<n;stp++,cnt*=2)
{
FOR(i,0,n)
{
elem[i].s_ind=P[stp-1][i];
elem[i].next_s_ind=i+cnt<n?P[stp-1][i+cnt]:-1;
elem[i].ind=i;
}
sort(elem,elem+n,cmp);
FOR(i,0,n)
{
P[stp][elem[i].ind]=i> 0 && elem[i].s_ind==elem[i-1].s_ind && elem[i].next_s_ind == elem[i- 1].next_s_ind ? P[stp][elem[i-1].ind] : i;
}
}
FOR(i,0,n)
{
if(elem[i].ind>=SZ(s1)) two.PB(i);
else one.PB(i);
}
log_n=stp-1;
/*FOR(i,0,n)
{
cout<<elem[i].ind<<endl;
} */
int index=-1,mx_len=-1;
FOR(i,0,SZ(s2))
{
ud[i].first=lower(one,two[i]);
ud[i].second=upper(one,two[i]);
}
/*FOR(i,0,SZ(one))
cout<<one[i]<<endl;
CTN(" ");
FOR(i,0,SZ(two))
cout<<two[i]<<endl;
CTN(" ");*/
FOR(i,0,SZ(s2))
{
int tmp_len1=-1,tmp_len2=-1;
if(ud[i].first!=-1)
tmp_len1=lcp(elem[two[i]].ind,elem[one[ud[i].first]].ind,n);
if(ud[i].second!=-1)
tmp_len2=lcp(elem[two[i]].ind,elem[one[ud[i].second]].ind,n);
if(tmp_len1>0 && (tmp_len1>mx_len || (tmp_len1==mx_len && elem[two[i]].ind<=index)))
{
mx_len=tmp_len1;
index=elem[two[i]].ind;
}
if(tmp_len2>0 && (tmp_len2>mx_len || (tmp_len2==mx_len && elem[two[i]].ind<=index)))
{
mx_len=tmp_len2;
index=elem[two[i]].ind;
}
//if(mx_len==7) cout<<"7 "<<two[i]<<" "<<elem[one[ud[i].second]].ind<<endl;
//cout<<i<<" "<<ud[i].first<<" "<<ud[i].second<<endl;
}
/* int _i=1,_j=2;
cout<<log_n<<endl;
REPR(k,log_n,0)
{
if(P[k][_i]==P[k][_j])
{
cout<<_i<<" "<<_j<<" "<<P[k][_i]<<endl;
_i+=(1<<k);
_j+=(1<<k);
}
}*/
if(index!=-1){ cout<<s2.substr(index-SZ(s1),mx_len)<<"\n"; }
index!=-1?cout<<mx_len<<"\n":cout<<"0\n";
}
LyoqKioqKioqKioqKioqKiBBdXRob3I6IHNhbWJpdDE5OTMgKioqKioqKioqKioqKioqKioqLwovKiAJQ2F0ZWdvcnk6IFVwZGF0ZUxhdGVyICAgICAgICAgICovCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPHF1ZXV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TsKCXg9Yy0nMCc7Cgl3aGlsZSgoYz1nYygpKT49JzAnICYmIGM8PSc5JykKCQl4PSh4PDwzKSsoeDw8MSkrYy0nMCc7CglyZXR1cm4geDsKfQp1c2luZyBuYW1lc3BhY2Ugc3RkOwovKioqKioqKioqKioqKioqKioqKioqKioqKipHTE9CQUwgREFUQSoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKi8KaW50IFBbMjBdWzUwMDAwMF07CnN0cnVjdCBub2RlCnsKCWludCBzX2luZCxuZXh0X3NfaW5kOwoJaW50IGluZDsKfWVsZW1bNTAwMDAwXTsKUElJIHVkWzI1MDAwMF07CmludCBsb2dfbjsKVkkgdHdvLG9uZTsKLyoqKioqKioqKioqKioqKioqKioqKioqKioqR0xPQkFMIERBVEEqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiovCmludCBsb3dlcihWSSAmb25lLGludCBwKQp7CglpbnQgbG93PTAsdXA9U1oob25lKS0xLGFucz0tMTsKCXdoaWxlKGxvdzw9dXApCgl7CgkJaW50IG1pZD0oKGxvdyt1cCk+PjEpOwoJCWlmKG9uZVttaWRdPnApCgkJewoJCQl1cD1taWQtMTsKCQl9CgkJZWxzZQoJCXsKCQkJCWxvdz1taWQrMTsKCQkJCWFucz1taWQ7CgkJfQoJfQoJcmV0dXJuIGFuczsKCn0KaW50IHVwcGVyKFZJICZvbmUsaW50IHApCnsKCWludCBsb3c9MCx1cD1TWihvbmUpLTEsYW5zPS0xOwoJd2hpbGUobG93PD11cCkKCXsKCQlpbnQgbWlkPSgobG93K3VwKT4+MSk7CgkJaWYob25lW21pZF08cCkKCQl7CgkJCWxvdz1taWQrMTsKCQl9CgkJZWxzZQoJCXsKCQkJCXVwPW1pZC0xOwoJCQkJYW5zPW1pZDsKCQl9Cgl9CglyZXR1cm4gYW5zOwoKfQoKaW50IGxjcChpbnQgaSxpbnQgaixpbnQgbikKewoJaW50IGFucz0wOwoKCWZvcihpbnQgaz1sb2dfbjt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