#include
#include
using namespace std;
string lcs(string s1,string s2){
pair<int,int> dp[1003][1003];
string s="";
int n=s1.length();
int m=s2.length();
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i==0){
dp[0][j].first=0; dp[0][j].second=1;
}
if(j==0){
dp[i][0].first=0; dp[i][0].second=2;
}
if(s1[i-1]==s2[j-1]){
dp[i][j].first=dp[i-1][j-1].first+1;
dp[i][j].second=3;
}
else{
dp[i][j].first=max(dp[i-1][j].first,dp[i][j-1].first);
dp[i][j].second=(dp[i][j].first==dp[i-1][j].first)?2:1;
}
}
}
int r=n,t=m;
while(r>0 && t>0){
if(dp[r][t].second==1)
t--;
if(dp[r][t].second==2)
r--;
if(dp[r][t].second==3){
s=s1[r-1]+s;
r--;t--;
}
}
return s;
}
int main() {
string s1,s2;
cin>>s1>>s2;
string s=lcs(s1,s2);
s=="" ? cout<<" " : cout<<s;
return 0;
}
