ar1 = gets.chomp.split("")
ar2 = gets.chomp.split("")
dp = Array.new(ar2.length+1).map{Array.new(ar1.length+1, 0)}
(1..ar2.length).each {|i| (1..ar1.length).each {|j|
  if ar2[i-1] == ar1[j-1]
    dp[i][j] = dp[i-1][j-1]+1
  else
    if dp[i-1][j] > dp[i][j-1]
      dp[i][j] = dp[i-1][j]
    else
      dp[i][j] = dp[i][j-1]
    end
  end}}
n = ar2.length
m = ar1.length
ans = []
while dp[n][m] > 0
  if dp[n][m] != dp[n-1][m] && dp[n][m] != dp[n][m-1]
    ans.push(ar2[n-1])
    n -= 1
    m -= 1
  elsif dp[n][m] == dp[n-1][m] && n > 1
    n -= 1
  elsif dp[n][m] == dp[n][m-1] && m > 1
    m -= 1
  end
end
puts ans.reverse.join
