class String
  def lcs(str)
    n = size
    m = str.size
    dp = Array.new(n + 1) { Array.new(m + 1, 0) }

    list = str.chars

    chars.each_with_index do |s, i|
      list.each_with_index do |t, j|
        if s == t
          dp[i + 1][j + 1] = dp[i][j] + 1
        else
          if dp[i][j + 1] < dp[i + 1][j]
            dp[i + 1][j + 1] = dp[i + 1][j]
          else
            dp[i + 1][j + 1] = dp[i][j + 1]
          end
        end
      end
    end

    ret = ''

    i = size
    j = str.size

    while i > 0 && j > 0
      if dp[i][j] == dp[i - 1][j]
        i -= 1
      elsif dp[i][j] == dp[i][j - 1]
        j -= 1
      else
        ret = self[i - 1] + ret
        i -= 1
        j -= 1
      end
    end

    ret
  end
end

s = gets.chomp
t = gets.chomp

puts s.lcs(t)
