S=gets.strip
T=gets.strip

dp_y0=Array.new(S.size,"")
dp_x0=Array.new(T.size,"")
for i in 0...S.size
  dp_y0[i]=S[0,i+1].include?(T[0]) ? T[0] : ""
end
for i in 0...T.size
  dp_x0[i]=T[0,i+1].include?(S[0]) ? S[0] : ""
end
dp_xi=dp_x0.clone

for i in 1...S.size
  dp_xi_1 = dp_xi.clone
  dp_xi[0]=dp_y0[i]
  for j in 1...T.size
    if S[i]==T[j]
      dp_xi[j]=dp_xi_1[j-1]+S[i]
    else
      dp_xi[j]=dp_xi_1[j].size <= dp_xi[j-1].size ? dp_xi[j-1] : dp_xi_1[j]
    end
  end
end
puts dp_xi[T.size-1]
