s = gets.chomp
n = s.size
t = gets.chomp
m = t.size

d = Array.new(n+1) {Array.new(m+1, 0)}
n.times do |i|
    m.times do |j|
        x = d[i][j] + (s[i] == t[j] ? 1 : 0)
        d[i+1][j+1] = [x, d[i][j+1], d[i+1][j]].max
    end
end

ans = ""
i = n
j = m
until i == 0 || j == 0
    if d[i-1][j] == d[i][j]
        i -= 1
    elsif d[i][j-1] == d[i][j]
        j -= 1
    else
        ans += s[i-1]
        i -= 1
        j -= 1
    end
end

puts ans.reverse