s=gets.chomp
t=gets.chomp
ss=s.size
ts=t.size
d=Array.new(ss+1){Array.new(ts+1,0)}
1.upto(ss){|i| 1.upto(ts){|j|
  if s[i-1]==t[j-1]
    d[i][j]=d[i-1][j-1]+1 #if d[i][j]<d[i-1][j-1]+1
  else
    d[i][j]=d[i][j-1] if d[i][j]<d[i][j-1]
    d[i][j]=d[i-1][j] if d[i][j]<d[i-1][j]
  end
}}
#puts d[s.size][t.size]
i=ss
j=ts
res=""
while i>0 and j>0
  case d[i][j]
  when d[i-1][j]
    i-=1
  when d[i][j-1]
    j-=1
  when d[i-1][j-1]+1
    res=s[i-1]+res
    i-=1;j-=1
  end
end
puts res