S = gets.chomp
T = gets.chomp

S_SIZE = S.size
T_SIZE = T.size
dp = Array.new(S_SIZE + 1) { Array.new(T_SIZE + 1, 0) }

S_SIZE.times do |s|
  T_SIZE.times do |t|
    if S[s] == T[t]
      dp[s+1][t+1] = dp[s][t] + 1
    else
      dp[s+1][t+1] = [dp[s+1][t], dp[s][t+1]].max
    end
  end
end

lcs = ''
s = S_SIZE
t = T_SIZE
while s > 0 && t > 0
  if dp[s][t] == dp[s-1][t]
    s -= 1
  elsif dp[s][t] == dp[s][t-1]
    t -= 1
  else
    lcs << S[s-1]
    s -= 1
    t -= 1
  end
end

puts lcs.reverse