# Educational DP Contest / DP まとめコンテスト
# F - LCS
# https://atcoder.jp/contests/dp/tasks/dp_f?lang=ja

def lcs(x, y)

  # dp[i][j] = x0...xj , y0...yj のLCSの長さ と考える
  #
  # xi+1 == yi+1 -> dp[i+1][j+1] =  dp[i][j] + 1
  x = [''] + x.split('')
  y = [''] + y.split('')

  dp = Array.new(x.length) { Array.new(y.length) {0} }
  sdp = Array.new(x.length) { Array.new(y.length) {''} }
  str = ''

  (1...x.length).each do |i|
    (1...y.length).each do |j|

      if x[i] == y[j]
        dp[i][j] = dp[i-1][j-1] + 1
        #sdp[i][j] = sdp[i-1][j-1] + x[i]

        if dp[i][j] > str.length
          str += '' + x[i]
        end
      else
        dp[i][j] = [dp[i-1][j], dp[i][j-1]].max
        #sdp[i][j] = sdp[i-1][j].length > sdp[i][j-1].length ? sdp[i-1][j] : sdp[i][j-1]
      end

      #p [i, j, dp[i][j], sdp[i][j], x[i] == y[j], x[1..i].join, y[1..j].join]
    end
  end

  #dp[x.length-1][y.length-1]
  str
  #sdp[x.length-1][y.length-1]
end

#Q = gets.chomp.to_i
#x, y = [], []
#
#1.upto(Q).each do |i|
#  x << gets.chomp
#  y << gets.chomp
#end
#
#pp x
#pp y
#
#result = []
#(0...Q).each do |i|
#  result << lcs(x[i], y[i])
#end
#
#pp result

s = gets.chomp
t = gets.chomp

puts lcs(s, t)
