import Control.Monad
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU

lcsTable :: BS.ByteString -> BS.ByteString -> V.Vector (VU.Vector Int)
lcsTable xs ys = V.scanl step (VU.replicate (m+1) 0) xs'
  where
    n = BS.length xs
    m = BS.length ys
    xs' = V.generate n $ BS.index xs :: V.Vector Char
    ys' = VU.generate m $ BS.index ys :: VU.Vector Char
    step :: VU.Vector Int -> Char -> VU.Vector Int
    step v x = VU.scanl innerStep 0 (VU.zip3 v (VU.tail v) ys')
      where
        innerStep :: Int -> (Int,Int,Char) -> Int
        innerStep a (b,c,y) | x == y = 1 + b
                            | otherwise = max a c

construct :: V.Vector (VU.Vector Int) -> BS.ByteString -> BS.ByteString -> (Int,Int) -> BS.ByteString -> BS.ByteString
construct dp xs ys (m,n) bs 
  | m == 0 || n == 0 = bs 
  | BS.index xs (m-1) == BS.index ys (n-1) = construct dp xs ys (m-1,n-1) (BS.cons (BS.index xs (m-1)) bs) 
  | otherwise = 
    let
      rd1 = (dp V.! (m-1)) VU.! n
      rd2 = (dp V.! m) VU.! (n-1)
    in
      if rd1 >= rd2 then construct dp xs ys (m-1,n) bs
                    else construct dp xs ys (m,n-1) bs
main = do 
  xs <- BS.getLine
  ys <- BS.getLine
  let dp = lcsTable xs ys 
  putStrLn $ BS.unpack $ construct dp xs ys (BS.length xs, BS.length ys) BS.empty