#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rev(i,b,a) for (ll i = b - 1; i >= a; i--)
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
#define cont continue
//#define minn 999999999
//#define maxx 0
ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
ll modulo(ll a, ll b)
{
    ll r = a % b;
    return r < 0 ? r + b : r;
}
//ncr
ull ncr(ull n, ull r)
{
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    ull ans = 1;
    ull i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
class abc
{
    public:
    ll val;
    ll ind;
};
bool fun1(abc x,abc y)
{
    return x.val>y.val;
}
///////////////////////////////////////////////////////
class abcd
{
    public:
    ll day;
    ll vas;
};
bool fun1(abcd x,abcd y)
{
    return x.vas<y.vas;
}
///////////////////////////////////////////
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}
ll fact[100000+2];
ll ncrfast(ll n, ll r, ll p)
{
   if (r==0)
      return 1;
    return (fact[n]* modInverse(fact[r], p) % p *
            modInverse(fact[n-r], p) % p) % p;
}
///////////////////////////////////////////////////////
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //ll tc;
    //cin>>tc;
    //while(tc--)
    {
        //ll n,m;
      //  cin>>n>>m;
        string s,t;
        cin>>s>>t;
        ll n=s.size();
        ll m=t.size();

        ll dp[n+1][m+1];
        string ans="";
        ll x=0;
        rep(i,0,n+1 )
        {
            rep(j,0,m+1 )
            {
                if( i==0 || j==0 )
                {
                    dp[i][j]=0;
                }
                else
                {
                    if( s[i-1] == t[ j-1] )
                    {
                        dp[i][j] = 1 + dp[i-1][j-1];
                        //ans.pb( t[j-1] );
                        //cout<<x++<<" ";
                    }
                    else
                    {
                        dp[i][j] = max( dp[i-1][j] , dp[i][j-1] );
                    }
                }
            }
        }
        //cout<<dp[n][m]<<" "<<ans<<"\n"<<x;
        ll i=n,j=m;
        while(i > 0 and j > 0){
        if(dp[i][j] == dp[i - 1][j]) i--;
        else if(dp[i][j] == dp[i][j -1]) j--;
        else{
            ans += s[i - 1];// + ans;
            i--, j--;
        }
        
    }
        reverse( ans.begin() , ans.end() );
        cout<<ans;
    }
}

Measured memory_bytes: 70656