{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Word
import qualified Data.ByteString as BSW
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Generic as G

-- Input: s t
-- Output: arr
--   arr ! (i,j) == length of lcs of (drop i s, drop j t)
--   (arr ! i) ! j == length of lcs of (drop i s, drop j t)
lcsTableV :: BS.ByteString -> BS.ByteString -> V.Vector (U.Vector Word16)
lcsTableV s t = V.scanr' (\ !x !v ->
                            G.iscanr (\ !j (!w,!u) !l -> if x == BSW.index t j
                                                         then u + 1
                                                         else max w l
                                     ) 0 (U.zip (U.init v) (U.tail v))
                         ) (U.replicate (n+1) 0) (V.fromListN m $ BSW.unpack s)
  where !m = BS.length s
        !n = BS.length t

main = do
  s <- BS.getLine
  t <- BS.getLine
  -- BS.length s <= 3000, BS.length t <= 3000, BS.all isAsciiLower s, BS.all isAsciiLower t
  let !table = lcsTableV s t
      !m = BS.length s
      !n = BS.length t
  let recon !i !j | i >= m || j >= n = Nothing
                  | x == y = let !i' = i+1 ; !j' = j+1
                             in Just (x, (i', j'))
                  | (table V.! (i+1)) U.! j >= (table V.! i) U.! (j+1) = recon (i+1) j
                  | otherwise = recon i (j+1)
        where x = BSW.index s i
              y = BSW.index t j
      (result, _) = BSW.unfoldrN (fromIntegral $ (table V.! 0) U.! 0) (\(!i,!j) -> recon i j) (0,0)
  BS.putStrLn result
