#include<bits/stdc++.h>

using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(long long int i=0;i<n;i++)
#define rep(i,k,n) for (lli i = k; i <= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)

typedef pair <lli,lli> pll;
 
// CODE BEGINS :

void solve()
{
    string s1, s2; cin>>s1>>s2;
    lli n=s1.le, m=s2.le;
    
    lli dp[n+1][m+1];
    char bt[n+1][m+1];
    
    forz(i,n+1)
    {
        forz(j,m+1)
        {
            dp[i][j]=-1;
            bt[i][j]='?';
        }
    }
    
    forz(i,n+1) dp[i][0]=0;
    forz(j,m+1) dp[0][j]=0;
    
    for(lli i=1; i<=n; i++)
    {
        for(lli j=1; j<=m; j++)
        {
            if(s1[i-1] == s2[j-1])
            {
                dp[i][j] = 1 + dp[i-1][j-1];
                bt[i][j] = 'd';
            }
            
            else
            {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            
                if(dp[i-1][j]>=dp[i][j-1])
                bt[i][j] = 'h';
                
                else
                bt[i][j] = 'v';
            }
        }
    }
    
    // forz(i, n+1)
    // {
    //     forz(j, m+1)
    //     {
    //         cout<<dp[i][j]<<" "<<bt[i][j]<<"### ";
    //     }
        
    //     cout<<endl;
    // }
    
    string str;
    
    //  Backtrack
    lli i1 = n, i2 = m;
    while(1)
    {
        // deb(i1, i2, bt[i1][i2]);
        if(bt[i1][i2] == 'd')  
        {
            str.pb(s2[i2-1]);
            i1--;
            i2--;
        }
        
        else if(bt[i1][i2] == 'h') i1--;
        
        else if(bt[i1][i2] == 'v') i2--;
        
        else break;
        
        if(i1==0 || i2==0) break;
    }
    
    reverse(str.be, str.en);
    cout<<str<<endl;
}

int main()
{
    kira; 

    lli t=1; // cin>>t;

    while(t--)
    {
        solve();
    }
    
    return 0;
}




















Measured memory_bytes: 79488