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 = UArray (Int,Int) Int --sl*tl matrix
type DP s = STUArray s (Int,Int) Int
type DPTable = UArray (Int,Int) Int -- == freeze $ DP s

dp_i :: DP s -> Str -> Str -> Int -> Int -> ST s ()
dp_i dparr s t i j = do
   dpij   <- readArray dparr (i,j)
   dpi1j1 <- readArray dparr (i-1,j-1)
   dpi1j  <- readArray dparr (i-1,j)
   dpij1  <- readArray dparr (i,j-1)
   if s!i == t!j then writeArray dparr (i,j) (max (dpi1j1+1) dpi1j1)
     else return ()
   writeArray dparr (i,j-1) (max dpi1j1 dpij1)
   writeArray dparr (i-1,j) (max dpi1j1 dpi1j)

--DPTableからStringを復元
mkans :: DPTable -> Str -> Int -> Int -> String
mkans dparr s i j
  | i == 0 || j == 0 = []
  | dparr!(i,j) == dparr!(i-1,j-1) = mkans dparr s (i-1) (j-1)
  | dparr!(i,j) == dparr!(i-1,j-1) + 1 =
    if dparr!(i,j) == dparr!(i-1,j) then mkans dparr s (i-1) j
    else if dparr!(i,j) == dparr!(i,j-1) then mkans dparr s i (j-1)
      else s!i : (mkans dparr s (i-1) (j-1))

solve :: Str -> Str -> Int -> Int -> ST s String
solve s t sl tl = do
  dparr <- newArray ((0,0),(sl,tl)) 0
  forM_ [1..sl] $ \i ->
    forM_ [1..tl] $ \j -> dp_i dparr s t i j
  dparr' <- freeze dparr
  let ans = reverse $ mkans dparr' s sl tl
  return 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 $ runST $ solve s' t' sl tl
