import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
public class DemoLessWord {
public static void main(String[] args) {
largeZiXuLie();
}
public static void LessWord()
{
Scanner sc=new Scanner(System.in);
String s;
int min=0;
String sresult="";
System.out.println("请输入一个字符串");
s=sc.nextLine();
char [] st = s.toCharArray();
int [] arr=new int[26];
for(int i=0;i<st.length;i++)
{
arr[(int)st[i]-'a']++;
}
for(int i=0;i<arr.length;i++)
{
if(arr[i]!=0)
{
if(min==0||arr[i]<min)
{
min=arr[i];
}
}
}
for(int i=0;i<st.length;i++)
{
if(arr[(int)st[i]-'a']!=min)
{
sresult=sresult+st[i];
}
}
System.out.println(sresult);
s=sc.nextLine();
}
public static void findAugNumber()
{
int num=0;
Scanner sc=new Scanner(System.in);
num=sc.nextInt();
int [] number=new int[num];
int index5=0,index2=0,index3=0;
number[0]=1;
for(int i=0;i<num;i++)
{
int temp=Math.min(number[index2]*2,number[index5]*5);
temp= Math.min(number[index3]*3,temp);
number[i+1]=temp;
System.out.println(i+" "+temp);
if(temp==number[index2]*2)
{
index2++;
}
if(temp==number[index3]*3)
{
index3++;
}
if(temp==number[index5]*5)
{
index5++;
}
}
}
public static void largeZiXuLie()
{
String s1="",s2="";
Scanner sc=new Scanner(System.in);
s1=sc.nextLine();
s2=sc.nextLine();
int [][] number=new int[s1.length()][s2.length()];
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<s2.length();j++)
{
if(s1.charAt(i)==s2.charAt(j))
{
if((i-1)>=0&&(j-1)>=0)
{
number[i][j]=1+number[i-1][j-1];
}
else
{
number[i][j]++;
}
}
}
}
int max=0;
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<s2.length();j++)
{
if(max<number[i][j])
{
max=number[i][j];
}
}
}
System.out.println(max);
ArrayList<Integer> ari=new ArrayList<Integer>();
ArrayList<Integer> arj=new ArrayList<Integer>();
if(max>1)
{
for(int i=0;i<s1.length();i++)
{
for(int j=0;j<s2.length();j++)
{
if(max==number[i][j])
{
ari.add(i);
arj.add(j);
}
}
}
}
String s3="";
int x=0,y=0;
for(int i=0;i<ari.size();i++)
{
x=ari.get(i);
y=arj.get(i);
while(x>=0&&y>=0&&number[x][y]!=0)
{
s3+=s1.charAt(x);
x--;
y--;
}
s3+=" ";
}
for(int i=s3.length()-1;i>=0;i--)
{
System.out.print(s3.charAt(i));
}
}
}