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

(&) :: 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
        v_end = B.foldl' step s0 t & V.last & p_snd & ("" &)
        step :: V.Vector P -> Char -> V.Vector P
        step tbl ch = tbl'
            where
            tbl' = V.constructN (len_s + 1) gen 
            gen vec | i == 0 = mempty
                    | ch == ch' = a1 `max` a2 `max` a3
                    | otherwise = a1 `max` a2
                where
                    i = V.length vec
                    ch' = B.index s (i - 1)
                    a1 = V.last vec
                    a2 = tbl V.! i
                    a3 = tbl V.! (i - 1) <> (P 1 (ch:))
        s0 = V.replicate (len_s + 1) mempty
    putStrLn (v_end :: String)
    
