def max(a, b)
  a < b ? b : a
end

s = gets.chomp
t = gets.chomp
slen = s.size
tlen = t.size
dp = Array.new(slen) { Array.new(tlen) { 0 } }

dp[0][0] = s[0] == t[0] ? 1 : 0
(1...slen).each do |i|
  dp[i][0] = dp[i - 1][0]
  dp[i][0] += 1 if s[i] == t[0]
end

(1...tlen).to_a.each do |i|
  dp[0][i] = dp[0][i - 1]
  dp[0][i] += 1 if t[i] == s[0]
end

(1...slen).to_a.each do |i|
  (1...tlen).to_a.each do |j|
    if s[i] == t[j]
      dp[i][j] = dp[i - 1][j - 1] + 1
    else
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
    end
  end
end

len = dp[-1][-1]
ans = []
i, j = slen - 1, tlen - 1
while len > 0
	if s[i] == t[j]
		ans.unshift(s[i])
		i -= 1
		j -= 1
		len -= 1
  elsif dp[i][j] == dp[i][j - 1]
		j -= 1
	else
		i -= 1
  end
end

puts ans.join