S = gets.chomp.chars
T = gets.chomp.chars

def calc(s, t)
  return [] if s == S.size || t == T.size

  return [S[s], *calc(s + 1, t + 1)] if S[s] == T[t]

  s2 = calc(s + 1, t)
  t2 = calc(s, t + 1)

  s2.size > t2.size ? s2 : t2
end

print calc(0, 0).join
