s_orig = gets.chomp
t_orig = gets.chomp

s = s_orig.codepoints
t = t_orig.codepoints

slen = s.size
tlen = t.size

dp = Array.new(slen + 1) { Array.new(tlen + 1, 0) }

0.upto(slen - 1) do |i|
  0.upto(tlen - 1) do |j|
    dpi = dp[i]
    dpi1 = dp[i + 1]
    if s[i] == t[j]
      dpi1[j + 1] = dpi[j] + 1
    else
      dpi1[j + 1] = dpi[j + 1] > dpi1[j] ? dpi[j + 1] : dpi1[j]
    end
  end
end

ans = []
y, x = slen, tlen

while y > 0
  if dp[y][x] == dp[y - 1][x - 1] + 1
    ans << s[y - 1]
    y -= 1
    x -= 1
  elsif dp[y][x] == dp[y - 1][x]
    y -= 1
  else
    x -= 1
  end
end

puts ans.reverse.map!(&:chr).join