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

dp = Array.new(n + 1) { Array.new(m + 1, 0) }

(0...n).each do |i|
  (0...m).each do |j|
    dp[i + 1][j + 1] =
      if s[i] == t[j]
        dp[i][j] + 1
      else
        [
          dp[i + 1][j],
          dp[i][j + 1]
        ].max
      end
  end
end

ans = ''
i = n
j = m
while i > 0 && j > 0
  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] + ans
    i -= 1
    j -= 1
  end
end

puts ans
