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]
  case dc[j]
  when dp[j]
    i-=1
  when dc[j-1]
    j-=1
  when dp[j-1]+1
    res<<S[i-1]
    i-=1;j-=1
  end
end
puts res.reverse