def max(a, b)
  a > b ? a : b
end

S = gets.chomp
T = gets.chomp

S_cod = S.codepoints
T_cod = T.codepoints

S_len = S.length
T_len = T.length

dp = Array.new(S_len + 1){Array.new(T_len + 1, 0)}

S_len.times do |i|
  dpi = dp[i]
  dpi1 = dp[i + 1]
  T_len.times do |j|
    if S_cod[i] == T_cod[j]
      dpi1[j + 1] = dpi[j] + 1
    else
      dpi1[j + 1] = max(dpi1[j], dpi[j + 1])
    end
  end
end

ans = ''
s_i = S_len
t_i = T_len

while s_i > 0 && t_i > 0
  if dp[s_i - 1][t_i] == dp[s_i][t_i]
    s_i -= 1
  elsif dp[s_i][t_i - 1] == dp[s_i][t_i]
    t_i -= 1
  else
    ans += S[s_i - 1]
    s_i -= 1
    t_i -= 1    
  end
end

puts ans.reverse