import Data.Array.Unboxed
import Data.Array.IO
import Control.Applicative
import Control.Monad

makeDp :: String -> String -> IO (IOUArray (Int,Int) Int)
makeDp s t = do
  let ls = length s
  let lt = length t
  dp  <- newArray ((0,0),(ls,lt)) 0
  forM_ [1..ls] $ \i ->
    forM_ [1..lt] $ \j ->
      if s !! (i-1) == t !! (j-1)
         then readArray dp (i-1,j-1) >>= \rd -> writeArray dp (i,j) (rd+1)
      else do
        rd1 <- readArray dp (i,j-1)
        rd2 <- readArray dp (i-1,j)
        writeArray dp (i,j) $ max rd1 rd2
  return dp

analyse :: IOUArray (Int,Int) Int -> (String,Int) -> (String,Int) -> String -> IO String
analyse dp (s,l) (t,m) acc
  | l == 0 || m == 0 = return $ reverse acc
  | otherwise = 
    if s !! (l-1) == t !! (m-1)
       then do
         analyse dp (s,l-1) (t,m-1) (s !! (l-1) : acc)
    else do
      rd1 <- readArray dp (l-1,m)
      rd2 <- readArray dp (l,m-1)
      if rd1 >= rd2
         then analyse dp (s,l-1) (t,m) acc
      else
          analyse dp (s,l) (t,m-1) acc

solve :: String -> String -> IO String 
solve s t = do
  let l = length s
  let m = length t
  dp <- makeDp s t
  analyse dp (s,l) (t,m) []
  
main = do
  s <- getLine :: IO String
  t <- getLine :: IO String
  solve s t >>= putStrLn
