#include<bits/stdc++.h>
using namespace std;
string s,t;
int p[500005]; //next数组
void getNext(){
int len=0,i=1;
int len1=s.length();
while(i<len1){
if(s[len]==s[i]){
p[i++]=++len;
}
else{
if(len)len=p[len-1];
else p[i++]=len;
}
}
}
int main(){
ios::sync_with_stdio(false);
while(cin>>s>>t){
int len1=s.length();
int len2=t.length();
memset(p,0,sizeof(p));
s+=t; //合并两个字符串
getNext();
int len=s.length();
int min_=min(len1,len2);
if(p[len-1]>min_)p[len-1]=min_; //长度大于输入的字符串
if(p[len-1]==0){ //不存在
cout<<0<<endl;
}
else{
cout<<s.substr(0,p[len-1])<<" "<<p[len-1]<<endl;
}
}
}
09-09
759
09-08
1040