#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
double doINF = 1.0/0.0 ;
ostream_iterator <int> outp(cout," ");
inline ll modadd(ll n,ll m,ll mod){
    ll sum = ((n+m)%mod+mod)%mod;
    return sum;
} 
inline ll modsub(ll n,ll m, ll mod){
    ll diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}
inline ll modpro(ll n,ll m,ll mod){
    ll pro = ((n*m)%mod+mod)%mod;
    return pro;
}
inline ll pow(int x,int y){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}
inline ll powmod(ll x,ll y,ll mod){
    ll res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}
//ll min(ll a, ll b){
//    if(a>b){
//        return b;
//    }
//    return a;
//}
// 
//ll max(ll a, ll b){
//    if(a>b){
//        return a;
//    }
//    return b;
//}
bool pairdec(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 		if(a.fi!=b.fi)
       	return (a.fi> b.fi);
		else return a.se>b.se;  
} 
ll power(ll x, ll y, ll mod) 
{ 
    ll res = 1; 
    x = x%mod; 
    while (y > 0) { 
        if (y & 1) 
            res = (res * x) % mod; 
  
        y = y >> 1;
        x = (x * x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll a, ll mod) 
{ 
    return  powmod(a, mod - 2, mod); 
} 
ll modFact(ll n, ll mod) 
{ 
    if (n >=mod) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) %mod; 
  
    return result; 
} 
//cout<<setprecision(9)<<fixed<<sum<<endl; --- precision for double numbers
//copy(v.beg,v.en,outp);
int main()
{
	string a,b;
	cin>>a>>b;
	int n=a.len;
	int m=b.len;
	int dp[n][m];
	//forl(i,0,n)forl(j,0,m) dp[i][j]=0;
	int myj=m,myi=n;
	forl(j,0,m)
	{
		if(a[0]==b[j])
		{
			myj=j;
			break;
		}
		else dp[0][j]=0;
	}
	forl(j,myj,m) dp[0][j]=1;
	forl(i,0,n)
	{
		if(a[i]==b[0])
		{
			myi=i;
			break;
		}
		else dp[i][0]=0;
	}
	forl(i,myi,n) dp[i][0]=1;
	forl(i,1,n)
	{
		forl(j,1,m)
		{
			if(a[i]==b[j])
			{
				dp[i][j]=max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]));
			}else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
//	cout<<dp[n-1][m-1]<<endl;
	string fnl;
	int i=n-1,j=m-1;
	while(i>=0 &&  j>=0)
	{
		if(i==0)
		{
			if(dp[i][j])fnl.pb(a[0]);
			break;
		}
		
		if(j==0)
		{
			if(dp[i][j])fnl.pb(b[0]);
			break;
		}
		if(a[i]==b[j])
		{
			if(dp[i-1][j-1]==max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]))-1){
				fnl.pb(a[i]);
				i--;
				j--;
			}
			else if(dp[i-1][j]==max(dp[i-1][j-1]+1,max(dp[i-1][j],dp[i][j-1]))){
				i--;
			}
			else{
				j--;
			}
		}else{
			if(dp[i-1][j]==max(dp[i-1][j],dp[i][j-1])){
				i--;
			}
			else{
				j--;
			}
		}
	}
	reverse(fnl.beg,fnl.en);
	cout<<fnl<<endl;
	
	
}


Measured memory_bytes: 35456