import std.string;
import std.stdio;
import std.algorithm;

void main() {
	auto s = readln.chomp.dup;
	auto t = readln.chomp.dup;

	if (s.length == 0 || t.length == 0) {
		writeln();
		return;
	}

	auto dp = new int[][t.length + 1];
	foreach (ref e;dp) {
		e = new int[s.length + 1];
	}

	foreach (size_t i, te;t) {
		foreach (size_t j, se;s) {
			if (te == se) {
				dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1]);
			} else  {
				dp[i + 1][j + 1] = max(dp[i][j], dp[i + 1][j], dp[i][j + 1]);
			}
		}
	}

	auto result = new char[dp[t.length][s.length]];

	auto y = t.length, x = s.length;

	for (;;) {
		auto num = dp[y][x];

		while (y >= 1 && dp[y - 1][x] == num) {
			--y;
		}

		while (x >= 1 && dp[y][x - 1] == num) {
			--x;
		}

		if (y == 0 || x == 0) break;

		result[num - 1] = s[x - 1];

		--x;
		--y;
	}

	writeln(result);
}
