s = gets.chomp
t = gets.chomp
dp = Array.new(t.size+1).map{Array.new(s.size+1,"")}
(t.size+1).times{|i|
    (s.size+1).times{|j|
        dp[i+1][j+1] = (a=dp[i+1][j+1]).size > (b = dp[i][j] + s[j]).size ? a : b if s[j] == t[i] and j != s.size and i != t.size
        dp[i][j+1] = (a = dp[i][j]).size > (b = dp[i][j+1]).size ? a : b if j != s.size
        dp[i+1][j] = (a = dp[i][j]).size > (b = dp[i+1][j]).size ? a : b if i != t.size
    }
}
puts dp[-1][-1]
