first=gets.chomp.to_s
second=gets.chomp.to_s

dp=Array.new(3001){[0]*3001}
array=[]
flag=Array.new(first.length){0}
for i in 0..first.length-1
    for j in 0..second.length-1
        if first[i]==second[j]
            dp[i+1][j+1]=dp[i][j]+1
            flag[i]=1
        else
            dp[i+1][j+1]=[dp[i+1][j],dp[i][j+1]].max
        end
    end
end

p dp[first.length][second.length]
result=[]
for i in 0..flag.length-1
    if flag[i]==1
       result<<first[i]
    end
    
end

puts result.join("")