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

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