/**
 *   created: 20 August 2019  11:36:13
**/
#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 rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#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

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		string s1,s2;
		cin>>s1>>s2;
		int n = s1.size(), m = s2.size();
		vector< vi > mem(n,vi(m,0));
		rep(i,0,m){
			if(s1[0]==s2[i])
				mem[0][i] = 1;
			else if(i>0)
				mem[0][i] = mem[0][i-1];
		}
		rep(i,0,n){
			if(s1[i]==s2[0])
				mem[i][0] = 1;
			else if(i>0)
				mem[i][0] = mem[i-1][0];
		}
		rep(i,1,n){
			rep(j,1,m){
				if(s1[i]==s2[j])
					mem[i][j] = max(mem[i-1][j-1]+1, max(mem[i-1][j], mem[i][j-1]));
				else
					mem[i][j] = max(mem[i-1][j-1], max(mem[i-1][j], mem[i][j-1]));
			}
		}
		int maxi  = 0;
		int ind1=n-1, ind2;
		rep(i,0,m){
			if(maxi<mem[n-1][i]){
				maxi = max(mem[n-1][i],maxi);
				ind2 = i;
			}
		}
		// rep(i,0,n){
		// 	rep(j,0,m)
		// 		cout<<mem[i][j]<<" ";
		// 	cout<<endl;
		// }
		string res = "";
		while(ind1>0 && ind2>0){
			int temp = max(mem[ind1-1][ind2], max(mem[ind1][ind2-1], mem[ind1-1][ind2-1]));
			if(mem[ind1][ind2]>temp){
				res += s1[ind1];
				ind1--,ind2--;
			}
			else{
				if(temp==mem[ind1-1][ind2]){
					ind1--;
				}
				else if(temp==mem[ind1][ind2-1])
					ind2--;
				else
					ind1--, ind2--;
			}
		}
		if(mem[ind1][ind2]==1){
			if(ind1==0)
				res += s1[ind1];
			else
				res+=s2[ind2];
		}
		reverse(all(res));
		cout<<res;
	}
	return 0;
}


Measured memory_bytes: 35584