#include <bits/stdc++.h>
using namespace std;

string s = "", t = "", ans = "";
int sz1 = 0, sz2 = 0;

int mem[3010][3010];
int DP(long long i, long long j){

	if(i == sz1 || j == sz2)	return 0;
	if(mem[i][j] != -1)	return mem[i][j];

	long long opt1 = (s[i] == t[j]) ? 1+ DP(i+1, j+1) : 0;
	long long opt2 = DP(i, j+1);
	long long opt3 = DP(i+1, j);

	int mx = 0;
	mx = (mx > opt1) ? mx : opt1;
	mx = (mx > opt2) ? mx : opt2;
	mx = (mx > opt3) ? mx : opt3;

	return mem[i][j] = mx;
}

void trace(long long i, long long j){

	if(i == sz1 || j == sz2)	return;

	long long opt1 = (s[i] == t[j]) ? 1+ mem[i+1][j+1] : 0;
	long long opt2 = mem[i][j+1];
	long long opt3 = mem[i+1][j];

	int mx = 0;
	mx = (mx > opt1) ? mx : opt1;
	mx = (mx > opt2) ? mx : opt2;
	mx = (mx > opt3) ? mx : opt3;

	if(mx == opt1)	{
		if(s[i] == t[j]){
					ans += s[i]; trace(i+1, j+1);
		}
	}
	else if(mx == opt2) {trace(i, j+1);}
	else if(mx == opt3)	{trace(i+1, j);}

	return;
}


int main(){

	freopen("input", "r", stdin);
	freopen("output", "w", stdout);
	memset(mem, -1, sizeof mem);

	cin >> s >> t;
	sz1 = s.length();
	sz2 = t.length();

	DP(0,0);
	trace(0,0);

	cout << ans << endl;
	return 0;
}