s = gets.chomp!
t = gets.chomp!

n = s.size
m = t.size

dp = Array.new(n + 1).map{Array.new(m + 1)}
dp[0].fill(0)

for i in 0 .. n - 1

    dp[i + 1][0] = 0

    for j in 0 .. m - 1
        if s[i] == t[j]
            dp[i + 1][j + 1] = dp[i][j] + 1
        elsif dp[i + 1][j] > dp[i][j + 1]
            dp[i + 1][j + 1] = dp[i + 1][j]
        else
            dp[i + 1][j + 1] = dp[i][j + 1]
        end
    end
end

i = n
j = m
ans = ""

while dp[i][j] != 0
    if dp[i - 1][j - 1] == dp[i][j]
        i -= 1
        j -= 1
    elsif dp[i - 1][j] == dp[i][j]
        i -= 1
    elsif dp[i][j - 1] == dp[i][j]
        j -= 1
    else
        i -= 1
        j -= 1
        ans.concat(s[i])
    end
end

puts ans.reverse