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