import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Goods = Tuple!(long, "w", long, "v");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto s = sread();
    auto t = sread();
    long m = s.length, n = t.length;
    auto lcs = new long[][](m + 1, n + 1);
    foreach (i; iota(m))
    {
        foreach (j; iota(n))
        {
            if (s[i] == t[j])
                lcs[i + 1][j + 1] = lcs[i][j] + 1;
            else
                lcs[i + 1][j + 1] = max(lcs[i][j + 1], lcs[i + 1][j]);
        }
    }
    lcs.traceback(t, m, n).writeln();
}

auto traceback(T)(T lcs, string s, long m, long n)
{
    auto str = new char[](0);
    while (m > 0 && n > 0)
    {
        if(lcs[m][n] == lcs[m][n - 1])
            n--;
        else if(lcs[m][n] == lcs[m - 1][n])
            m--;
        else
        {
            m--, n--;
            str ~= s[n];
        }
    }
    str.reverse();
    return str;
}
