#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fast std::ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define clr0(a) memset((a), 0, sizeof(a))
#define clr1(a) memset((a), -1, sizeof(a))
#define srtin1 cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
#define strin2 getline(cin, text);
#define ll long long
#define test cout<<"archit\n"
#define debug(x) cout<<x<<" "
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define pb push_back
#define pi pair<int,int>
#define fi first
#define si second
#define mod (ll)1000000007
#define mxn 1000005
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
//using namespace boost::multiprecision;
using namespace __gnu_pbds;
int dp[1005][1005];
int solve(string a, string b, int n, int m, int i, int j)
{
    if(i==n || j==m){
        return 0;
    }
    if(dp[i][j] > -1){
        return dp[i][j];
    }
    int ans=0;
    if(a[i] == b[j]){
        ans = 1+solve(a, b, n, m, i+1, j+1);
    }
    else{
        ans = solve(a, b, n, m, i+1, j);
        ans = max(ans, solve(a, b, n, m, i, j+1));
    }
    return dp[i][j] = ans;
}
int main()
{
    string a,b;
    cin>>a>>b;
    int n=a.length();
    int m=b.length();
    memset(dp, 0, sizeof(dp));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i-1] == b[j-1]){
                dp[i][j] = 1+dp[i-1][j-1];
            }
            else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    string ans="";
    int i=n,j=m;
    while(i>=0 && j>=0){
        if(dp[i][j] == 1+dp[i-1][j-1]){
            ans+=a[i-1];
            i-=1;
            j-=1;
        }
        else if(dp[i][j] == dp[i-1][j]){
            --i;
        }
        else{
            --j;
        }
    }
    std::reverse(ans.begin(), ans.end());
    cout<<ans;
    return 0;
}
