local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
local function array(dimension, default_val) local n=dimension local m={default_val and {__index=function()return default_val end}}for i=2,n do m[i]={__index=function(p, k)local c=setmetatable({},m[i-1])rawset(p,k,c)return c end}end return setmetatable({},m[n])end
local unpack = table.unpack or unpack
local insert = table.insert or insert
----
local S = setmetatable(read.l():totable(), {__index=function()return '!' end})
local T = setmetatable(read.l():totable(), {__index=function()return '@' end})
local tbl1 = array(2, 0)
local tbl2 = array(2, nil)

local function cons(val, next)
    return {val = val, next = next}
end

for i=1,#S do
    local tbl1_i = tbl1[i]
    local tbl1_i_1 = tbl1[i-1]
    local tbl2_i = tbl2[i]
    local tbl2_i_1 = tbl2[i-1]
    for j=1,#T do
        local ns = S[i]
        local nt = T[j]
        if ns == nt then
            local a = tbl1_i_1[j-1]
            local ra = cons(ns, tbl2_i_1[j-1])
            tbl1_i[j] = a+1
            tbl2_i[j] = ra
        else
            local a = tbl1_i_1[j]
            local b = tbl1_i[j-1]
            if a > b then
                tbl1_i[j] = a
                tbl2_i[j] = tbl2_i_1[j]
            else
                tbl1_i[j] = b
                tbl2_i[j] = tbl2_i_1[j-1]
            end
        end
    end
end
if false then
    print(tbl1[#S][#T])
    return
end
local ans_revt = {}
local it = tbl2[#S][#T]
while it do
    --print(it, it.val, it.next)
    insert(ans_revt, it.val)
    it = it.next
end
local ans_revs = table.concat(ans_revt, "")
print(ans_revs:reverse())