s = gets.chomp
t = gets.chomp

s_code = s.codepoints
t_code = t.codepoints

s_size = s.size
t_size = t.size

dp = Array.new(t_size + 1) { Array.new(s_size + 1, 0) }

1.upto(t_size) do |i|
  1.upto(s_size) do |j|
    i_prev = i - 1
    j_prev = j - 1

    dp[i][j] = if t_code[i_prev] == s_code[j_prev]
                 dp[i_prev][j_prev] + 1
               else
                 dp[i_prev][j] < dp[i][j_prev] ? dp[i][j_prev] : dp[i_prev][j]
               end
  end
end

result = ""
i = t_size
j = s_size
while 0 < i && 0 < j
  if dp[i - 1][j] == dp[i][j]
    i -= 1
  elsif dp[i][j - 1] == dp[i][j]
    j -= 1
  else
    i -= 1
    j -= 1
    result << s[j]
  end
end

puts result.reverse
