s = gets.chomp
t = gets.chomp
slength = s.size
tlength = t.size
# dp = Array.new(slength + 1){Array.new(tlength + 1, "")}
dp = Array.new(tlength + 1, "")

slength.times do |i|
  tlength.times do |j|
    if s[i] == t[j]
      dp[j+1] = dp[j] + t[j]
    else
      dp[j+1] = dp[j] if dp[j+1].size < dp[j].size
    end
  end
end
puts dp[tlength]