s = gets.chomp.chars
t = gets.chomp.chars
dp = Array.new(s.size + 10)
dp.size.times do |i|
  dp[i] = Array.new(t.size + 10) { [0, []] }
end
s.size.times do |i|
  t.size.times do |j|
    dp[i + 1][j + 1] =
      if s[i] == t[j]
        c, str = dp[i][j]
        [c + 1, str + [s[i]]]
      else
        a = dp[i][j + 1]
        b = dp[i + 1][j]
        a[0] > b[0] ? a : b
      end
  end
end
puts dp[s.size][t.size][1].join('')
