import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container;
import std.numeric, std.math;

string my_readln() { return chomp(readln()); }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	//auto tokens = my_readln().split();
	//auto N = tokens[0].to!uint;
	//auto K = tokens[1].to!uint;
	auto s = my_readln;
	auto t = my_readln;

	auto dp = new uint[][](3005, 3005);

	foreach (i, cs; s)
	{
		foreach (j, ct; t)
		{
			dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
			if (cs == ct)
			{
				dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
			}
			//stderr.writeln(i, ":", j, " ", dp[i+1][j+1]);
		}
	}

	string ans;
	long i = s.length - 1, j = t.length - 1;
	while (i >= 0 && j >= 0)
	{
		if (s[i] == t[j])
		{
			ans = s[i] ~ ans;
			--i; --j;
		}
		else if (dp[i+1][j] > dp[i][j+1]) --j;
		else							  --i;
	}
	
	writeln(ans);
	stdout.flush();
}