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

dp = Hash.new(0)
n.times do |i|
  m.times do |j|
    if s[i] == t[j]
      dp["#{i+1}:#{j+1}"] = dp["#{i}:#{j}"] + 1
    else
      a = dp["#{i}:#{j+1}"]
      b = dp["#{i+1}:#{j}"]
      dp["#{i+1}:#{j+1}"] = a > b ? a : b
    end
  end
end

i, j = n, m
ans = ''
while i > 0 && j > 0 do
  if dp["#{i}:#{j}"] == dp["#{i-1}:#{j}"]
    i -= 1
  elsif dp["#{i}:#{j}"] == dp["#{i}:#{j-1}"]
    j -= 1
  else
    ans << s[i-1]
    i -= 1
    j -= 1
  end
end

puts ans.reverse
