import qualified Data.Vector as V

main = do
    s <- getLine
    t <- getLine
    putStrLn $ reverse $ lcs s t V.! (length s) V.! (length t)

lcs xs ys = V.scanl step (V.replicate (m+1) []) xs'
  where n = length xs
        m = length ys
        xs' = V.fromList xs
        ys' = V.fromList ys
        step v x = V.scanl innerstep [] (V.zip3 v (V.tail v) ys')
          where innerstep a (b,c,y) | x == y = x : b
                                    | otherwise = if length a >= length c then a else c