import Control.Monad
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV

main=interact $ f.take 2.lines

f [s,t]=reverse $ snd $ (V.! ls) $ foldl' p (V.replicate (ls+1) (0, "")) t where
    vs = UV.fromList s
    ls = length s
    lt = length t
    p v0 ct = v1 where
        v1 = V.generate (ls+1) m
        m 0 = (0, "")
        m i | ct == vs UV.! (i-1) = (na+1, ct : sa) 
            | nb > nc = (nb, sb)
            | otherwise = (nc, sc)
            where
                (na, sa) = v0 V.! (i-1)
                (nb, sb) = v0 V.! i
                (nc, sc) = v1 V.! (i-1)