#include
#include
#include
using namespace std;
int main(){
string pre,post;
cin>>pre>>post;
int n=pre.length();
int m=post.length();
int dp[m+1][n+1];
for(int i=0;i<=m;i++){
dp[i][0]=0;
}
for(int i=0;i<=n;i++){
dp[0][i]=0;
}
for(int i=1;i<=m;i++){
for(int j=1;j<=n;j++){
if(pre[i-1]==post[j-1]){
dp[i][j]=dp[i-1][j-1]+1;
}
else{
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
}
}
}
int index = dp[m][n];
// Create a character array to store the lcs string
char lcs[index+1];
lcs[index] = ‘\0’; // Set the terminating character
int i = m, j = n;
while (i > 0 && j > 0)
{
if (pre[i-1] == post[j-1])
{
lcs[index-1] = pre[i-1];
i--; j--; index--;
}
else if (dp[i-1][j] > dp[i][j-1])
i--;
else
j--;
}
cout << lcs;
}