s = gets.chomp
t = gets.chomp

# dp[sの決めた位置][tの決めた位置] := 部分列一致の長さ
dp = Array.new(s.size + 1) { Array.new(t.size + 1, 0) }

s.size.times do |i|
  t.size.times do |j|
    if s[i] == t[j]
      dp[i + 1][j + 1] = dp[i][j] + 1
    else
      dp[i + 1][j + 1] = [dp[i][j + 1],dp[i + 1][j]].max
    end
  end
end

i = s.size
j = t.size
ans = []
while i > 0 || j > 0
  if dp[i-1][j] == dp[i][j]
    i -= 1
  elsif dp[i][j-1] == dp[i][j]
    j -= 1
  else
    ans.unshift(s[i-1])
    i -= 1
    j -= 1
  end
end

puts ans.join
