import Control.Monad
import Control.Applicative
import qualified Data.Map as M
import Debug.Trace

type DP = M.Map (Int,Int) String

solve :: String -> String -> (Int,Int) -> DP -> DP
solve _ [] _ dp = dp
solve ss (t:ts) point dp =
  loop ss t point dp
  where
    loop :: String -> Char -> (Int,Int) -> DP -> DP
    loop [] _ (y,x) dp = solve ss ts (y+1,1) dp
    loop (a:as) b (y,x) dp
      | a == b = 
        case M.lookup (y-1,x-1) dp of
          Just v -> loop as b (y,x+1) $ M.insert (y,x) (a:v) dp
          Nothing -> loop as b (y,x+1) $ M.insert (y,x) [a] dp
      | otherwise = 
        let f = findFromPair (y-1,x) (y,x-1) dp in loop as b (y,x+1) $ M.insert (y,x) f dp
    
    findFromPair :: (Int,Int) -> (Int,Int) -> DP -> String
    findFromPair p q dp =
      case [(M.lookup p dp), (M.lookup q dp)] of
        [Nothing, Nothing] -> undefined 
        [Just v, Nothing] -> v
        [Nothing, Just w] -> w
        [Just v, Just w] -> if length v >= length w then v else w
main = do
  s <- getLine
  t <- getLine
  let dp = solve s t (1,1) M.empty
  putStrLn $ reverse $ snd $ fst $ M.deleteFindMax dp
