import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import           Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  sa <- BS.getLine
  ta <- BS.getLine
  let n = BS.length sa
      m = BS.length ta
  let result = solve (n,sa) (m,ta)
  putStrLn $ restore sa result n m

solve :: (Int, ByteString) -> (Int, ByteString) -> UArray (Int,Int) Int
solve (n',sa) (m',ta) = runSTUArray $ do
  dp <- newArray ((0,0),(n',m')) 0
  forM_ [(n_,m_) | n_ <- [1..n'], m_ <- [1..m']] $ \(n,m) -> do
    a <- readArray dp (n-1,m-1)
    b <- readArray dp (n,m-1)
    c <- readArray dp (n-1,m)
    if sa `BS.index` (n-1) == ta `BS.index` (m-1)
      then writeArray dp (n,m) $ maximum [a+1,b,c]
      else writeArray dp (n,m) $ maximum [b,c]
  return dp

restore :: ByteString -> UArray (Int,Int) Int -> Int -> Int -> String
restore st ary n m = go n m ""
  where go 0 _ ss = ss
        go _ 0 ss = ss
        go i j ss
          | ary U.! (i,j) == ary U.! (i-1,j) = go (i-1) j ss
          | ary U.! (i,j) == ary U.! (i,j-1) = go i (j-1) ss
          | otherwise                        = go (i-1) (j-1) ((st `BS.index` (i-1)):ss)
