S = gets.chomp.chars
T = gets.chomp.chars
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
      a = dp[i][j+1]
      b = dp[i+1][j]
      dp[i+1][j+1] = a > b ? a : b
    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 -= 1
    j -= 1
  end
end

puts ans.reverse
