def max(a, b)
  a > b ? a : b
end

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...slen).to_a.each do |i|
  (0...tlen).to_a.each do |j|
    if s[i] == t[j]
      dp[i + 1][j + 1] = dp[i][j] + 1
    else
      dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][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