s = gets.chomp.chars
t = gets.chomp.chars
n = s.size
m = t.size
 
dp = Array.new(n + 1) { Array.new(m + 1, 0) }

def min(a,b); a < b ? b : a; end

1.upto(n) do |i|
  1.upto(m) do |j|
    pre = min(dp[i-1][j], dp[i][j-1])
    pre += 1 if s[i-1] == t[j-1]
    dp[i][j] = pre
  end
end

ans = []
i = n
j = m
while dp[i][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]
    i -= 1
    j -= 1
  end
end

puts ans.reverse.join("")



