{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Array.Unboxed
import Data.Array.ST
import qualified Data.ByteString.Char8 as BS

makeTable :: BS.ByteString -> BS.ByteString -> UArray (Int,Int) Int
makeTable xs ys =
  runSTUArray $ do
    dp <- newArray ((0,0),(BS.length xs, BS.length ys)) 0
    forM_ [0..BS.length xs -1] $ \i ->
      forM_ [0..BS.length ys - 1] $ \j ->
        if BS.index xs i == BS.index ys j 
           then do
             rd <- readArray dp (i,j)
             writeArray dp (i+1,j+1) $! rd+1 
           else do
             rd1 <- readArray dp (i+1,j)
             rd2 <- readArray dp (i,j+1)
             writeArray dp (i+1,j+1) $! max rd1 rd2
    return dp

construct :: UArray (Int,Int) Int -> BS.ByteString -> BS.ByteString -> (Int,Int) -> BS.ByteString -> BS.ByteString
construct dp xs ys (n,m) bs
  | n == 0 || m == 0 = bs
  | BS.index xs (n-1) == BS.index ys (m-1) = construct dp xs ys (n-1,m-1) (BS.cons (BS.index xs (n-1)) bs)
  | otherwise =
    let
      a = dp ! (n-1,m)
      b = dp ! (n,m-1)
    in
      if a >= b then construct dp xs ys (n-1,m) bs
                else construct dp xs ys (n,m-1) bs
main = do 
  xs <- BS.getLine
  ys <- BS.getLine
  let n = BS.length xs
  let m = BS.length ys
  let dp = makeTable xs ys
  putStrLn $ BS.unpack $ construct dp xs ys (n,m) BS.empty

