import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS

main = do
    s <- BS.getLine
    t <- BS.getLine
    putStrLn $ lcs s t

lcs xs ys = reverse . (V.! m) . (V.! n) $ V.scanl step (V.replicate (m+1) []) xs'
  where n = BS.length xs
        m = BS.length ys
        xs' = V.generate n $ BS.index xs
        ys' = V.generate m $ BS.index 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