S=gets.chomp
T=gets.chomp
SC=S.codepoints
TC=T.codepoints
SS=S.size
TS=T.size
d=Array.new(SS+1){Array.new(TS+1,0)}
1.upto(SS){|i| 1.upto(TS){|j|
  d_prev=d[i-1]
  d_cur=d[i]
  if SC[i-1]==TC[j-1]
    d_cur[j]=d_prev[j-1]+1 #if d[i][j]<d[i-1][j-1]+1
  else
    d_cur[j]=d_cur[j-1]
    d_cur[j]=d_prev[j] if d_cur[j]<d_prev[j]
  end
}}
#puts d[s.size][t.size]
i=SS
j=TS
res=""
while i>0 and j>0
  dp=d[i-1]
  dc=d[i]
  dcj=dc[j]
  if dcj==dp[j]
    i-=1
  elsif dcj==dc[j-1]
    j-=1
  elsif dcj=dp[j-1]+1
    res<<S[i-1]
    i-=1;j-=1
  end
end
puts res.reverse
