#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
using namespace std;
int gcd(int a, int b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
#define MOD 1000000007
#define INF 99999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}
ll modi(ll a, ll m)
{
	return power(a, m - 2, m);

}
ll ncr(ll n, ll r,ll m)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans *= modi(n - i + 1, m);
		ans %= m;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}


bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}
ll arr[1000];
void dfs(ll a, vector<ll>adj[100099], bool visited[100001], ll& count, vector<ll> in, ll n, ll ans[])
{
	visited[a] = true;
	if (a <= n)
	{
		count++;
		arr[count - 1] = a;
	}
	for (auto u : adj[a])
	{
		if (!visited[u])
		{
			visited[u] = true;
			dfs(u, adj, visited, count, in, n, ans);
		}
	}
	for (ll i = 0; i < count; i++) {
		ans[arr[i]] = count;
	}

}

ll calhash(string& s) {
	ll i, hash = 0, p = 1, pow = 3;
	for (i = 0; s[i] != '\0'; i++) {
		hash = (hash + p * (s[i] - 'a' + 1)) % MOD;
		p *= pow;
	}
	return hash;
}
ll digit(ll n)
{
	ll count = 0;
	while (n != 0) {
		n = n / 10;
		++count;
	}
	return count;
}
ll* kmp(string& s) {
	ll j, i, prefix[1000];
	prefix[0] = 0;
	for (i = 1; s[i] != '\0'; i++) {

			j = prefix[i - 1];
			while (j > 0 && s[j] != s[i]) {
				j = prefix[j - 1];
			}
			if (s[i] == s[j]) {
				prefix[i] = j + 1;
			}
	}
	return prefix;
}

void bfs(ll start, ll arr[], vector<ll> adj[], ll c) {
	queue<pair<ll,ll>> q;
	pair<ll, ll> temp;
	temp = { start, c };
	q.push(temp);
	while (!q.empty()) {
		temp = q.front();
		q.pop();
		for (auto u : adj[temp.first]) {
			    arr[u] = arr[u] - temp.second;
				q.push({ u , -temp.second});
			}
			
		
	}
}
int main() {
	fast
	ll n, m, i, j;
	string s, t;
	cin >> s >> t;
	n = s.length();
	m = t.length();
	ll c[4000][4000];
	for (i = 0; i <= n; i++) {
		c[i][0] = 0;
	}
	for (i = 0; i <= m; i++) {
		c[0][i] = 0;
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= m; j++) {
			if (s[i-1] == t[j-1]) {
				c[i][j] = abs(c[i - 1][j - 1]) + 1;
				c[i][j] *= -1;
			}
			else
			{
				c[i][j] = max(abs(c[i - 1][j]), abs(c[i][j - 1]));
			}
		}
	}
	
	stack<char> st;
	while (true) {
		//cout << n <<" "<< m << endl;
		if (c[n][m] < 0) {
			st.push(s[n-1]);
			n--;
			m--;	
		}
		else if(c[n][m]==abs(c[n-1][m])){
			n--;
		}
		else if (c[n][m] == abs(c[n][m - 1])) {
			m--;
		}
		
		if (n == 0 || m <= 0) {
			break;
		}
		
	}
	while (!st.empty()) {
		cout << st.top();
		st.pop();
	}
	return 0;
}

Measured memory_bytes: 95616