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 string[][](3005, 3005);

	foreach (i, cs; s)
	{
		foreach (j, ct; t)
		{
			auto s1 = dp[i+1][j].length > dp[i][j+1].length ? dp[i+1][j] : dp[i][j+1];
			if (cs == ct)
			{
				dp[i+1][j+1] = dp[i][j].length + 1 > s1.length ? dp[i][j] ~ cs : s1;
			}
			else
			{
				dp[i+1][j+1] = s1;
			}
			//stderr.writeln(i, ":", j, " ", dp[i+1][j+1]);
		}
	}

	writeln(dp[s.length][t.length]);
	stdout.flush();
}