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 Debug.Trace

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

mkTable :: Str -> Str -> Int -> Int -> Table
mkTable s t sl tl = -- '-'はAlphabetではないもの
    listArray ((1,1),(sl,tl)) [if s!i == t!j then (s!i) else '-' | i <- [1..sl], j <- [1..tl]]

add :: DP -> Char -> Int -> DP
add (Node (c,n) []) c0 i = (Node (c,n) [Node (c0:c,i) []])
add (Node (c,n) xs) c0 i =
  let less = filter (\(Node (c',n') _) -> i > n') xs in
    if less == []
      then (Node (c,n) ((Node (c0:c,i) []):xs))
      else (Node (c,n) (map (\t -> if i > (snd $ rootLabel t) then add t c0 i else t) xs))

dp_i :: DP -> Table -> Int -> Int -> Int -> Int -> DP
dp_i tree table sl tl i j
  | i > sl && j >= tl = tree
  | i > sl            = dp_i tree table sl tl 1 (j+1)
  | otherwise = if table!(i,j) == '-' then dp_i tree table sl tl (i+1) j
  else dp_i  (add tree (table!(i,j)) i) table sl tl (i+1) j

find :: DP -> String
find (Node (s,n) []) = s
find (Node _ xs) = head $ sortOn ((0-).length) $ map (\t -> find t) xs

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


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
