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

wchar[][3000][3000] MEMO;

void main()
{
    auto s = readln.chomp.to!(wchar[]);
    auto t = readln.chomp.to!(wchar[]);

    wchar[] solve(int i, int j) {
        if (i == s.length || j == t.length) return [];
        if (MEMO[i][j] != []) return MEMO[i][j];

        wchar[] r1;
        if (s[i] == t[j]) {
            r1 = [s[i]] ~ solve(i+1, j+1);
        }
        auto r2 = solve(i+1, j);
        auto r3 = solve(i, j+1);

        return MEMO[i][j] =
            r1.length > r2.length && r1.length > r3.length ? r1
            : r2.length > r1.length && r2.length > r3.length ? r2
            : r3;
    }

    writeln(solve(0, 0));
}