S=gets.strip
T=gets.strip
SN=S.codepoints
TN=T.codepoints
SL=S.size
TL=T.size
dp_y0=Array.new(SL,"")
dp_y0n=Array.new(SL,0)
dp_x0=Array.new(TL,"")
dp_x0n=Array.new(TL,0)

for i in 0...SL
  dp_y0[i]=SN[0,i+1].include?(TN[0]) ? T[0] : ""
  dp_y0n[i]=SN[0,i+1].include?(TN[0]) ? 0 : 1
end
for i in 0...TL
  dp_x0[i]=TN[0,i+1].include?(SN[0]) ? S[0] : ""
  dp_x0n[i]=TN[0,i+1].include?(SN[0]) ? 0 : 1
end
dp_xi=dp_x0.clone
dp_xin=dp_x0n.clone


for i in 1...SL
  dp_xi_1 = dp_xi.clone
  dp_xi_1n = dp_xin.clone
  dp_xi[0]=dp_y0[i]
  dp_xin[0]=dp_y0n[i]
  for j in 1...TL
    if SN[i]==TN[j]
      dp_xi[j]=dp_xi_1[j-1]+S[i]
      dp_xin[j]=dp_xi_1n[j-1]+1
    else
      dp_xi[j]=dp_xi_1n[j] <= dp_xin[j-1] ? dp_xi[j-1] : dp_xi_1[j]
      dp_xin[j]=dp_xi_1n[j] <= dp_xin[j-1] ? dp_xin[j-1] : dp_xi_1n[j]

    end
  end
end
puts dp_xi[TL-1]
