#include<bits/stdc++.h>
#define f first
#define se second
#define pb push_back
#define pf push_front
#define eb emplace_back
#define emp emplace
#define ins insert
#define sz(s) (int)s.size()
#define rep(i,a,b) for( int i=a;i<b;i++)
#define repr(i,a,b) for( int i=a;i>=b;i--)
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(n,m) memset(n,m,sizeof(n))
#define ii pair<int,int>
#define iii tuple<int, int, int>
#define si set<int>
#define vi vector<int>
#define vii vector<ii>
#define mi map<int,int>
#define lb lower_bound
#define ub upper_bound
#define present(s,x) (s.find(x) != s.end())
#define ford(container, it) for(auto it:container)
#define fors(container, it, a, b) for(auto it = a; it != b; it++)
#define Anurag_Gupta ios_base::sync_with_stdio(0);
#define IIIT_ALLD cin.tie(0);cout.tie(0);
#define mod 987654319
#define EPSILON 1e-9
#define PI acos(-1)
#define inf 1e17
#define int long long
#define debug(a) cerr<<#a<<": ";for(auto i:a)cerr<<i<<" ";cerr<<'\n';
#define trace(a) cerr<<#a<<": "<<a<<"\n"
#define gcd(a,b) __gcd(a,b)
using namespace std;
int add(int a, int b, int c){int res=a+b;return(res>=c?res-c:res);}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mul(int a, int b, int c){int res=(int)a*b;return(res>=c?res%c:res);}
template<typename T>T power(T e, T n){T x=1,p=e;while(n){if(n&1)x=x*p;p=p*p;n>>=1;}return x;}
template<typename T>T mdpower(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
/*------------------------------------------------------------------------------------------------------------------*/

int32_t main()
{
    Anurag_Gupta
    IIIT_ALLD
 
   
  
   string s,t;
    cin>>s>>t;
    
    int pp = s.size();
    int tt = t.size();

    vector<vector<pair<int,ii>>>dp(pp+1,vector<pair<int,ii>>(tt+1));
    dp[0][0] = {0,{0,0}};
    for(int i=1;i<=pp;i++)
    {
        for(int j=1;j<=tt;j++)
        {
             dp[i][j] = {0,{0,0}};
            if(s[i-1]==t[j-1]){
            dp[i][j] = {1+dp[i-1][j-1].f,{i-1,j-1}};
            }
            else
            {
                int aa = dp[i][j-1].f;
                int bb = dp[i-1][j].f;

                dp[i][j].f = max(aa,bb);
                if(dp[i][j].f==aa){
                    dp[i][j].se = {i,j-1};
                }
                else dp[i][j].se = {i-1,j};
            }
            
        }
    }
    
    int i = pp;
    int j = tt;
    string ans = "";
    while(i>0 and j>0)
    {
        if(s[i-1]==t[j-1])
            ans+=s[i-1];

       int  i1 = dp[i][j].se.f;
        int j1 = dp[i][j].se.se;
        i = i1;
        j = j1;

    }
    reverse(all(ans));
    cout<<ans<<"\n";
  







 
#ifndef LOCAL_DEFINE
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
}


Measured memory_bytes: 214368