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

0.step(s.size - 1) do |i|
  r0 = l[i]
  r1 = l[i + 1]
  0.step(t.size - 1) do |j|
    r1[j + 1] = if s[i] == t[j]
      r0[j] + 1
    else
      (r0[j + 1] > r1[j])? r0[j + 1] : r1[j]
    end
  end
end

n = s.size
m = t.size
i = l[n][m]
res = []
while i > 0
  if l[n][m] == l[n - 1][m]
    n -= 1
  elsif l[n][m] == l[n][m - 1]
    m -= 1
  else
    res.unshift(s[n - 1])
    i -= 1
    n -= 1
    m -= 1
  end
end
puts res.join("")