rt
#include <bits/stdc++.h>
using namespace std;
const int N=50;
int dp[N][N];
string A,B;
int main()
{
cin>>A>>B;
int n=A.size()-1;
int m=B.size()-1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(A[i]!=B[j])
dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
else
dp[i][j]=dp[i-1][j-1]+1;
}
}
cout<<dp[n][m]<<endl;
string lcs;
int i=n,j=m;
while (i>0&&j>0)
{
if(A[i]==B[j])
{
lcs=A[i]+lcs;
i--;
j--;
}
else if(dp[i-1][j]>dp[i][j-1]) i--;
else j--;
}
cout<<lcs;
return 0;
}