s = gets.chop
t = gets.chop
n = s.size
m = t.size
ml = n > m ? n : m

dp = Array.new(ml+1) { Array.new(ml+1, nil) }

(n+1).times do |i|
  (m+1).times do |j|
    if i.zero? || j.zero?
      dp[i][j] = 0
      next
    end

    dp[i][j] = dp[i-1][j] > dp[i][j-1] ? dp[i-1][j] : dp[i][j-1]
    if s[i-1] == t[j-1] && dp[i][j] < dp[i-1][j-1] + 1
      dp[i][j] = dp[i-1][j-1] + 1
    end
  end
end
sna = []

loop do
  break if n.zero? || m.zero?

  if dp[n][m] == dp[n-1][m]
    n -= 1
  elsif dp[n][m] == dp[n][m-1]
    m -= 1
  else
    sna << s[n-1]
    n -= 1
    m -= 1
  end
end

puts sna.join.reverse