/**
 *   created: 23 May 2019  15:36:43
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
vector< vi > mem,mem2;
string s1,s2;

int sol(int n,int m){
	if(n<0 || m<0)
		return 0;
	if(mem2[n][m]!=-1)
		return mem2[n][m];
	if(s1[n]==s2[m])
		return mem2[n][m] = 1+sol(n-1,m-1);
	return mem2[n][m] = max(sol(n-1,m), sol(n,m-1));
}
int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		cin>>s1>>s2;
		mem.resize(s1.size(), vi(s2.size(), 0));
		int flag=0;
		rep(i,0,s2.size()){
			if(s1[0]==s2[i]){
				flag=1;
			}
			mem[0][i] = flag;
		}
		flag=0;
		rep(i,0,s1.size()){
			if(s2[0]==s1[i]){
				flag=1;
			}
			mem[i][0] = flag;
		}
		rep(i,1,s1.size()){
			rep(j,1,s2.size()){
				if(s1[i]==s2[j]){
					mem[i][j] = max(1+mem[i-1][j-1], max(mem[i-1][j],mem[i][j-1]));
				}
				else{
					mem[i][j] = max(mem[i-1][j],mem[i][j-1]);
				}
			}
		}
		int n,m;
		int maxi =0;
		rep(i,0,s2.size()){
			if(maxi<mem[s1.size()-1][i]){
				maxi=mem[s1.size()-1][i];
				n = s1.size()-1;
				m = i;
			}
		}
		string res="";
		while(n>=0 && m>=0){
			// trace2(n,m);
			if(s1[n]==s2[m]){
				res += s1[n];
				n--;
				m--;
			}
			else{
				if(n>0 && m>0 && mem[n-1][m]>mem[n][m-1]){
					n = n-1;
				}
				else if(n>0 && m>0 && mem[n-1][m]<=mem[n][m-1]){
					m = m-1;
				}
				else if(n>0){
					n--;
				}
				else
					m--;
			}
		}
		int i=0,j=res.size()-1;
		while(i<j){
			swap(res[i],res[j]);
			i++;
			j--;
		}
		cout<<res<<endl;
		// mem2.resize(s1.size(), vi(s2.size(),-1));
		// maxi=0;
		// rep(i,0,s1.size())
		// 	rep(j,0,s2.size())
		// 		maxi = max(maxi, mem[i][j]);
		// cout<<maxi<<endl;
		// // cout<<sol(s1.size()-1, s2.size()-1)<<endl;
		// rep(j,0,s2.size()){
		// 	rep(i,0,s1.size())
		// 		cout<<mem[i][j]<<"  ";
		// 	cout<<endl;
		// }
		// rep(j,0,s2.size()){
		// 	rep(i,0,s1.size())
		// 		cout<<mem2[i][j]<<"  ";
		// 	cout<<endl;
		// }
	}
	return 0;
}


Measured memory_bytes: 35584