s = gets.chomp
t = gets.chomp
n = s.size
m = t.size

dp = Array.new(n+1){Array.new(m+1, 0)}
n.times do |i|
  m.times do |j|
    if s[i] == t[j]
      dp[i+1][j+1] = dp[i][j] + 1
    else
      dp[i+1][j+1] = dp[i][j+1] if dp[i][j+1] > dp[i+1][j+1]
      dp[i+1][j+1] = dp[i+1][j] if dp[i+1][j] > dp[i+1][j+1]
    end
  end
end

i, j = n, m
ans = ''
while i > 0 && j > 0 do
  if dp[i][j] == dp[i-1][j]
    i -= 1
  elsif dp[i][j] == dp[i][j-1]
    j -= 1
  else
    ans << s[i-1]
    i, j = i-1, j-1
  end
end

puts ans.reverse
