class Array
    def lcs(array)
        self.unshift(0)
        array.unshift(0)
        dp=Array.new(self.size+1){Array.new(array.size+1,Array.new)}
        f=false
        for i in 1..array.size
            f=true if self[1]==array[i]
            dp[1][i]=[self[1]] if f
        end
        f=false
        for i in 1..self.size
            f=true if self[i]==array[1]
            dp[i][1]=[array[1]] if f
        end
        for y in 2..self.size
            for x in 2..array.size
                if self[y]==array[x]
                    dp[y][x]=dp[y-1][x-1]+[self[y]]
                else
                    dp[y][x]=dp[y-1][x].size > dp[y][x-1].size ? dp[y-1][x] : dp[y][x-1]
                end
            end
        end
        self.shift
        return dp[self.size][array.size]
    end
end
s=gets.strip.codepoints
t=gets.strip.codepoints

puts s.lcs(t).map{|i|i.chr}.join
