{-# LANGUAGE BangPatterns, OverloadedStrings #-}
import Control.Arrow
import Control.Monad.Fix
import qualified Data.Array as AU
import qualified Data.Array.IO as AUM
import Data.Int
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VUM.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uset :: VUM.Unbox a => a -> VUM.IOVector a -> VUM.IOVector a
uset !a !v = accursedUnutterablePerformIO $ VUM.set v a >> return v

solve :: B.ByteString -> B.ByteString -> String
solve !s !t = walk
 where
  (!) :: AU.Array (Int, Int) Int16 -> (Int, Int) -> Int16
  (!) !vec (!i, !j) | i == 0 || j == 0 = 0
                    | otherwise        = vec AU.! (i, j)

  dp :: AU.Array (Int, Int) Int16
  dp = AU.array
    ((0, 0), (B.length s, B.length t))
    [ ( (i, j)
      , let si = B.index s (i - 1)
            tj = B.index t (j - 1)
        in  if i == 0 || j == 0
              then 0
              else if si == tj
                then dp ! (i - 1, j - 1) + 1
                else max (dp ! (i, j - 1)) (dp ! (i - 1, j))
      )
    | i <- [0 .. B.length s]
    , j <- [0 .. B.length t]
    ]

  walk = 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 (s `B.index` (i - 1) : acc, (i - 1, j - 1))
        else if dp AU.! (i - 1, j) < dp AU.! (i, 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
  putStrLn $ solve s t
