# LCS 最長共通部分列
# reference: http://9871225.blog.fc2.com/blog-entry-304.html

s = gets.chomp.split("")
s.unshift("")
s_len = s.length
t = gets.chomp.split("")
t.unshift("")
t_len = t.length
dp = Array.new(s_len) { Array.new(t_len + 1, 0) }

# dpテーブルを埋める
(1...t_len).each do |t_index|
  (1...s_len).each do |s_index|
    if t[t_index] == s[s_index]
      dp[s_index][t_index + 1] = dp[s_index - 1][t_index] + 1
    else
      up = dp[s_index - 1][t_index + 1]
      left = dp[s_index][t_index]
      dp[s_index][t_index + 1] = up > left ? up : left
    end
  end
end

# 時間をはかる
exit

# dpテーブルを右下から左上に辿って文字列を復元
count = dp.last.last
current_s = s_len - 1
current_t = t_len
restored = []
while count > 0
  loop do
    if dp[current_s - 1][current_t] == count
      current_s -= 1
    else
      break
    end
  end
  loop do
    if dp[current_s][current_t - 1] == count
      current_t -= 1
    else
      break
    end
  end
  restored.unshift(s[current_s])
  count -= 1
end

puts restored.join("")
