#include<stdio.h>
#include<string.h>
const int max=120;//字符串大小
char x[max],y[max];
int b[max][max];
int c[max][max];
int m,n;
void printstring(int i,int j)//打印最长字串
{
if(i==0||j==0) return;
if(b[i][j]==1)
{
printstring(i-1,j-1);
printf("%c ",x[i-1]);
}
else if(b[i][j]==2)
printstring(i-1,j);
else
printstring(i,j-1);
}
void maxstring()//动态规划求最长字串长度
{
int i,j;
memset(c,0,sizeof(c));
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(x[i-1]==y[j-1])
{
c[i][j]=c[i-1][j-1]+1;
b[i][j]=1;
}
else if(c[i-1][j]>c[i][j-1])
{
c[i][j]=c[i-1][j];
b[i][j]=2;
}
else
{
c[i][j]=c[i][j-1];
b[i][j]=3;
}
printf("%d\n",c[m][n]);
}
int main()
{
while(scanf("%s%s",x,y))
{
m=strlen(x);
n=strlen(y);
maxstring();
printstring(m,n);
printf("\n\n");
}
return 0;
}