s_orig = gets.chomp
t_orig = gets.chomp

s = s_orig.codepoints
t = t_orig.codepoints

s_size = s.size
t_size = t.size

dp = Array.new(s_size+1) { Array.new(t_size+1,0) }

0.upto(s_size-1).each do |i|
  0.upto(t_size-1).each do |j|
    if s[i] == t[j]
      dp[i+1][j+1] = dp[i][j] + 1
    else
      dp[i+1][j+1] = dp[i+1][j] > dp[i][j+1] ? dp[i+1][j] : dp[i][j+1]
    end
  end
end

ans = ''
y = s_size
x = t_size

while y>0
  if dp[y-1][x] == dp[y][x]
    y-=1
  elsif dp[y][x-1] == dp[y][x]
    x-=1
  else
    y-=1
    x-=1
    ans << s_orig[y]
  end
end

# dp.each{|l| p l}

puts ans.reverse
