s = gets.chomp
t = gets.chomp

dp = Array.new(s.length+1) { Array.new(t.length+1,0) }

0.upto(s.length-1).each do |i|
  0.upto(t.length-1).each do |j|
    if s[i] == t[j]
      dp[i+1][j+1] = dp[i][j] + 1
    else
      dp[i+1][j+1] = dp[i+1][j] > dp[i][j+1] ? dp[i+1][j] : dp[i][j+1]
    end
  end
end

ans = ''
current = dp[s.length][t.length]
y = s.length
x = t.length

while true
  if current == 0
    break
  elsif dp[y-1][x] == current
    y-=1
  elsif dp[y][x-1] == current
    x-=1
  else
    # p [y,x,current]
    y-=1
    x-=1
    ans += s[y]
    current-=1
  end
end

# dp.each{|l| p l}

puts ans.reverse
