s = gets.chomp.chars
t = gets.chomp.chars
l = Array.new(s.size + 1) { Array.new(t.size + 1, 0) }

0.step(s.size - 1) do |i|
  0.step(t.size - 1) do |j|
    l[i + 1][j + 1] = l[i + 1][j] if l[i + 1][j] > l[i + 1][j + 1]
    l[i + 1][j + 1] = l[i][j + 1] if l[i][j + 1] > l[i + 1][j + 1]
    l[i + 1][j + 1] = l[i][j] + 1 if s[i] == t[j] && l[i][j] + 1 > l[i + 1][j + 1]
  end
end

i = s.size
j = t.size
res = ""
while i > 0 && j > 0
  if l[i][j] == l[i - 1][j]
    i -= 1
  elsif l[i][j] == l[i][j - 1]
    j -= 1
  else
    res = s[i - 1] + res
    i -= 1
    j -= 1
  end
end
puts res