import qualified Data.ByteString.Char8 as B
import Data.List
import qualified Data.Vector.Unboxed as V
import Data.Monoid((<>))
import Data.Function hiding ((&))
import Debug.Trace

(&) :: a -> (a -> b) -> b
(&) a b = b a

infixl 1 &

data P = P { p_fst :: {-# UNPACK #-} !Int, 
             p_snd :: (String -> String) }

{-
instance Eq P where
    (==) = (==) `on` p_fst
instance Ord P where
    compare = compare `on` p_fst
instance Monoid P where
    mappend (P a b) (P c d) = P (a + c) (b . d)
    mempty = P 0 id 
    -}

main :: IO ()
main = do
    s <- B.getLine
    t <- B.getLine
    let len_s = B.length s
        len_t = B.length t
        v_end = scanl' step s0 (B.unpack t) 
                    & reverse 
                    & dig (len_t, len_s) ""
        step :: V.Vector (Int,Int) -> Char -> V.Vector (Int,Int)
        step tbl ch = tbl'
            where
            tbl' = V.constructN (len_s + 1) gen 
            gen vec | i == 0 = (0, -1)
                    | ch == ch' = (a1,0) `max` (a2,1) `max` (a3,2)
                    | otherwise = (a1,0) `max` (a2,1)
                where
                    i = V.length vec
                    ch' = B.index s (i - 1)
                    a1 = fst $ V.last vec
                    a2 = fst $ tbl V.! i
                    a3 = fst (tbl V.! (i - 1)) + 1
        dig :: (Int, Int) -> String -> [V.Vector (Int, Int)] -> String
        dig (i,j) acc (tbl:tbls) 
            | dir == 0 = dig (i,j-1) acc (tbl:tbls)
            | dir == 1 = dig (i-1,j) acc tbls
            | dir == 2 = dig (i-1,j-1) (B.index t (i-1) :acc) tbls
            | otherwise = acc
            where
                (_, dir) = tbl V.! j
        s0 = V.replicate (len_s + 1) (0,-1)
    putStrLn v_end 
    
