import Data.List hiding (find)
import Data.Tree
--import Data.Array
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
--import Data.Vector as V
import Control.Monad
import Control.Monad.ST
import Control.Monad.State
import Debug.Trace

type Str = UArray Int Char
type Table = [(Char,Int)] --sl*tl matrix
type DP = Tree (String,Int)

mkTable :: Str -> Str -> Int -> Int -> Table
mkTable s t sl tl = [(s!i,i) | j <- [1..tl], i <- [1..sl], s!i == t!j]

add :: DP -> Char -> Int -> State String DP
add (Node (c,n) []) c0 i = do
  s <- get
  if (length c) >= (length s) then put (c0:c)
    else return ()
  return (Node (c,n) [Node (c0:c,i) []])
add (Node (c,n) xs) c0 i = do
  s <- get
  if [] == filter (\(Node (c',n') _) -> i > n') xs
    then if (length c) >= (length s) then put (c0:c) >> return (Node (c,n) ((Node (c0:c,i) []):xs))
           else return (Node (c,n) ((Node (c0:c,i) []):xs))
    else sequence (map (\t -> if i > (snd $ rootLabel t) then add t c0 i else return t) xs) >>= \l -> return (Node (c,n) l)

dp_i :: DP -> Table -> State String DP
dp_i tree [] = return tree
dp_i tree (t:table) = do
   tree' <- (add tree (fst t) (snd t))
   dp_i tree' table

solve :: Str -> Str -> Int -> Int -> String
solve s t sl tl = ans
  where (anstree,ans') = runState (dp_i (Node ("",0) []) (mkTable s t sl tl)) ""
        ans = reverse $ ans'


main :: IO ()
main = do
  s <- getLine
  t <- getLine
  let sl = length s
      tl = length t
      s' = listArray (1,sl) s
      t' = listArray (1,tl) t
  putStrLn $ solve s' t' sl tl
