import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Array.Unboxed
import Data.Array.ST
import Control.Monad.ST

main = do
    s <- BS.getLine
    t <- BS.getLine
    putStrLn . solve s t (BS.length s - 1) (BS.length t - 1) $ makeTable s t

makeTable s t = runSTUArray $ do
    let n = BS.length s
        m = BS.length t
    arr <- newArray ((-1,-1),(n-1,m-1)) 0 :: ST s (STUArray s (Int, Int) Int)
    forM_ [0..n-1] $ \i -> do
        forM_ [0..m-1] $ \j -> do
            let x = BS.index s i
                y = BS.index t j
            if x == y then do
                l <- readArray arr (i-1, j-1)
                writeArray arr (i, j) (l + 1)
            else do
                li <- readArray arr (i-1, j)
                lj <- readArray arr (i, j-1)
                writeArray arr (i,j) (max li lj)
    return arr

solve s t i j table = reverse $ loop i j
    where loop (-1) _ = []
          loop _ (-1) = []
          loop i j | si == tj = si : loop (i-1) (j-1)
                   | i1j == ij = loop (i-1) j
                   | otherwise = loop i (j-1)
                   where si = BS.index s i
                         tj = BS.index t j
                         i1j = table ! (i-1,j)
                         ij = table ! (i,j)