{-# LANGUAGE BangPatterns, OverloadedStrings #-}
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: B.ByteString -> B.ByteString -> B.ByteString
solve !s !t = walk
 where
  toIndex !i !j = j * succ (B.length s) + i
  sChars = V.unfoldrN (B.length s) (\(!k) -> Just (B.index s k, k + 1)) 0
  tChars = V.unfoldrN (B.length t) (\(!k) -> Just (B.index t k, k + 1)) 0

  dp :: V.Vector (VU.Vector Int16)
  dp = V.scanl'
    ( \(!prev) (!si) -> V.convert $ V.scanl'
      ( \(!cur) (!j, !tj) ->
        if si == tj then prev VU.! j + 1 else max cur (prev VU.! (j + 1))
      )
      0
      (V.indexed tChars)
    )
    (VU.replicate (B.length t + 1) 0)
    sChars

  walk =
    fst
      $ B.unfoldrN (fromIntegral $ dp V.! B.length s VU.! B.length t)
                   (\(x:xs) -> Just $ (,) (B.index s x) xs)
      $ fst
      $ fix
          ( \(!f) (!acc, (!i, !j)) -> if i == 0 || j == 0
            then (acc, (i, j))
            else if s `B.index` (i - 1) == t `B.index` (j - 1)
              then f ((i - 1) : acc, (i - 1, j - 1))
              else if dp V.! (i - 1) VU.! j < dp V.! i VU.! (j - 1)
                then f (acc, (i, j - 1))
                else f (acc, (i - 1, j))
          )
          ([], (B.length s, B.length t))

main = do
  s <- B.getLine
  t <- B.getLine
  B.putStrLn $ solve s t
