// Problem : F - LCS
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define infl 1e18+5
#define mninfl -1e18-5
#define Mod 1000000007
#define newmod  998244353
int ah=911382323;
int bh=972663749;
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const long double pi=acos(-1);
//looping
#define int long long
#define For(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' ';  cout<<endl
#define pv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";  cout<<endl
#define pm(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}cout<<endl
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}
template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}
template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}
template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}
#define deb(x) cerr << #x << " = " << x << endl;
#define deb2(x,y)  cerr << #x << " = " << x <<"   "<< #y << " = " << y << endl;
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define all(v) (v).begin(),(v).end()
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,1,-1,1,-1};
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef vector < pair <int, int> > vpii;
typedef pair<int,int>  pii;
/*/----------------------------Code begins----------------------------------/*/
int dp[3001][3001];
int32_t main(){
fio;
string a,b;
cin>>a>>b;
for(int i=0;i<a.size();i++){
	for(int j=0;j<b.size();j++){
		if(a[i]==b[j])
		dp[i+1][j+1]=1+dp[i][j];
		else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
	}
}

//printing lcs
string s;
int i=a.size(),j=b.size();
while(i>0&&j>0){
	 if(dp[i][j]==dp[i-1][j])
	{
		i--;
	}
	else if(dp[i][j]==dp[i][j-1])
	j--;
	else {
		s+=a[i-1];
		i--;j--;
	}
}
reverse(s.begin(),s.end());
cl(s);
}
//n m thus total unique function call are n*m then why are we calling 2^(m+n);




























Measured memory_bytes: 70656